Permalink
Browse files

Removed child tables inheriting constraints. Made them inherit indexe…

…s. If original parent table has data, it's no longer renamed, just left as the parent table.
  • Loading branch information...
1 parent 7191aca commit 54a9109917d212432690a4fcdfee34d0725b0e10 @keithf4 committed Sep 12, 2012
View
@@ -1,17 +1,18 @@
PostgreSQL Partition Manager Extension (pg_partman)
--------------------------------------------------
-Extension to help make managing time or serial id based table partitioning easier.
+Extension to help make managing time or serial id based table partitioning easier.
+
+For this extension, the attributes of the child partitions are all obtained from the original parent. This includes defaults, indexes (primary keys, unique, etc) as well as permissions (permissions not yet inherited. coming soon). While you would not normally create indexes on the parent of a partition set, doing so makes it much easier to manage in this case. There will be no data in the parent table (if everything is working right), so they will not take up any space or have any impact on system performance. Using the parent table as a control to the details of the child tables gives a more central place to manage things that's a little more natural than a configuration table or using setup functions.
*create_parent(p_parent_table text, p_control text, p_type part.partition_type, p_interval text, p_premake int DEFAULT 3, p_debug boolean DEFAULT false)*
- * Main function to create a partition set with one parent table and inherited children. Parent table must already exist. If it has data, it will be renamed with the suffix _pre_partition, made part of the inheritance tree and a new parent table will be created with the original name (function to partition existing data coming soon).
- * If turning an existing table with data into a partitioned set, please double check all permissions & constraints after the conversion. Constraints should be good, but permissions are not copied. Indexes are not recreated on the new parent either and should not be.
+ * Main function to create a partition set with one parent table and inherited children. Parent table must already exist. Please apply all indexes, constraints and permissions to parent table so they will propagate to children.
* First parameter (p_parent_table) is the existing parent table
* Second paramter (p_control) is the column that the partitioning will be based on. Must be a time based column (integer support for ID partitioning coming soon).
* Third column (p_type) is one of 4 values to set the partitioning type that will be used
> **time-static** - Trigger function inserts only into specifically named partitions (handles data for current partition, 2 partitions ahead and 1 behind). Cannot handle inserts to parent table outside the hard-coded time window. Function is kept up to date by run_maintenance() function. Ideal for high TPS tables that get inserts of new data only.
- > **time-dynamic** - Trigger function can insert into any child partition based on the value of the control column. More flexible but not as efficient as time-static. Be aware that if the appropriate partition doesn't yet exist for the data inserted, the insert will fail. This applies for data before the lowest partition and higher than the greatest premade partition.
+ > **time-dynamic** - Trigger function can insert into any child partition based on the value of the control column. More flexible but not as efficient as time-static. Be aware that if the appropriate partition doesn't yet exist for the data inserted, the insert will fail.
> **id-static** - Same functionality as time-static but for a numeric range instead of time. When the id value has reached 50% of the max value for that partition, it will automatically create the next partition in sequence if it doesn't yet exist. Does NOT require run_maintenance() function to create new partitions.
> **id-dynamic** - Same functionality and limitations as time-dynamic but for a numeric range instead of time. Uses same 50% rule as id-static to create future partitions. Does NOT require run_maintenance() function to create new partitions.
@@ -24,9 +25,9 @@ Extension to help make managing time or serial id based table partitioning easie
> **hourly** - One partition per hour
> **half-hour** - One partition per 30 minute interval on the half-hour (1200, 1230)
> **quarter-hour** - One partition per 15 minute interval on the quarter-hour (1200, 1215, 1230, 1245)
- > **id** - For ID based partitions, the range of that ID that should be set per partition
+ > **<integer>** - For ID based partitions, the integer value range of that ID that should be set per partition. This is the actual integer value, not text values like time-based partitioning.
- * Fifth paramter (p_premake) is how many additional partitions to stay ahead of the current partition. Default value is 3. This will keep at minimum 4 partitions made, including the current one. For example, if today was Sept 6, 2012, and premake was set to 4 for a daily partition, then partitions would be made for the 6th as well as the 7th, 8th, 9th and 10th.
+ * Fifth paramter (p_premake) is how many additional partitions to always stay ahead of the current partition. Default value is 3. This will keep at minimum 4 partitions made, including the current one. For example, if today was Sept 6, 2012, and premake was set to 4 for a daily partition, then partitions would be made for the 6th as well as the 7th, 8th, 9th and 10th.
* Sixth parameter (p_debug) is to turn on additional debugging information (not yet working).
*run_maintenance()*
@@ -126,7 +126,7 @@ ELSIF v_type = 'id-dynamic' THEN
RETURN NULL;
END $t$;';
- RAISE NOTICE 'v_trig_func: %',v_trig_func;
+-- RAISE NOTICE 'v_trig_func: %',v_trig_func;
EXECUTE v_trig_func;
ELSE
@@ -22,7 +22,7 @@ FOREACH v_id IN ARRAY p_partition_ids LOOP
v_tablename := substring(v_partition_name from position('.' in v_partition_name)+1);
END IF;
- EXECUTE 'CREATE TABLE '||v_partition_name||' (LIKE '||p_parent_table||' INCLUDING DEFAULTS INCLUDING CONSTRAINTS) INHERITS ('||p_parent_table||')';
+ EXECUTE 'CREATE TABLE '||v_partition_name||' (LIKE '||p_parent_table||' INCLUDING DEFAULTS INCLUDING INDEXES) INHERITS ('||p_parent_table||')';
EXECUTE 'ALTER TABLE '||v_partition_name||' ADD CONSTRAINT '||v_tablename||'_partition_check
CHECK ('||p_control||'>='||quote_literal(v_id)||' AND '||p_control||'<'||quote_literal(v_id + p_interval)||')';
@@ -53,16 +53,6 @@ CASE
END CASE;
EXECUTE 'SELECT max('||p_control||')::text FROM '||p_parent_table||' LIMIT 1' INTO v_max;
-IF v_max IS NOT NULL THEN
- IF position('.' in p_parent_table) > 0 THEN
- v_tablename := substring(p_parent_table from position('.' in p_parent_table)+1);
- END IF;
-
- EXECUTE 'ALTER TABLE '||p_parent_table||' RENAME TO '||v_tablename||'_pre_partition';
- EXECUTE 'CREATE TABLE '||p_parent_table||' (LIKE '||p_parent_table||'_pre_partition
- INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING COMMENTS)';
-
-END IF;
IF p_type = 'time-static' OR p_type = 'time-dynamic' THEN
FOR i IN 0..p_premake LOOP
@@ -64,7 +64,7 @@ FOREACH v_time IN ARRAY p_partition_times LOOP
v_tablename := substring(v_partition_name from position('.' in v_partition_name)+1);
END IF;
- EXECUTE 'CREATE TABLE '||v_partition_name||' (LIKE '||p_parent_table||' INCLUDING DEFAULTS INCLUDING CONSTRAINTS) INHERITS ('||p_parent_table||')';
+ EXECUTE 'CREATE TABLE '||v_partition_name||' (LIKE '||p_parent_table||' INCLUDING DEFAULTS INCLUDING INDEXES) INHERITS ('||p_parent_table||')';
EXECUTE 'ALTER TABLE '||v_partition_name||' ADD CONSTRAINT '||v_tablename||'_partition_check
CHECK ('||p_control||'>='||quote_literal(v_partition_timestamp_start)||' AND '||p_control||'<'||quote_literal(v_partition_timestamp_end)||')';

0 comments on commit 54a9109

Please sign in to comment.