aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2018-01-19 11:49:22 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2018-01-19 11:49:22 -0300
commit8b08f7d4820fd7a8ef6152a9dd8c6e3cb01e5f99 (patch)
tree0ecb879a9568e7e14275afe72a77e316e72376c6 /src/backend/utils/adt/ruleutils.c
parent1ef61ddce9086c30a18a6ecc48bc3ce0ef62cb39 (diff)
downloadpostgresql-8b08f7d4820fd7a8ef6152a9dd8c6e3cb01e5f99.tar.gz
postgresql-8b08f7d4820fd7a8ef6152a9dd8c6e3cb01e5f99.zip
Local partitioned indexes
When CREATE INDEX is run on a partitioned table, create catalog entries for an index on the partitioned table (which is just a placeholder since the table proper has no data of its own), and recurse to create actual indexes on the existing partitions; create them in future partitions also. As a convenience gadget, if the new index definition matches some existing index in partitions, these are picked up and used instead of creating new ones. Whichever way these indexes come about, they become attached to the index on the parent table and are dropped alongside it, and cannot be dropped on isolation unless they are detached first. To support pg_dump'ing these indexes, add commands CREATE INDEX ON ONLY <table> (which creates the index on the parent partitioned table, without recursing) and ALTER INDEX ATTACH PARTITION (which is used after the indexes have been created individually on each partition, to attach them to the parent index). These reconstruct prior database state exactly. Reviewed-by: (in alphabetical order) Peter Eisentraut, Robert Haas, Amit Langote, Jesper Pedersen, Simon Riggs, David Rowley Discussion: https://postgr.es/m/20171113170646.gzweigyrgg6pwsg4@alvherre.pgsql
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 9cdbb06add7..c5f5a1ca3f9 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -317,7 +317,7 @@ static void decompile_column_index_array(Datum column_index_array, Oid relId,
static char *pg_get_ruledef_worker(Oid ruleoid, int prettyFlags);
static char *pg_get_indexdef_worker(Oid indexrelid, int colno,
const Oid *excludeOps,
- bool attrsOnly, bool showTblSpc,
+ bool attrsOnly, bool showTblSpc, bool inherits,
int prettyFlags, bool missing_ok);
static char *pg_get_statisticsobj_worker(Oid statextid, bool missing_ok);
static char *pg_get_partkeydef_worker(Oid relid, int prettyFlags,
@@ -1086,7 +1086,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
prettyFlags = PRETTYFLAG_INDENT;
- res = pg_get_indexdef_worker(indexrelid, 0, NULL, false, false,
+ res = pg_get_indexdef_worker(indexrelid, 0, NULL, false, false, false,
prettyFlags, true);
if (res == NULL)
@@ -1107,7 +1107,7 @@ pg_get_indexdef_ext(PG_FUNCTION_ARGS)
prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT;
res = pg_get_indexdef_worker(indexrelid, colno, NULL, colno != 0, false,
- prettyFlags, true);
+ false, prettyFlags, true);
if (res == NULL)
PG_RETURN_NULL();
@@ -1123,7 +1123,7 @@ pg_get_indexdef_ext(PG_FUNCTION_ARGS)
char *
pg_get_indexdef_string(Oid indexrelid)
{
- return pg_get_indexdef_worker(indexrelid, 0, NULL, false, true, 0, false);
+ return pg_get_indexdef_worker(indexrelid, 0, NULL, false, true, true, 0, false);
}
/* Internal version that just reports the column definitions */
@@ -1133,7 +1133,7 @@ pg_get_indexdef_columns(Oid indexrelid, bool pretty)
int prettyFlags;
prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT;
- return pg_get_indexdef_worker(indexrelid, 0, NULL, true, false,
+ return pg_get_indexdef_worker(indexrelid, 0, NULL, true, false, false,
prettyFlags, false);
}
@@ -1146,7 +1146,7 @@ pg_get_indexdef_columns(Oid indexrelid, bool pretty)
static char *
pg_get_indexdef_worker(Oid indexrelid, int colno,
const Oid *excludeOps,
- bool attrsOnly, bool showTblSpc,
+ bool attrsOnly, bool showTblSpc, bool inherits,
int prettyFlags, bool missing_ok)
{
/* might want a separate isConstraint parameter later */
@@ -1259,9 +1259,11 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
if (!attrsOnly)
{
if (!isConstraint)
- appendStringInfo(&buf, "CREATE %sINDEX %s ON %s USING %s (",
+ appendStringInfo(&buf, "CREATE %sINDEX %s ON %s%s USING %s (",
idxrec->indisunique ? "UNIQUE " : "",
quote_identifier(NameStr(idxrelrec->relname)),
+ idxrelrec->relkind == RELKIND_PARTITIONED_INDEX
+ && !inherits ? "ONLY " : "",
generate_relation_name(indrelid, NIL),
quote_identifier(NameStr(amrec->amname)));
else /* currently, must be EXCLUDE constraint */
@@ -2148,6 +2150,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
operators,
false,
false,
+ false,
prettyFlags,
false));
break;