From: Ant Zucaro Date: Thu, 23 May 2013 02:05:06 +0000 (-0400) Subject: Partition player weapon stats through 2014. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c52ae86477d2842fd62e16c3b879e69206028a23;p=xonotic%2Fxonstatdb.git Partition player weapon stats through 2014. --- diff --git a/tables/player_weapon_stats.tab b/tables/player_weapon_stats.tab index 8670753..0645fc3 100755 --- a/tables/player_weapon_stats.tab +++ b/tables/player_weapon_stats.tab @@ -35,6 +35,7 @@ CREATE INDEX player_weap_stats_ix03 on player_weapon_stats(player_id); ALTER TABLE xonstat.player_weapon_stats OWNER TO xonstat; +-- 2011 CREATE TABLE xonstat.player_weapon_stats_2011Q2 ( CHECK ( create_dt >= DATE '2011-04-01' AND create_dt < DATE '2011-07-01' ) ) INHERITS (player_weapon_stats); @@ -62,6 +63,7 @@ CREATE INDEX player_weap_stats_2011Q4_ix02 on player_weapon_stats_2011Q4(game_id CREATE INDEX player_weap_stats_2011Q4_ix03 on player_weapon_stats_2011Q4(player_id); ALTER TABLE xonstat.player_weapon_stats_2011Q4 OWNER TO xonstat; +-- 2012 CREATE TABLE xonstat.player_weapon_stats_2012Q1 ( CHECK ( create_dt >= DATE '2012-01-01' AND create_dt < DATE '2012-04-01' ) ) INHERITS (player_weapon_stats); @@ -98,6 +100,7 @@ CREATE INDEX player_weap_stats_2012Q4_ix02 on player_weapon_stats_2012Q4(game_id CREATE INDEX player_weap_stats_2012Q4_ix03 on player_weapon_stats_2012Q4(player_id); ALTER TABLE xonstat.player_weapon_stats_2012Q4 OWNER TO xonstat; +-- 2013 CREATE TABLE xonstat.player_weapon_stats_2013Q1 ( CHECK ( create_dt >= DATE '2013-01-01' AND create_dt < DATE '2013-04-01' ) ) INHERITS (player_weapon_stats); @@ -115,3 +118,58 @@ CREATE INDEX player_weap_stats_2013Q2_ix01 on player_weapon_stats_2013Q2(create_ CREATE INDEX player_weap_stats_2013Q2_ix02 on player_weapon_stats_2013Q2(game_id); CREATE INDEX player_weap_stats_2013Q2_ix03 on player_weapon_stats_2013Q2(player_id); ALTER TABLE xonstat.player_weapon_stats_2013Q2 OWNER TO xonstat; + +CREATE TABLE xonstat.player_weapon_stats_2013Q3 ( + CHECK ( create_dt >= DATE '2013-07-01' AND create_dt < DATE '2013-10-01' ) +) INHERITS (player_weapon_stats); + +CREATE INDEX player_weap_stats_2013Q3_ix01 on player_weapon_stats_2013Q3(create_dt); +CREATE INDEX player_weap_stats_2013Q3_ix02 on player_weapon_stats_2013Q3(game_id); +CREATE INDEX player_weap_stats_2013Q3_ix03 on player_weapon_stats_2013Q3(player_id); +ALTER TABLE xonstat.player_weapon_stats_2013Q3 OWNER TO xonstat; + +CREATE TABLE xonstat.player_weapon_stats_2013Q4 ( + CHECK ( create_dt >= DATE '2013-10-01' AND create_dt < DATE '2014-01-01' ) +) INHERITS (player_weapon_stats); + +CREATE INDEX player_weap_stats_2013Q4_ix01 on player_weapon_stats_2013Q4(create_dt); +CREATE INDEX player_weap_stats_2013Q4_ix02 on player_weapon_stats_2013Q4(game_id); +CREATE INDEX player_weap_stats_2013Q4_ix03 on player_weapon_stats_2013Q4(player_id); +ALTER TABLE xonstat.player_weapon_stats_2013Q4 OWNER TO xonstat; + +-- 2014 +CREATE TABLE xonstat.player_weapon_stats_2014Q1 ( + CHECK ( create_dt >= DATE '2014-01-01' AND create_dt < DATE '2014-04-01' ) +) INHERITS (player_weapon_stats); + +CREATE INDEX player_weap_stats_2014Q1_ix01 on player_weapon_stats_2014Q1(create_dt); +CREATE INDEX player_weap_stats_2014Q1_ix02 on player_weapon_stats_2014Q1(game_id); +CREATE INDEX player_weap_stats_2014Q1_ix03 on player_weapon_stats_2014Q1(player_id); +ALTER TABLE xonstat.player_weapon_stats_2014Q1 OWNER TO xonstat; + +CREATE TABLE xonstat.player_weapon_stats_2014Q2 ( + CHECK ( create_dt >= DATE '2014-04-01' AND create_dt < DATE '2014-07-01' ) +) INHERITS (player_weapon_stats); + +CREATE INDEX player_weap_stats_2014Q2_ix01 on player_weapon_stats_2014Q2(create_dt); +CREATE INDEX player_weap_stats_2014Q2_ix02 on player_weapon_stats_2014Q2(game_id); +CREATE INDEX player_weap_stats_2014Q2_ix03 on player_weapon_stats_2014Q2(player_id); +ALTER TABLE xonstat.player_weapon_stats_2014Q2 OWNER TO xonstat; + +CREATE TABLE xonstat.player_weapon_stats_2014Q3 ( + CHECK ( create_dt >= DATE '2014-07-01' AND create_dt < DATE '2014-10-01' ) +) INHERITS (player_weapon_stats); + +CREATE INDEX player_weap_stats_2014Q3_ix01 on player_weapon_stats_2014Q3(create_dt); +CREATE INDEX player_weap_stats_2014Q3_ix02 on player_weapon_stats_2014Q3(game_id); +CREATE INDEX player_weap_stats_2014Q3_ix03 on player_weapon_stats_2014Q3(player_id); +ALTER TABLE xonstat.player_weapon_stats_2014Q3 OWNER TO xonstat; + +CREATE TABLE xonstat.player_weapon_stats_2014Q4 ( + CHECK ( create_dt >= DATE '2014-10-01' AND create_dt < DATE '2015-01-01' ) +) INHERITS (player_weapon_stats); + +CREATE INDEX player_weap_stats_2014Q4_ix01 on player_weapon_stats_2014Q4(create_dt); +CREATE INDEX player_weap_stats_2014Q4_ix02 on player_weapon_stats_2014Q4(game_id); +CREATE INDEX player_weap_stats_2014Q4_ix03 on player_weapon_stats_2014Q4(player_id); +ALTER TABLE xonstat.player_weapon_stats_2014Q4 OWNER TO xonstat; diff --git a/triggers/player_weapon_stats_ins_trg.sql b/triggers/player_weapon_stats_ins_trg.sql index d1b21ae..3b9e268 100644 --- a/triggers/player_weapon_stats_ins_trg.sql +++ b/triggers/player_weapon_stats_ins_trg.sql @@ -1,24 +1,23 @@ CREATE OR REPLACE FUNCTION player_weapon_stats_ins() RETURNS TRIGGER AS $$ BEGIN - IF (NEW.create_dt >= DATE '2011-04-01' AND NEW.create_dt < DATE '2011-07-01') THEN - INSERT INTO player_weapon_stats_2011Q2 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2011-07-01' AND NEW.create_dt < DATE '2011-10-01') THEN - INSERT INTO player_weapon_stats_2011Q3 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2011-10-01' AND NEW.create_dt < DATE '2012-01-01') THEN - INSERT INTO player_weapon_stats_2011Q4 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2012-01-01' AND NEW.create_dt < DATE '2012-04-01') THEN - INSERT INTO player_weapon_stats_2012Q1 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2012-04-01' AND NEW.create_dt < DATE '2012-07-01') THEN - INSERT INTO player_weapon_stats_2012Q2 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2012-07-01' AND NEW.create_dt < DATE '2012-10-01') THEN - INSERT INTO player_weapon_stats_2012Q3 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2012-10-01' AND NEW.create_dt < DATE '2013-01-01') THEN - INSERT INTO player_weapon_stats_2012Q4 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2013-01-01' AND NEW.create_dt < DATE '2013-04-01') THEN - INSERT INTO player_weapon_stats_2013Q1 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2013-04-01' AND NEW.create_dt < DATE '2013-07-01') THEN + IF (NEW.create_dt >= DATE '2013-04-01' AND NEW.create_dt < DATE '2013-07-01') THEN INSERT INTO player_weapon_stats_2013Q2 VALUES (NEW.*); + ELSIF (NEW.create_dt >= DATE '2013-07-01' AND NEW.create_dt < DATE '2013-10-01') THEN + INSERT INTO player_weapon_stats_2013Q3 VALUES (NEW.*); + ELSIF (NEW.create_dt >= DATE '2013-10-01' AND NEW.create_dt < DATE '2014-01-01') THEN + INSERT INTO player_weapon_stats_2013Q4 VALUES (NEW.*); + + -- 2014 + ELSIF (NEW.create_dt >= DATE '2014-01-01' AND NEW.create_dt < DATE '2014-04-01') THEN + INSERT INTO player_weapon_stats_2014Q1 VALUES (NEW.*); + ELSIF (NEW.create_dt >= DATE '2014-04-01' AND NEW.create_dt < DATE '2014-07-01') THEN + INSERT INTO player_weapon_stats_2014Q2 VALUES (NEW.*); + ELSIF (NEW.create_dt >= DATE '2014-07-01' AND NEW.create_dt < DATE '2014-10-01') THEN + INSERT INTO player_weapon_stats_2014Q3 VALUES (NEW.*); + ELSIF (NEW.create_dt >= DATE '2014-10-01' AND NEW.create_dt < DATE '2015-01-01') THEN + INSERT INTO player_weapon_stats_2014Q4 VALUES (NEW.*); + ELSE RAISE EXCEPTION 'Date out of range. Fix the player_weapon_stats_ins() trigger!'; END IF;