pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedREINDEX CONCURRENTLY causes ALTER TABLE to fail
10+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2019-07-29 7cce159349 28bbf7a81b Fix handling of expressions and predicates in REINDEX CONCURRENTLY
* REINDEX CONCURRENTLY causes ALTER TABLE to fail
@ 2019-07-17 12:53 Manuel Rigger <rigger.manuel@gmail.com>
0 siblings, 2 replies; 10+ messages in thread
From: Manuel Rigger @ 2019-07-17 12:53 UTC (permalink / raw)
To: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Hi everyone,
Consider the following statement sequence:
CREATE TABLE t0(c0 INTEGER , c1 BOOLEAN);
INSERT INTO t0(c0, c1) VALUES(1369652450, FALSE), (414515746, TRUE),
(897778963, FALSE);
CREATE UNIQUE INDEX i0 ON t0((1 / t0.c0)) WHERE ('-H') >=
(t0.c1::TEXT) COLLATE "C";
REINDEX TABLE CONCURRENTLY t0;
ALTER TABLE t0 ALTER c1 TYPE TEXT; -- could not create unique index
"i0" DETAIL: Key ((1 / c0))=(0) is duplicated.
The REINDEX TABLE CONCURRENTLY causes the ALTER TABLE to fail, which
is unexpected. Without the CONCURRENTLY, the ALTER TABLE works as
expected. When first executing a concurrent reindex, which is followed
by a non-current one, the error still occurs, which might suggest that
the concurrent reindex breaks some internal state.
I tested this on trunk. On the latest release version, the
CONCURRENTLY option is not available.
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: REINDEX CONCURRENTLY causes ALTER TABLE to fail
@ 2019-07-18 03:02 Michael Paquier <michael@paquier.xyz>
parent: Manuel Rigger <rigger.manuel@gmail.com>
1 sibling, 1 reply; 10+ messages in thread
From: Michael Paquier @ 2019-07-18 03:02 UTC (permalink / raw)
To: Manuel Rigger <rigger.manuel@gmail.com>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
On Wed, Jul 17, 2019 at 02:53:54PM +0200, Manuel Rigger wrote:
> The REINDEX TABLE CONCURRENTLY causes the ALTER TABLE to fail, which
> is unexpected. Without the CONCURRENTLY, the ALTER TABLE works as
> expected. When first executing a concurrent reindex, which is followed
> by a non-current one, the error still occurs, which might suggest that
> the concurrent reindex breaks some internal state.
Thanks. The issue comes from the handling of the collation part
within the index predicates in pg_index.indpred. I can see a slight
difference in the tree with a switch from COLLATE to REFLABEL for
example.
In your test case, if you actually remove the collation part, this
fails similarly:
=# CREATE UNIQUE INDEX i0 ON t0((1 / t0.c0)) WHERE ('-H') >=
(t0.c1::TEXT);
ERROR: 23505: could not create unique index "i0"
DETAIL: Key ((1 / c0))=(0) is duplicated.
The root of the problem comes from the fact that we rely on
BuildIndexInfo() for the index information. This uses
RelationGetIndexExpressions() to fetch the set of expressions and
RelationGetIndexPredicate() for the predicates. However, the issue is
that those routines apply some extra flattening operations for the
planner when storing this data in the relation cache, causing the
expressions stored in the catalogs for the copy to be changed. So
what we store are the expressions that the planner uses. No wonder
that this gets broken.
There are a couple of approaches that we could do to fix that. The
first one I could think about is to change the relcache level so as we
don't apply planner-level optimizations when creating a concurrent
index entry. Another one, which is less invasive, is to just update
the list of expressions and predicates after calling
BuildIndexInfo(). Still that means overriding the contents of the
relcache with what has been optimized for the planner to what we want
to use for the reindex build and I think that this weakens the logic
of index_build.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: REINDEX CONCURRENTLY causes ALTER TABLE to fail
@ 2019-07-18 04:25 Michael Paquier <michael@paquier.xyz>
parent: Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 10+ messages in thread
From: Michael Paquier @ 2019-07-18 04:25 UTC (permalink / raw)
To: Manuel Rigger <rigger.manuel@gmail.com>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
On Thu, Jul 18, 2019 at 12:02:32PM +0900, Michael Paquier wrote:
> There are a couple of approaches that we could do to fix that. The
> first one I could think about is to change the relcache level so as we
> don't apply planner-level optimizations when creating a concurrent
> index entry. Another one, which is less invasive, is to just update
> the list of expressions and predicates after calling
> BuildIndexInfo(). Still that means overriding the contents of the
> relcache with what has been optimized for the planner to what we want
> to use for the reindex build and I think that this weakens the logic
> of index_build.
I have done some work on that, and for now I am finishing with the
attached. This takes the approach of updating BuildIndexInfo() so as
the optimizations for the planner are not done.
That's not completely right yet though as even if it passes your
initial test case, this does not allow the index expressions and
predicates to have an exact match. I have designed a test case for
this purpose which stores the contents of pg_node_tree before and
after the REINDEX and even if the collation gets right, all the
location fields from pg_node_tree get reset. The solution is not
complete, still the test case is quite useful. So even if the
solution happens to not be like the attached, I'd rather keep the
test case and perhaps extend it.
--
Michael
Attachments:
reindex-conc-predicates-v1.patch (text/x-diff, 23.5K) download
diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c
index 9126c18d0e..6bfce99ca2 100644
--- a/contrib/amcheck/verify_nbtree.c
+++ b/contrib/amcheck/verify_nbtree.c
@@ -514,7 +514,7 @@ bt_check_every_level(Relation rel, Relation heaprel, bool heapkeyspace,
*/
if (state->heapallindexed)
{
- IndexInfo *indexinfo = BuildIndexInfo(state->rel);
+ IndexInfo *indexinfo = BuildIndexInfo(state->rel, true);
TableScanDesc scan;
/* Report on extra downlink checks performed in readonly case */
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index ae7b729edd..ab68840ebc 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -1370,7 +1370,7 @@ brinsummarize(Relation index, Relation heapRel, BlockNumber pageRange,
Assert(!indexInfo);
state = initialize_brin_buildstate(index, revmap,
pagesPerRange);
- indexInfo = BuildIndexInfo(index);
+ indexInfo = BuildIndexInfo(index, true);
}
summarize_range(indexInfo, state, heapRel, startBlk, heapNumBlocks);
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index d0b9013caf..b73c40ee8b 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -1766,7 +1766,7 @@ _bt_parallel_scan_and_sort(BTSpool *btspool, BTSpool *btspool2,
buildstate.btleader = NULL;
/* Join parallel scan */
- indexInfo = BuildIndexInfo(btspool->index);
+ indexInfo = BuildIndexInfo(btspool->index, true);
indexInfo->ii_Concurrent = btshared->isconcurrent;
scan = table_beginscan_parallel(btspool->heap,
ParallelTableScanFromBTShared(btshared));
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 032fab9ac4..4db8f0615e 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -3149,7 +3149,7 @@ RelationTruncateIndexes(Relation heapRelation)
currentIndex = index_open(indexId, AccessExclusiveLock);
/* Fetch info needed for index_build */
- indexInfo = BuildIndexInfo(currentIndex);
+ indexInfo = BuildIndexInfo(currentIndex, true);
/*
* Now truncate the actual file (and discard buffers).
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 9234e93261..80eaddb59a 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -1212,7 +1212,7 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, const char
indexRelation = index_open(oldIndexId, RowExclusiveLock);
/* New index uses the same index information as old index */
- indexInfo = BuildIndexInfo(indexRelation);
+ indexInfo = BuildIndexInfo(indexRelation, false);
/* Get the array of class and column options IDs from index info */
indexTuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(oldIndexId));
@@ -1312,7 +1312,7 @@ index_concurrently_build(Oid heapRelationId,
* commit of the transaction where this concurrent index was created at
* the catalog level.
*/
- indexInfo = BuildIndexInfo(indexRelation);
+ indexInfo = BuildIndexInfo(indexRelation, true);
Assert(!indexInfo->ii_ReadyForInserts);
indexInfo->ii_Concurrent = true;
indexInfo->ii_BrokenHotChain = false;
@@ -2162,10 +2162,14 @@ index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
* FormIndexDatum, which is used for both index_build() and later insertion
* of individual index tuples. Normally we build an IndexInfo for an index
* just once per command, and then use it for (potentially) many tuples.
+ *
+ * If "optimize" is true, index expressions and predicates are not made
+ * planner-ready. This is used by REINDEX CONCURRENTLY when creating a
+ * duplicate index entry rebuilt concurrently.
* ----------------
*/
IndexInfo *
-BuildIndexInfo(Relation index)
+BuildIndexInfo(Relation index, bool optimize)
{
IndexInfo *ii = makeNode(IndexInfo);
Form_pg_index indexStruct = index->rd_index;
@@ -2186,11 +2190,11 @@ BuildIndexInfo(Relation index)
ii->ii_IndexAttrNumbers[i] = indexStruct->indkey.values[i];
/* fetch any expressions needed for expressional indexes */
- ii->ii_Expressions = RelationGetIndexExpressions(index);
+ ii->ii_Expressions = RelationGetIndexExpressions(index, optimize);
ii->ii_ExpressionsState = NIL;
/* fetch index predicate if any */
- ii->ii_Predicate = RelationGetIndexPredicate(index);
+ ii->ii_Predicate = RelationGetIndexPredicate(index, optimize);
ii->ii_PredicateState = NULL;
/* fetch exclusion constraint info if any */
@@ -3034,7 +3038,7 @@ validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
* passed in from DefineIndex, but its copy is long gone due to having
* been built in a previous transaction.)
*/
- indexInfo = BuildIndexInfo(indexRelation);
+ indexInfo = BuildIndexInfo(indexRelation, true);
/* mark build is concurrent just for consistency */
indexInfo->ii_Concurrent = true;
@@ -3322,7 +3326,7 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence,
TransferPredicateLocksToHeapRelation(iRel);
/* Fetch info needed for index_build */
- indexInfo = BuildIndexInfo(iRel);
+ indexInfo = BuildIndexInfo(iRel, true);
/* If requested, skip checking uniqueness/exclusion constraints */
if (skip_constraint_checks)
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 8d633f2585..3f5b05b325 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -434,7 +434,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
AnlIndexData *thisdata = &indexdata[ind];
IndexInfo *indexInfo;
- thisdata->indexInfo = indexInfo = BuildIndexInfo(Irel[ind]);
+ thisdata->indexInfo = indexInfo = BuildIndexInfo(Irel[ind], true);
thisdata->tupleFract = 1.0; /* fix later if partial */
if (indexInfo->ii_Expressions != NIL && va_cols == NIL)
{
diff --git a/src/backend/commands/constraint.c b/src/backend/commands/constraint.c
index 806962a686..05fef01e79 100644
--- a/src/backend/commands/constraint.c
+++ b/src/backend/commands/constraint.c
@@ -132,7 +132,7 @@ unique_key_recheck(PG_FUNCTION_ARGS)
*/
indexRel = index_open(trigdata->tg_trigger->tgconstrindid,
RowExclusiveLock);
- indexInfo = BuildIndexInfo(indexRel);
+ indexInfo = BuildIndexInfo(indexRel, true);
/*
* Typically the index won't have expressions, but if it does we need an
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index fd299273c5..42675360ef 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -1121,7 +1121,7 @@ DefineIndex(Oid relationId,
continue;
cldidx = index_open(cldidxid, lockmode);
- cldIdxInfo = BuildIndexInfo(cldidx);
+ cldIdxInfo = BuildIndexInfo(cldidx, true);
if (CompareIndexInfo(cldIdxInfo, indexInfo,
cldidx->rd_indcollation,
collationObjectId,
diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c
index 537d0e8cef..5dfd06447e 100644
--- a/src/backend/commands/matview.c
+++ b/src/backend/commands/matview.c
@@ -871,7 +871,7 @@ is_usable_unique_index(Relation indexRel)
indexStruct->indimmediate &&
indexRel->rd_rel->relam == BTREE_AM_OID &&
indexStruct->indisvalid &&
- RelationGetIndexPredicate(indexRel) == NIL &&
+ RelationGetIndexPredicate(indexRel, true) == NIL &&
indexStruct->indnatts > 0)
{
/*
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index fc1c4dfa4c..7ba1bfdfeb 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -7242,7 +7242,7 @@ ATExecAddIndexConstraint(AlteredTableInfo *tab, Relation rel,
indexName = pstrdup(RelationGetRelationName(indexRel));
- indexInfo = BuildIndexInfo(indexRel);
+ indexInfo = BuildIndexInfo(indexRel, true);
/* this should have been checked at parse time */
if (!indexInfo->ii_Unique)
@@ -13817,13 +13817,13 @@ ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode
errmsg("cannot use non-immediate index \"%s\" as replica identity",
RelationGetRelationName(indexRel))));
/* Expression indexes aren't supported. */
- if (RelationGetIndexExpressions(indexRel) != NIL)
+ if (RelationGetIndexExpressions(indexRel, true) != NIL)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot use expression index \"%s\" as replica identity",
RelationGetRelationName(indexRel))));
/* Predicate indexes aren't supported. */
- if (RelationGetIndexPredicate(indexRel) != NIL)
+ if (RelationGetIndexPredicate(indexRel, true) != NIL)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot use partial index \"%s\" as replica identity",
@@ -15725,7 +15725,7 @@ AttachPartitionEnsureIndexes(Relation rel, Relation attachrel)
Oid cldIdxId = lfirst_oid(cell);
attachrelIdxRels[i] = index_open(cldIdxId, AccessShareLock);
- attachInfos[i] = BuildIndexInfo(attachrelIdxRels[i]);
+ attachInfos[i] = BuildIndexInfo(attachrelIdxRels[i], true);
i++;
}
@@ -15781,7 +15781,7 @@ AttachPartitionEnsureIndexes(Relation rel, Relation attachrel)
}
/* construct an indexinfo to compare existing indexes against */
- info = BuildIndexInfo(idxRel);
+ info = BuildIndexInfo(idxRel, true);
attmap = convert_tuples_by_name_map(RelationGetDescr(attachrel),
RelationGetDescr(rel),
gettext_noop("could not convert row type"));
@@ -16357,8 +16357,8 @@ ATExecAttachPartitionIdx(List **wqueue, Relation parentIdx, RangeVar *name)
RelationGetRelationName(parentTbl))));
/* Ensure the indexes are compatible */
- childInfo = BuildIndexInfo(partIdx);
- parentInfo = BuildIndexInfo(parentIdx);
+ childInfo = BuildIndexInfo(partIdx, true);
+ parentInfo = BuildIndexInfo(parentIdx, true);
attmap = convert_tuples_by_name_map(RelationGetDescr(partTbl),
RelationGetDescr(parentTbl),
gettext_noop("could not convert row type"));
diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c
index 40bd8049f0..4158b02f04 100644
--- a/src/backend/executor/execIndexing.c
+++ b/src/backend/executor/execIndexing.c
@@ -199,7 +199,7 @@ ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative)
indexDesc = index_open(indexOid, RowExclusiveLock);
/* extract index key information from the index's pg_index info */
- ii = BuildIndexInfo(indexDesc);
+ ii = BuildIndexInfo(indexDesc, true);
/*
* If the indexes are to be used for speculative insertion, add extra
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index ca3b7f29e1..076530172e 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -6307,8 +6307,8 @@ plan_create_index_workers(Oid tableOid, Oid indexOid)
* safe.
*/
if (heap->rd_rel->relpersistence == RELPERSISTENCE_TEMP ||
- !is_parallel_safe(root, (Node *) RelationGetIndexExpressions(index)) ||
- !is_parallel_safe(root, (Node *) RelationGetIndexPredicate(index)))
+ !is_parallel_safe(root, (Node *) RelationGetIndexExpressions(index, true)) ||
+ !is_parallel_safe(root, (Node *) RelationGetIndexPredicate(index, true)))
{
parallel_workers = 0;
goto done;
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index 98e99481c6..93a300880c 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -368,8 +368,8 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
* correct varno for the parent relation, so that they match up
* correctly against qual clauses.
*/
- info->indexprs = RelationGetIndexExpressions(indexRelation);
- info->indpred = RelationGetIndexPredicate(indexRelation);
+ info->indexprs = RelationGetIndexExpressions(indexRelation, true);
+ info->indpred = RelationGetIndexPredicate(indexRelation, true);
if (info->indexprs && varno != 1)
ChangeVarNodes((Node *) info->indexprs, 1, varno, 0);
if (info->indpred && varno != 1)
@@ -759,7 +759,7 @@ infer_arbiter_indexes(PlannerInfo *root)
goto next;
/* Expression attributes (if any) must match */
- idxExprs = RelationGetIndexExpressions(idxRel);
+ idxExprs = RelationGetIndexExpressions(idxRel, true);
foreach(el, onconflict->arbiterElems)
{
InferenceElem *elem = (InferenceElem *) lfirst(el);
@@ -810,7 +810,7 @@ infer_arbiter_indexes(PlannerInfo *root)
* If it's a partial index, its predicate must be implied by the ON
* CONFLICT's WHERE clause.
*/
- predExprs = RelationGetIndexPredicate(idxRel);
+ predExprs = RelationGetIndexPredicate(idxRel, true);
if (!predicate_implied_by(predExprs, (List *) onconflict->arbiterWhere, false))
goto next;
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index f0f6ee7db6..4c03f38581 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -2078,14 +2078,14 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
errdetail("Cannot create a primary key or unique constraint using such an index."),
parser_errposition(cxt->pstate, constraint->location)));
- if (RelationGetIndexExpressions(index_rel) != NIL)
+ if (RelationGetIndexExpressions(index_rel, true) != NIL)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("index \"%s\" contains expressions", index_name),
errdetail("Cannot create a primary key or unique constraint using such an index."),
parser_errposition(cxt->pstate, constraint->location)));
- if (RelationGetIndexPredicate(index_rel) != NIL)
+ if (RelationGetIndexPredicate(index_rel, true) != NIL)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is a partial index", index_name),
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 7aa5d7c7fa..5e478b785c 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -4570,9 +4570,13 @@ RelationGetReplicaIndex(Relation relation)
* Otherwise, the returned tree is copied into the caller's memory context.
* (We don't want to return a pointer to the relcache copy, since it could
* disappear due to relcache invalidation.)
+ *
+ * If "optimize" is true, apply all optimizations to make this result
+ * usable by the planner. Non-optimized expressions are currently used
+ * when creating a concurrent index for REINDEX CONCURRENTLY.
*/
List *
-RelationGetIndexExpressions(Relation relation)
+RelationGetIndexExpressions(Relation relation, bool optimize)
{
List *result;
Datum exprsDatum;
@@ -4603,14 +4607,17 @@ RelationGetIndexExpressions(Relation relation)
result = (List *) stringToNode(exprsString);
pfree(exprsString);
- /*
- * Run the expressions through eval_const_expressions. This is not just an
- * optimization, but is necessary, because the planner will be comparing
- * them to similarly-processed qual clauses, and may fail to detect valid
- * matches without this. We must not use canonicalize_qual, however,
- * since these aren't qual expressions.
- */
- result = (List *) eval_const_expressions(NULL, (Node *) result);
+ if (optimize)
+ {
+ /*
+ * Run the expressions through eval_const_expressions. This is not just an
+ * optimization, but is necessary, because the planner will be comparing
+ * them to similarly-processed qual clauses, and may fail to detect valid
+ * matches without this. We must not use canonicalize_qual, however,
+ * since these aren't qual expressions.
+ */
+ result = (List *) eval_const_expressions(NULL, (Node *) result);
+ }
/* May as well fix opfuncids too */
fix_opfuncids((Node *) result);
@@ -4627,14 +4634,18 @@ RelationGetIndexExpressions(Relation relation)
* RelationGetIndexPredicate -- get the index predicate for an index
*
* We cache the result of transforming pg_index.indpred into an implicit-AND
- * node tree (suitable for use in planning).
+ * node tree suitable for use in planning if "optimize" is true.
* If the rel is not an index or has no predicate, we return NIL.
* Otherwise, the returned tree is copied into the caller's memory context.
* (We don't want to return a pointer to the relcache copy, since it could
* disappear due to relcache invalidation.)
+ *
+ * If "optimize" is true, apply all optimizations to make this result
+ * usable by the planner. Non-optimized expressions are currently used
+ * when creating a concurrent index for REINDEX CONCURRENTLY.
*/
List *
-RelationGetIndexPredicate(Relation relation)
+RelationGetIndexPredicate(Relation relation, bool optimize)
{
List *result;
Datum predDatum;
@@ -4665,24 +4676,28 @@ RelationGetIndexPredicate(Relation relation)
result = (List *) stringToNode(predString);
pfree(predString);
- /*
- * Run the expression through const-simplification and canonicalization.
- * This is not just an optimization, but is necessary, because the planner
- * will be comparing it to similarly-processed qual clauses, and may fail
- * to detect valid matches without this. This must match the processing
- * done to qual clauses in preprocess_expression()! (We can skip the
- * stuff involving subqueries, however, since we don't allow any in index
- * predicates.)
- */
- result = (List *) eval_const_expressions(NULL, (Node *) result);
+ if (optimize)
+ {
+ /*
+ * Run the expression through const-simplification and canonicalization.
+ * This is not just an optimization, but is necessary, because the planner
+ * will be comparing it to similarly-processed qual clauses, and may fail
+ * to detect valid matches without this. This must match the processing
+ * done to qual clauses in preprocess_expression()! (We can skip the
+ * stuff involving subqueries, however, since we don't allow any in index
+ * predicates.)
+ */
+ result = (List *) eval_const_expressions(NULL, (Node *) result);
- result = (List *) canonicalize_qual((Expr *) result, false);
+ result = (List *) canonicalize_qual((Expr *) result, false);
+ }
/* Also convert to implicit-AND format */
result = make_ands_implicit((Expr *) result);
/* May as well fix opfuncids too */
- fix_opfuncids((Node *) result);
+ if (optimize)
+ fix_opfuncids((Node *) result);
/* Now save a copy of the completed tree in the relcache entry. */
oldcxt = MemoryContextSwitchTo(relation->rd_indexcxt);
diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c
index 7b8e67899e..cd963fda3f 100644
--- a/src/backend/utils/sort/tuplesort.c
+++ b/src/backend/utils/sort/tuplesort.c
@@ -915,7 +915,7 @@ tuplesort_begin_cluster(TupleDesc tupDesc,
state->readtup = readtup_cluster;
state->abbrevNext = 10;
- state->indexInfo = BuildIndexInfo(indexRel);
+ state->indexInfo = BuildIndexInfo(indexRel, true);
state->tupDesc = tupDesc; /* assume we need not copy tupDesc */
diff --git a/src/include/catalog/index.h b/src/include/catalog/index.h
index 1113d25b2d..5b9d429e9f 100644
--- a/src/include/catalog/index.h
+++ b/src/include/catalog/index.h
@@ -104,7 +104,7 @@ extern ObjectAddress index_constraint_create(Relation heapRelation,
extern void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode);
-extern IndexInfo *BuildIndexInfo(Relation index);
+extern IndexInfo *BuildIndexInfo(Relation index, bool optimize);
extern bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
Oid *collations1, Oid *collations2,
diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h
index d9c10ffcba..ee96bf0d36 100644
--- a/src/include/utils/relcache.h
+++ b/src/include/utils/relcache.h
@@ -47,8 +47,8 @@ extern List *RelationGetIndexList(Relation relation);
extern List *RelationGetStatExtList(Relation relation);
extern Oid RelationGetPrimaryKeyIndex(Relation relation);
extern Oid RelationGetReplicaIndex(Relation relation);
-extern List *RelationGetIndexExpressions(Relation relation);
-extern List *RelationGetIndexPredicate(Relation relation);
+extern List *RelationGetIndexExpressions(Relation relation, bool optimize);
+extern List *RelationGetIndexPredicate(Relation relation, bool optimize);
typedef enum IndexAttrBitmapKind
{
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 9305649c11..ab419972c8 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -2170,6 +2170,40 @@ Indexes:
"concur_reindex_ind5" UNIQUE, btree (c1)
DROP TABLE concur_reindex_tab4;
+-- Check handling of indexes with expressions and predicates.
+-- Run a couple of commands, then the state of the expression and
+-- predicate tree stored in the catalogs before and after the rebuilds.
+-- Note that the index name is used for the tree comparison as the OID
+-- of an index rebuilt changes.
+CREATE TEMP TABLE concur_reindex_trees (
+ relname text,
+ indexprs_before pg_node_tree,
+ indexprs_after pg_node_tree,
+ indpred_before pg_node_tree,
+ indpred_after pg_node_tree);
+CREATE TABLE concur_exprs_tab (c1 int , c2 boolean);
+INSERT INTO concur_exprs_tab (c1, c2) VALUES (1369652450, FALSE),
+ (414515746, TRUE),
+ (897778963, FALSE);
+CREATE UNIQUE INDEX concur_exprs_index ON concur_exprs_tab ((1 / c1))
+ WHERE ('-H') >= (c2::TEXT) COLLATE "C";
+INSERT INTO concur_reindex_trees (relname, indexprs_before, indpred_before)
+ SELECT indexrelid::regclass, indexprs, indpred FROM pg_index
+ WHERE indexrelid = 'concur_exprs_index'::regclass;
+REINDEX TABLE CONCURRENTLY concur_exprs_tab;
+UPDATE concur_reindex_trees SET (indexprs_after, indpred_after) =
+ (SELECT indexprs, indpred FROM pg_index WHERE indexrelid = 'concur_exprs_index'::regclass)
+ WHERE relname = 'concur_exprs_index';
+SELECT relname,
+ indexprs_before = indexprs_after AS same_exprs,
+ indpred_before = indpred_after AS same_pred
+ FROM concur_reindex_trees;
+ relname | same_exprs | same_pred
+--------------------+------------+-----------
+ concur_exprs_index | f | f
+(1 row)
+
+DROP TABLE concur_exprs_tab;
--
-- REINDEX SCHEMA
--
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index cd46f071bd..c92e107b35 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -872,6 +872,36 @@ REINDEX INDEX CONCURRENTLY concur_reindex_ind5;
\d concur_reindex_tab4
DROP TABLE concur_reindex_tab4;
+-- Check handling of indexes with expressions and predicates.
+-- Run a couple of commands, then the state of the expression and
+-- predicate tree stored in the catalogs before and after the rebuilds.
+-- Note that the index name is used for the tree comparison as the OID
+-- of an index rebuilt changes.
+CREATE TEMP TABLE concur_reindex_trees (
+ relname text,
+ indexprs_before pg_node_tree,
+ indexprs_after pg_node_tree,
+ indpred_before pg_node_tree,
+ indpred_after pg_node_tree);
+CREATE TABLE concur_exprs_tab (c1 int , c2 boolean);
+INSERT INTO concur_exprs_tab (c1, c2) VALUES (1369652450, FALSE),
+ (414515746, TRUE),
+ (897778963, FALSE);
+CREATE UNIQUE INDEX concur_exprs_index ON concur_exprs_tab ((1 / c1))
+ WHERE ('-H') >= (c2::TEXT) COLLATE "C";
+INSERT INTO concur_reindex_trees (relname, indexprs_before, indpred_before)
+ SELECT indexrelid::regclass, indexprs, indpred FROM pg_index
+ WHERE indexrelid = 'concur_exprs_index'::regclass;
+REINDEX TABLE CONCURRENTLY concur_exprs_tab;
+UPDATE concur_reindex_trees SET (indexprs_after, indpred_after) =
+ (SELECT indexprs, indpred FROM pg_index WHERE indexrelid = 'concur_exprs_index'::regclass)
+ WHERE relname = 'concur_exprs_index';
+SELECT relname,
+ indexprs_before = indexprs_after AS same_exprs,
+ indpred_before = indpred_after AS same_pred
+ FROM concur_reindex_trees;
+DROP TABLE concur_exprs_tab;
+
--
-- REINDEX SCHEMA
--
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: REINDEX CONCURRENTLY causes ALTER TABLE to fail
@ 2019-07-21 03:19 Tom Lane <tgl@sss.pgh.pa.us>
parent: Manuel Rigger <rigger.manuel@gmail.com>
1 sibling, 0 replies; 10+ messages in thread
From: Tom Lane @ 2019-07-21 03:19 UTC (permalink / raw)
To: Manuel Rigger <rigger.manuel@gmail.com>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Manuel Rigger <rigger.manuel@gmail.com> writes:
> Consider the following statement sequence:
> CREATE TABLE t0(c0 INTEGER , c1 BOOLEAN);
> INSERT INTO t0(c0, c1) VALUES(1369652450, FALSE), (414515746, TRUE),
> (897778963, FALSE);
> CREATE UNIQUE INDEX i0 ON t0((1 / t0.c0)) WHERE ('-H') >=
> (t0.c1::TEXT) COLLATE "C";
> REINDEX TABLE CONCURRENTLY t0;
> ALTER TABLE t0 ALTER c1 TYPE TEXT; -- could not create unique index
> "i0" DETAIL: Key ((1 / c0))=(0) is duplicated.
> The REINDEX TABLE CONCURRENTLY causes the ALTER TABLE to fail, which
> is unexpected.
BTW, a note for anybody trying to follow along at home --- this example
does not reproduce if the database's default collation is "C".
regards, tom lane
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: REINDEX CONCURRENTLY causes ALTER TABLE to fail
@ 2019-07-22 21:41 Tom Lane <tgl@sss.pgh.pa.us>
parent: Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 10+ messages in thread
From: Tom Lane @ 2019-07-22 21:41 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Manuel Rigger <rigger.manuel@gmail.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Michael Paquier <michael@paquier.xyz> writes:
> I have done some work on that, and for now I am finishing with the
> attached. This takes the approach of updating BuildIndexInfo() so as
> the optimizations for the planner are not done.
This seems like a really bad idea.
As you have it, whether the relcache contains optimized or unoptimized
expressions will be basically chance, depending on which sort of call
happened first after the last cache flush. That will break things,
because for most use-cases it's *not* optional to apply
eval_const_expressions.
Even without that, changing the APIs of the functions you've touched
here seems pretty invasive.
I think the correct fix is to nuke the code in REINDEX CONCURRENTLY that
thinks it should use any of this infrastructure to fetch the existing
index properties, and just have it read the catalog directly instead.
regards, tom lane
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: REINDEX CONCURRENTLY causes ALTER TABLE to fail
@ 2019-07-23 04:28 Michael Paquier <michael@paquier.xyz>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 10+ messages in thread
From: Michael Paquier @ 2019-07-23 04:28 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Manuel Rigger <rigger.manuel@gmail.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
On Mon, Jul 22, 2019 at 05:41:26PM -0400, Tom Lane wrote:
> I think the correct fix is to nuke the code in REINDEX CONCURRENTLY that
> thinks it should use any of this infrastructure to fetch the existing
> index properties, and just have it read the catalog directly instead.
Okay. Sharing a maximum the build of IndexInfo done as part of
DefineIndex is something that we should do then. Attached is a patch
that I have been working on, introducing a new makeIndexInfo() in
makefuncs.c. Still as IndexInfo is not a parse node but an exec node,
I am including execnodes.h in makefuncs.h for now (perhaps somebody
has a better idea?). This fills the index information of the new
entry directly from the catalog of the old entry for expressions and
predicates.
I have let BuildIndexInfo out of that as ii_ReadyForInserts can change
for system catalogs during bootstrap. I have also reworked the test
case to just use pg_get_indexdef() which is enough to show the
original bug as after the initial REINDEX CONCURRENTLY the collation
part goes missing when testing on HEAD. Predicates need to properly
be formatted with an implicit-AND format by the way.
Thoughts?
--
Michael
Attachments:
reindex-conc-predicates-v2.patch (text/x-diff, 12.5K) download
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 9234e93261..4a85e57b5b 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -1197,7 +1197,7 @@ Oid
index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, const char *newName)
{
Relation indexRelation;
- IndexInfo *indexInfo;
+ IndexInfo *oldInfo, *newInfo;
Oid newIndexId = InvalidOid;
HeapTuple indexTuple,
classTuple;
@@ -1208,11 +1208,22 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, const char
int2vector *indcoloptions;
bool isnull;
List *indexColNames = NIL;
+ List *indexExprs = NIL;
+ List *indexPreds = NIL;
indexRelation = index_open(oldIndexId, RowExclusiveLock);
- /* New index uses the same index information as old index */
- indexInfo = BuildIndexInfo(indexRelation);
+ /* The new index needs some information from the old index */
+ oldInfo = BuildIndexInfo(indexRelation);
+
+ /*
+ * Concurrent build of an index with exclusion constraints is not
+ * supported.
+ */
+ if (oldInfo->ii_ExclusionOps != NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("concurrent index creation for exclusion constraints is not supported")));
/* Get the array of class and column options IDs from index info */
indexTuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(oldIndexId));
@@ -1236,14 +1247,64 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, const char
Anum_pg_class_reloptions, &isnull);
/*
- * Extract the list of column names to be used for the index creation.
+ * Fetch the list of expressions and predicates directly from the
+ * catalogs. We cannot rely on the information fetched previously
+ * from the old index as this has been flattened for the planner.
*/
- for (int i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
+ if (oldInfo->ii_Expressions != NIL)
+ {
+ Datum exprDatum;
+ char *exprString;
+
+ exprDatum = SysCacheGetAttr(INDEXRELID, indexTuple,
+ Anum_pg_index_indexprs, &isnull);
+ Assert(!isnull);
+ exprString = TextDatumGetCString(exprDatum);
+ indexExprs = (List *) stringToNode(exprString);
+ pfree(exprString);
+ }
+ if (oldInfo->ii_Predicate != NIL)
+ {
+ Datum predDatum;
+ char *predString;
+
+ predDatum = SysCacheGetAttr(INDEXRELID, indexTuple,
+ Anum_pg_index_indpred, &isnull);
+ Assert(!isnull);
+ predString = TextDatumGetCString(predDatum);
+ indexPreds = (List *) stringToNode(predString);
+
+ /* Also convert to implicit-AND format */
+ indexPreds = make_ands_implicit((Expr *) indexPreds);
+ pfree(predString);
+ }
+
+ /*
+ * Build the index information for the new index. Note that rebuild of
+ * indexes with exclusion constraints is not supported, hence there is
+ * no need to fill all the ii_Exclusion* fields.
+ */
+ newInfo = makeIndexInfo(oldInfo->ii_NumIndexAttrs,
+ oldInfo->ii_NumIndexKeyAttrs,
+ oldInfo->ii_Am,
+ indexExprs,
+ indexPreds,
+ oldInfo->ii_Unique,
+ false, /* not ready for inserts */
+ true);
+
+ /*
+ * Extract the list of column names and the column numbers for the new
+ * index information. All this information will be used for the index
+ * creation.
+ */
+ for (int i = 0; i < oldInfo->ii_NumIndexAttrs; i++)
{
TupleDesc indexTupDesc = RelationGetDescr(indexRelation);
Form_pg_attribute att = TupleDescAttr(indexTupDesc, i);
indexColNames = lappend(indexColNames, NameStr(att->attname));
+ newInfo->ii_IndexAttrNumbers[i] = oldInfo->ii_IndexAttrNumbers[i];
}
/*
@@ -1259,7 +1320,7 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, const char
InvalidOid, /* parentIndexRelid */
InvalidOid, /* parentConstraintId */
InvalidOid, /* relFileNode */
- indexInfo,
+ newInfo,
indexColNames,
indexRelation->rd_rel->relam,
indexRelation->rd_rel->reltablespace,
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index fd299273c5..ce1c6f3b09 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -202,18 +202,8 @@ CheckIndexCompatible(Oid oldId,
* contains only key attributes, thus we're filling ii_NumIndexAttrs and
* ii_NumIndexKeyAttrs with same value.
*/
- indexInfo = makeNode(IndexInfo);
- indexInfo->ii_NumIndexAttrs = numberOfAttributes;
- indexInfo->ii_NumIndexKeyAttrs = numberOfAttributes;
- indexInfo->ii_Expressions = NIL;
- indexInfo->ii_ExpressionsState = NIL;
- indexInfo->ii_PredicateState = NULL;
- indexInfo->ii_ExclusionOps = NULL;
- indexInfo->ii_ExclusionProcs = NULL;
- indexInfo->ii_ExclusionStrats = NULL;
- indexInfo->ii_Am = accessMethodId;
- indexInfo->ii_AmCache = NULL;
- indexInfo->ii_Context = CurrentMemoryContext;
+ indexInfo = makeIndexInfo(numberOfAttributes, numberOfAttributes,
+ accessMethodId, NIL, NIL, false, false, false);
typeObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
collationObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
classObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
@@ -780,27 +770,17 @@ DefineIndex(Oid relationId,
/*
* Prepare arguments for index_create, primarily an IndexInfo structure.
- * Note that ii_Predicate must be in implicit-AND format.
+ * Note that predicates must be in implicit-AND format. In a concurrent
+ * build, mark it not-ready-for-inserts.
*/
- indexInfo = makeNode(IndexInfo);
- indexInfo->ii_NumIndexAttrs = numberOfAttributes;
- indexInfo->ii_NumIndexKeyAttrs = numberOfKeyAttributes;
- indexInfo->ii_Expressions = NIL; /* for now */
- indexInfo->ii_ExpressionsState = NIL;
- indexInfo->ii_Predicate = make_ands_implicit((Expr *) stmt->whereClause);
- indexInfo->ii_PredicateState = NULL;
- indexInfo->ii_ExclusionOps = NULL;
- indexInfo->ii_ExclusionProcs = NULL;
- indexInfo->ii_ExclusionStrats = NULL;
- indexInfo->ii_Unique = stmt->unique;
- /* In a concurrent build, mark it not-ready-for-inserts */
- indexInfo->ii_ReadyForInserts = !stmt->concurrent;
- indexInfo->ii_Concurrent = stmt->concurrent;
- indexInfo->ii_BrokenHotChain = false;
- indexInfo->ii_ParallelWorkers = 0;
- indexInfo->ii_Am = accessMethodId;
- indexInfo->ii_AmCache = NULL;
- indexInfo->ii_Context = CurrentMemoryContext;
+ indexInfo = makeIndexInfo(numberOfAttributes,
+ numberOfKeyAttributes,
+ accessMethodId,
+ NIL, /* expressions, NIL for now */
+ make_ands_implicit((Expr *) stmt->whereClause),
+ stmt->unique,
+ !stmt->concurrent,
+ stmt->concurrent);
typeObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
collationObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c
index 7085ed2c4c..967c4bdf6b 100644
--- a/src/backend/nodes/makefuncs.c
+++ b/src/backend/nodes/makefuncs.c
@@ -733,6 +733,54 @@ make_ands_implicit(Expr *clause)
return list_make1(clause);
}
+/*
+ * makeIndexInfo
+ * create an IndexInfo node
+ */
+IndexInfo *
+makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions,
+ List *predicates, bool unique, bool isready, bool concurrent)
+{
+ IndexInfo *n = makeNode(IndexInfo);
+
+ n->ii_NumIndexAttrs = numattrs;
+ n->ii_NumIndexKeyAttrs = numkeyattrs;
+ Assert(n->ii_NumIndexKeyAttrs != 0);
+ Assert(n->ii_NumIndexKeyAttrs <= n->ii_NumIndexAttrs);
+ n->ii_Unique = unique;
+ n->ii_ReadyForInserts = isready;
+ n->ii_Concurrent = concurrent;
+
+ /* expressions */
+ n->ii_Expressions = expressions;
+ n->ii_ExpressionsState = NIL;
+
+ /* predicates */
+ n->ii_Predicate = predicates;
+ n->ii_PredicateState = NULL;
+
+ /* exclusion constraints */
+ n->ii_ExclusionOps = NULL;
+ n->ii_ExclusionProcs = NULL;
+ n->ii_ExclusionStrats = NULL;
+
+ /* speculative inserts */
+ n->ii_UniqueOps = NULL;
+ n->ii_UniqueProcs = NULL;
+ n->ii_UniqueStrats = NULL;
+
+ /* initialize index-build state to default */
+ n->ii_BrokenHotChain = false;
+ n->ii_ParallelWorkers = 0;
+
+ /* set up for possible use by index AM */
+ n->ii_Am = amoid;
+ n->ii_AmCache = NULL;
+ n->ii_Context = CurrentMemoryContext;
+
+ return n;
+}
+
/*
* makeGroupingSet
*
diff --git a/src/include/nodes/makefuncs.h b/src/include/nodes/makefuncs.h
index ad7b41d4aa..5bfd6ac1a2 100644
--- a/src/include/nodes/makefuncs.h
+++ b/src/include/nodes/makefuncs.h
@@ -14,6 +14,7 @@
#ifndef MAKEFUNC_H
#define MAKEFUNC_H
+#include "nodes/execnodes.h"
#include "nodes/parsenodes.h"
@@ -92,6 +93,10 @@ extern Node *make_and_qual(Node *qual1, Node *qual2);
extern Expr *make_ands_explicit(List *andclauses);
extern List *make_ands_implicit(Expr *clause);
+extern IndexInfo *makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid,
+ List *expressions, List *predicates,
+ bool unique, bool isready, bool concurrent);
+
extern DefElem *makeDefElem(char *name, Node *arg, int location);
extern DefElem *makeDefElemExtended(char *nameSpace, char *name, Node *arg,
DefElemAction defaction, int location);
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 9305649c11..161cc94e6c 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -2170,6 +2170,36 @@ Indexes:
"concur_reindex_ind5" UNIQUE, btree (c1)
DROP TABLE concur_reindex_tab4;
+-- Check handling of indexes with expressions and predicates.
+-- The definition of the rebuilt index should matche the original definition.
+CREATE TABLE concur_exprs_tab (c1 int , c2 boolean);
+INSERT INTO concur_exprs_tab (c1, c2) VALUES (1369652450, FALSE),
+ (414515746, TRUE),
+ (897778963, FALSE);
+CREATE UNIQUE INDEX concur_exprs_index ON concur_exprs_tab ((1 / c1))
+ WHERE ('-H') >= (c2::TEXT) COLLATE "C";
+SELECT pg_get_indexdef('concur_exprs_index'::regclass);
+ pg_get_indexdef
+-------------------------------------------------------------------------------------------------------------------------------------------
+ CREATE UNIQUE INDEX concur_exprs_index ON public.concur_exprs_tab USING btree (((1 / c1))) WHERE ('-H'::text >= ((c2)::text COLLATE "C"))
+(1 row)
+
+REINDEX TABLE CONCURRENTLY concur_exprs_tab;
+SELECT pg_get_indexdef('concur_exprs_index'::regclass);
+ pg_get_indexdef
+-------------------------------------------------------------------------------------------------------------------------------------------
+ CREATE UNIQUE INDEX concur_exprs_index ON public.concur_exprs_tab USING btree (((1 / c1))) WHERE ('-H'::text >= ((c2)::text COLLATE "C"))
+(1 row)
+
+-- ALTER TABLE recreates the index, which should keep its collation.
+ALTER TABLE concur_exprs_tab ALTER c2 TYPE TEXT;
+SELECT pg_get_indexdef('concur_exprs_index'::regclass);
+ pg_get_indexdef
+-----------------------------------------------------------------------------------------------------------------------------------
+ CREATE UNIQUE INDEX concur_exprs_index ON public.concur_exprs_tab USING btree (((1 / c1))) WHERE ('-H'::text >= (c2 COLLATE "C"))
+(1 row)
+
+DROP TABLE concur_exprs_tab;
--
-- REINDEX SCHEMA
--
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index cd46f071bd..63c796ce6e 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -872,6 +872,22 @@ REINDEX INDEX CONCURRENTLY concur_reindex_ind5;
\d concur_reindex_tab4
DROP TABLE concur_reindex_tab4;
+-- Check handling of indexes with expressions and predicates.
+-- The definition of the rebuilt index should matche the original definition.
+CREATE TABLE concur_exprs_tab (c1 int , c2 boolean);
+INSERT INTO concur_exprs_tab (c1, c2) VALUES (1369652450, FALSE),
+ (414515746, TRUE),
+ (897778963, FALSE);
+CREATE UNIQUE INDEX concur_exprs_index ON concur_exprs_tab ((1 / c1))
+ WHERE ('-H') >= (c2::TEXT) COLLATE "C";
+SELECT pg_get_indexdef('concur_exprs_index'::regclass);
+REINDEX TABLE CONCURRENTLY concur_exprs_tab;
+SELECT pg_get_indexdef('concur_exprs_index'::regclass);
+-- ALTER TABLE recreates the index, which should keep its collation.
+ALTER TABLE concur_exprs_tab ALTER c2 TYPE TEXT;
+SELECT pg_get_indexdef('concur_exprs_index'::regclass);
+DROP TABLE concur_exprs_tab;
+
--
-- REINDEX SCHEMA
--
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: REINDEX CONCURRENTLY causes ALTER TABLE to fail
@ 2019-07-25 10:31 Michael Paquier <michael@paquier.xyz>
parent: Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 10+ messages in thread
From: Michael Paquier @ 2019-07-25 10:31 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Manuel Rigger <rigger.manuel@gmail.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
On Tue, Jul 23, 2019 at 01:28:38PM +0900, Michael Paquier wrote:
> Okay. Sharing a maximum the build of IndexInfo done as part of
> DefineIndex is something that we should do then. Attached is a patch
> that I have been working on, introducing a new makeIndexInfo() in
> makefuncs.c. Still as IndexInfo is not a parse node but an exec node,
> I am including execnodes.h in makefuncs.h for now (perhaps somebody
> has a better idea?). This fills the index information of the new
> entry directly from the catalog of the old entry for expressions and
> predicates.
I have been looking at this code today and extended the test cases
with more expression and predicate indexes to stress more the patch,
and it happens that I am still stuck for with makeIndexInfo(). The
header comments of makefuncs.h and makefuncs.c mention primitive
nodes, so I would need at least to update that part to mention
execution nodes. Still I'd rather not have people scream at me as
that could be considered invasive in terms of included dependencies
for makefuncs.c :)
If we don't have the makeIndexInfo wrapper, please note that we finish
by filling in three times IndexInfo with roughly the same data in
different places, so I would like to keep it.
So, are there any opinions or ideas about that?
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: REINDEX CONCURRENTLY causes ALTER TABLE to fail
@ 2019-07-26 00:34 Michael Paquier <michael@paquier.xyz>
parent: Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 10+ messages in thread
From: Michael Paquier @ 2019-07-26 00:34 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Manuel Rigger <rigger.manuel@gmail.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
On Thu, Jul 25, 2019 at 07:31:13PM +0900, Michael Paquier wrote:
> I have been looking at this code today and extended the test cases
> with more expression and predicate indexes to stress more the patch,
> and it happens that I am still stuck for with makeIndexInfo(). The
> header comments of makefuncs.h and makefuncs.c mention primitive
> nodes, so I would need at least to update that part to mention
> execution nodes. Still I'd rather not have people scream at me as
> that could be considered invasive in terms of included dependencies
> for makefuncs.c :)
After an extra round of polishing, I am finishing with the attached
and the following change for makefuncs.h:
* makefuncs.h
- * prototypes for the creator functions (for primitive nodes)
+ * prototypes for the creator functions for various nodes
Any objections with this version? Please note that the predicates and
expressions are fetched directly from the catalogs, and that we does
not rely on the relcache anymore.
--
Michael
Attachments:
reindex-conc-predicates-v3.patch (text/x-diff, 16.9K) download
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 9234e93261..6aac64c4cf 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -1197,7 +1197,8 @@ Oid
index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, const char *newName)
{
Relation indexRelation;
- IndexInfo *indexInfo;
+ IndexInfo *oldInfo,
+ *newInfo;
Oid newIndexId = InvalidOid;
HeapTuple indexTuple,
classTuple;
@@ -1208,11 +1209,22 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, const char
int2vector *indcoloptions;
bool isnull;
List *indexColNames = NIL;
+ List *indexExprs = NIL;
+ List *indexPreds = NIL;
indexRelation = index_open(oldIndexId, RowExclusiveLock);
- /* New index uses the same index information as old index */
- indexInfo = BuildIndexInfo(indexRelation);
+ /* The new index needs some information from the old index */
+ oldInfo = BuildIndexInfo(indexRelation);
+
+ /*
+ * Concurrent build of an index with exclusion constraints is not
+ * supported.
+ */
+ if (oldInfo->ii_ExclusionOps != NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("concurrent index creation for exclusion constraints is not supported")));
/* Get the array of class and column options IDs from index info */
indexTuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(oldIndexId));
@@ -1236,14 +1248,64 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, const char
Anum_pg_class_reloptions, &isnull);
/*
- * Extract the list of column names to be used for the index creation.
+ * Fetch the list of expressions and predicates directly from the
+ * catalogs. This cannot rely on the information from IndexInfo for the
+ * old index as these have been flattened for the planner.
*/
- for (int i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
+ if (oldInfo->ii_Expressions != NIL)
+ {
+ Datum exprDatum;
+ char *exprString;
+
+ exprDatum = SysCacheGetAttr(INDEXRELID, indexTuple,
+ Anum_pg_index_indexprs, &isnull);
+ Assert(!isnull);
+ exprString = TextDatumGetCString(exprDatum);
+ indexExprs = (List *) stringToNode(exprString);
+ pfree(exprString);
+ }
+ if (oldInfo->ii_Predicate != NIL)
+ {
+ Datum predDatum;
+ char *predString;
+
+ predDatum = SysCacheGetAttr(INDEXRELID, indexTuple,
+ Anum_pg_index_indpred, &isnull);
+ Assert(!isnull);
+ predString = TextDatumGetCString(predDatum);
+ indexPreds = (List *) stringToNode(predString);
+
+ /* Also convert to implicit-AND format */
+ indexPreds = make_ands_implicit((Expr *) indexPreds);
+ pfree(predString);
+ }
+
+ /*
+ * Build the index information for the new index. Note that rebuild of
+ * indexes with exclusion constraints is not supported, hence there is no
+ * need to fill all the ii_Exclusion* fields.
+ */
+ newInfo = makeIndexInfo(oldInfo->ii_NumIndexAttrs,
+ oldInfo->ii_NumIndexKeyAttrs,
+ oldInfo->ii_Am,
+ indexExprs,
+ indexPreds,
+ oldInfo->ii_Unique,
+ false, /* not ready for inserts */
+ true);
+
+ /*
+ * Extract the list of column names and the column numbers for the new
+ * index information. All this information will be used for the index
+ * creation.
+ */
+ for (int i = 0; i < oldInfo->ii_NumIndexAttrs; i++)
{
TupleDesc indexTupDesc = RelationGetDescr(indexRelation);
Form_pg_attribute att = TupleDescAttr(indexTupDesc, i);
indexColNames = lappend(indexColNames, NameStr(att->attname));
+ newInfo->ii_IndexAttrNumbers[i] = oldInfo->ii_IndexAttrNumbers[i];
}
/*
@@ -1259,7 +1321,7 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, const char
InvalidOid, /* parentIndexRelid */
InvalidOid, /* parentConstraintId */
InvalidOid, /* relFileNode */
- indexInfo,
+ newInfo,
indexColNames,
indexRelation->rd_rel->relam,
indexRelation->rd_rel->reltablespace,
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index fd299273c5..8dc7a39870 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -202,18 +202,8 @@ CheckIndexCompatible(Oid oldId,
* contains only key attributes, thus we're filling ii_NumIndexAttrs and
* ii_NumIndexKeyAttrs with same value.
*/
- indexInfo = makeNode(IndexInfo);
- indexInfo->ii_NumIndexAttrs = numberOfAttributes;
- indexInfo->ii_NumIndexKeyAttrs = numberOfAttributes;
- indexInfo->ii_Expressions = NIL;
- indexInfo->ii_ExpressionsState = NIL;
- indexInfo->ii_PredicateState = NULL;
- indexInfo->ii_ExclusionOps = NULL;
- indexInfo->ii_ExclusionProcs = NULL;
- indexInfo->ii_ExclusionStrats = NULL;
- indexInfo->ii_Am = accessMethodId;
- indexInfo->ii_AmCache = NULL;
- indexInfo->ii_Context = CurrentMemoryContext;
+ indexInfo = makeIndexInfo(numberOfAttributes, numberOfAttributes,
+ accessMethodId, NIL, NIL, false, false, false);
typeObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
collationObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
classObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
@@ -780,27 +770,17 @@ DefineIndex(Oid relationId,
/*
* Prepare arguments for index_create, primarily an IndexInfo structure.
- * Note that ii_Predicate must be in implicit-AND format.
+ * Note that predicates must be in implicit-AND format. In a concurrent
+ * build, mark it not-ready-for-inserts.
*/
- indexInfo = makeNode(IndexInfo);
- indexInfo->ii_NumIndexAttrs = numberOfAttributes;
- indexInfo->ii_NumIndexKeyAttrs = numberOfKeyAttributes;
- indexInfo->ii_Expressions = NIL; /* for now */
- indexInfo->ii_ExpressionsState = NIL;
- indexInfo->ii_Predicate = make_ands_implicit((Expr *) stmt->whereClause);
- indexInfo->ii_PredicateState = NULL;
- indexInfo->ii_ExclusionOps = NULL;
- indexInfo->ii_ExclusionProcs = NULL;
- indexInfo->ii_ExclusionStrats = NULL;
- indexInfo->ii_Unique = stmt->unique;
- /* In a concurrent build, mark it not-ready-for-inserts */
- indexInfo->ii_ReadyForInserts = !stmt->concurrent;
- indexInfo->ii_Concurrent = stmt->concurrent;
- indexInfo->ii_BrokenHotChain = false;
- indexInfo->ii_ParallelWorkers = 0;
- indexInfo->ii_Am = accessMethodId;
- indexInfo->ii_AmCache = NULL;
- indexInfo->ii_Context = CurrentMemoryContext;
+ indexInfo = makeIndexInfo(numberOfAttributes,
+ numberOfKeyAttributes,
+ accessMethodId,
+ NIL, /* expressions, NIL for now */
+ make_ands_implicit((Expr *) stmt->whereClause),
+ stmt->unique,
+ !stmt->concurrent,
+ stmt->concurrent);
typeObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
collationObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c
index 7085ed2c4c..5c11b5472e 100644
--- a/src/backend/nodes/makefuncs.c
+++ b/src/backend/nodes/makefuncs.c
@@ -1,8 +1,8 @@
/*-------------------------------------------------------------------------
*
* makefuncs.c
- * creator functions for primitive nodes. The functions here are for
- * the most frequently created nodes.
+ * creator functions for various nodes. The functions here are for the
+ * most frequently created nodes.
*
* Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
@@ -733,6 +733,54 @@ make_ands_implicit(Expr *clause)
return list_make1(clause);
}
+/*
+ * makeIndexInfo
+ * create an IndexInfo node
+ */
+IndexInfo *
+makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions,
+ List *predicates, bool unique, bool isready, bool concurrent)
+{
+ IndexInfo *n = makeNode(IndexInfo);
+
+ n->ii_NumIndexAttrs = numattrs;
+ n->ii_NumIndexKeyAttrs = numkeyattrs;
+ Assert(n->ii_NumIndexKeyAttrs != 0);
+ Assert(n->ii_NumIndexKeyAttrs <= n->ii_NumIndexAttrs);
+ n->ii_Unique = unique;
+ n->ii_ReadyForInserts = isready;
+ n->ii_Concurrent = concurrent;
+
+ /* expressions */
+ n->ii_Expressions = expressions;
+ n->ii_ExpressionsState = NIL;
+
+ /* predicates */
+ n->ii_Predicate = predicates;
+ n->ii_PredicateState = NULL;
+
+ /* exclusion constraints */
+ n->ii_ExclusionOps = NULL;
+ n->ii_ExclusionProcs = NULL;
+ n->ii_ExclusionStrats = NULL;
+
+ /* speculative inserts */
+ n->ii_UniqueOps = NULL;
+ n->ii_UniqueProcs = NULL;
+ n->ii_UniqueStrats = NULL;
+
+ /* initialize index-build state to default */
+ n->ii_BrokenHotChain = false;
+ n->ii_ParallelWorkers = 0;
+
+ /* set up for possible use by index AM */
+ n->ii_Am = amoid;
+ n->ii_AmCache = NULL;
+ n->ii_Context = CurrentMemoryContext;
+
+ return n;
+}
+
/*
* makeGroupingSet
*
diff --git a/src/include/nodes/makefuncs.h b/src/include/nodes/makefuncs.h
index ad7b41d4aa..232bee21c1 100644
--- a/src/include/nodes/makefuncs.h
+++ b/src/include/nodes/makefuncs.h
@@ -1,7 +1,7 @@
/*-------------------------------------------------------------------------
*
* makefuncs.h
- * prototypes for the creator functions (for primitive nodes)
+ * prototypes for the creator functions for various nodes
*
*
* Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
@@ -14,6 +14,7 @@
#ifndef MAKEFUNC_H
#define MAKEFUNC_H
+#include "nodes/execnodes.h"
#include "nodes/parsenodes.h"
@@ -92,6 +93,10 @@ extern Node *make_and_qual(Node *qual1, Node *qual2);
extern Expr *make_ands_explicit(List *andclauses);
extern List *make_ands_implicit(Expr *clause);
+extern IndexInfo *makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid,
+ List *expressions, List *predicates,
+ bool unique, bool isready, bool concurrent);
+
extern DefElem *makeDefElem(char *name, Node *arg, int location);
extern DefElem *makeDefElemExtended(char *nameSpace, char *name, Node *arg,
DefElemAction defaction, int location);
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index 9305649c11..c6d575a2f9 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -2170,6 +2170,78 @@ Indexes:
"concur_reindex_ind5" UNIQUE, btree (c1)
DROP TABLE concur_reindex_tab4;
+-- Check handling of indexes with expressions and predicates. The
+-- definitions of the rebuilt indexes should match the original
+-- definitions.
+CREATE TABLE concur_exprs_tab (c1 int , c2 boolean);
+INSERT INTO concur_exprs_tab (c1, c2) VALUES (1369652450, FALSE),
+ (414515746, TRUE),
+ (897778963, FALSE);
+CREATE UNIQUE INDEX concur_exprs_index_expr
+ ON concur_exprs_tab ((c1::text COLLATE "C"));
+CREATE UNIQUE INDEX concur_exprs_index_pred ON concur_exprs_tab (c1)
+ WHERE (c1::text > 500000000::text COLLATE "C");
+CREATE UNIQUE INDEX concur_exprs_index_pred_2
+ ON concur_exprs_tab ((1 / c1))
+ WHERE ('-H') >= (c2::TEXT) COLLATE "C";
+SELECT pg_get_indexdef('concur_exprs_index_expr'::regclass);
+ pg_get_indexdef
+---------------------------------------------------------------------------------------------------------------
+ CREATE UNIQUE INDEX concur_exprs_index_expr ON public.concur_exprs_tab USING btree (((c1)::text) COLLATE "C")
+(1 row)
+
+SELECT pg_get_indexdef('concur_exprs_index_pred'::regclass);
+ pg_get_indexdef
+----------------------------------------------------------------------------------------------------------------------------------------------
+ CREATE UNIQUE INDEX concur_exprs_index_pred ON public.concur_exprs_tab USING btree (c1) WHERE ((c1)::text > ((500000000)::text COLLATE "C"))
+(1 row)
+
+SELECT pg_get_indexdef('concur_exprs_index_pred_2'::regclass);
+ pg_get_indexdef
+--------------------------------------------------------------------------------------------------------------------------------------------------
+ CREATE UNIQUE INDEX concur_exprs_index_pred_2 ON public.concur_exprs_tab USING btree (((1 / c1))) WHERE ('-H'::text >= ((c2)::text COLLATE "C"))
+(1 row)
+
+REINDEX TABLE CONCURRENTLY concur_exprs_tab;
+SELECT pg_get_indexdef('concur_exprs_index_expr'::regclass);
+ pg_get_indexdef
+---------------------------------------------------------------------------------------------------------------
+ CREATE UNIQUE INDEX concur_exprs_index_expr ON public.concur_exprs_tab USING btree (((c1)::text) COLLATE "C")
+(1 row)
+
+SELECT pg_get_indexdef('concur_exprs_index_pred'::regclass);
+ pg_get_indexdef
+----------------------------------------------------------------------------------------------------------------------------------------------
+ CREATE UNIQUE INDEX concur_exprs_index_pred ON public.concur_exprs_tab USING btree (c1) WHERE ((c1)::text > ((500000000)::text COLLATE "C"))
+(1 row)
+
+SELECT pg_get_indexdef('concur_exprs_index_pred_2'::regclass);
+ pg_get_indexdef
+--------------------------------------------------------------------------------------------------------------------------------------------------
+ CREATE UNIQUE INDEX concur_exprs_index_pred_2 ON public.concur_exprs_tab USING btree (((1 / c1))) WHERE ('-H'::text >= ((c2)::text COLLATE "C"))
+(1 row)
+
+-- ALTER TABLE recreates the indexes, which should keep their collations.
+ALTER TABLE concur_exprs_tab ALTER c2 TYPE TEXT;
+SELECT pg_get_indexdef('concur_exprs_index_expr'::regclass);
+ pg_get_indexdef
+---------------------------------------------------------------------------------------------------------------
+ CREATE UNIQUE INDEX concur_exprs_index_expr ON public.concur_exprs_tab USING btree (((c1)::text) COLLATE "C")
+(1 row)
+
+SELECT pg_get_indexdef('concur_exprs_index_pred'::regclass);
+ pg_get_indexdef
+----------------------------------------------------------------------------------------------------------------------------------------------
+ CREATE UNIQUE INDEX concur_exprs_index_pred ON public.concur_exprs_tab USING btree (c1) WHERE ((c1)::text > ((500000000)::text COLLATE "C"))
+(1 row)
+
+SELECT pg_get_indexdef('concur_exprs_index_pred_2'::regclass);
+ pg_get_indexdef
+------------------------------------------------------------------------------------------------------------------------------------------
+ CREATE UNIQUE INDEX concur_exprs_index_pred_2 ON public.concur_exprs_tab USING btree (((1 / c1))) WHERE ('-H'::text >= (c2 COLLATE "C"))
+(1 row)
+
+DROP TABLE concur_exprs_tab;
--
-- REINDEX SCHEMA
--
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index cd46f071bd..f96bebf410 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -872,6 +872,34 @@ REINDEX INDEX CONCURRENTLY concur_reindex_ind5;
\d concur_reindex_tab4
DROP TABLE concur_reindex_tab4;
+-- Check handling of indexes with expressions and predicates. The
+-- definitions of the rebuilt indexes should match the original
+-- definitions.
+CREATE TABLE concur_exprs_tab (c1 int , c2 boolean);
+INSERT INTO concur_exprs_tab (c1, c2) VALUES (1369652450, FALSE),
+ (414515746, TRUE),
+ (897778963, FALSE);
+CREATE UNIQUE INDEX concur_exprs_index_expr
+ ON concur_exprs_tab ((c1::text COLLATE "C"));
+CREATE UNIQUE INDEX concur_exprs_index_pred ON concur_exprs_tab (c1)
+ WHERE (c1::text > 500000000::text COLLATE "C");
+CREATE UNIQUE INDEX concur_exprs_index_pred_2
+ ON concur_exprs_tab ((1 / c1))
+ WHERE ('-H') >= (c2::TEXT) COLLATE "C";
+SELECT pg_get_indexdef('concur_exprs_index_expr'::regclass);
+SELECT pg_get_indexdef('concur_exprs_index_pred'::regclass);
+SELECT pg_get_indexdef('concur_exprs_index_pred_2'::regclass);
+REINDEX TABLE CONCURRENTLY concur_exprs_tab;
+SELECT pg_get_indexdef('concur_exprs_index_expr'::regclass);
+SELECT pg_get_indexdef('concur_exprs_index_pred'::regclass);
+SELECT pg_get_indexdef('concur_exprs_index_pred_2'::regclass);
+-- ALTER TABLE recreates the indexes, which should keep their collations.
+ALTER TABLE concur_exprs_tab ALTER c2 TYPE TEXT;
+SELECT pg_get_indexdef('concur_exprs_index_expr'::regclass);
+SELECT pg_get_indexdef('concur_exprs_index_pred'::regclass);
+SELECT pg_get_indexdef('concur_exprs_index_pred_2'::regclass);
+DROP TABLE concur_exprs_tab;
+
--
-- REINDEX SCHEMA
--
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: REINDEX CONCURRENTLY causes ALTER TABLE to fail
@ 2019-07-29 01:10 Michael Paquier <michael@paquier.xyz>
parent: Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 10+ messages in thread
From: Michael Paquier @ 2019-07-29 01:10 UTC (permalink / raw)
To: Postgres bugs <pgsql-bugs@lists.postgresql.org>; +Cc: Manuel Rigger <rigger.manuel@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>
On Fri, Jul 26, 2019 at 09:34:13AM +0900, Michael Paquier wrote:
> Any objections with this version? Please note that the predicates and
> expressions are fetched directly from the catalogs, and that we does
> not rely on the relcache anymore.
Hearing nothing, applied and back-patched down to v12. Thanks Manuel
for the report!
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: REINDEX CONCURRENTLY causes ALTER TABLE to fail
@ 2019-07-29 07:22 Manuel Rigger <rigger.manuel@gmail.com>
parent: Michael Paquier <michael@paquier.xyz>
0 siblings, 0 replies; 10+ messages in thread
From: Manuel Rigger @ 2019-07-29 07:22 UTC (permalink / raw)
To: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>
Thanks a lot for fixing this, Michael!
Best,
Manuel
On Mon, Jul 29, 2019 at 3:10 AM Michael Paquier <michael@paquier.xyz> wrote:
>
> On Fri, Jul 26, 2019 at 09:34:13AM +0900, Michael Paquier wrote:
> > Any objections with this version? Please note that the predicates and
> > expressions are fetched directly from the catalogs, and that we does
> > not rely on the relcache anymore.
>
> Hearing nothing, applied and back-patched down to v12. Thanks Manuel
> for the report!
> --
> Michael
^ permalink raw reply [nested|flat] 10+ messages in thread
end of thread, other threads:[~2019-07-29 07:22 UTC | newest]
Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-07-17 12:53 REINDEX CONCURRENTLY causes ALTER TABLE to fail Manuel Rigger <rigger.manuel@gmail.com>
2019-07-18 03:02 ` Michael Paquier <michael@paquier.xyz>
2019-07-18 04:25 ` Michael Paquier <michael@paquier.xyz>
2019-07-22 21:41 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-07-23 04:28 ` Michael Paquier <michael@paquier.xyz>
2019-07-25 10:31 ` Michael Paquier <michael@paquier.xyz>
2019-07-26 00:34 ` Michael Paquier <michael@paquier.xyz>
2019-07-29 01:10 ` Michael Paquier <michael@paquier.xyz>
2019-07-29 07:22 ` Manuel Rigger <rigger.manuel@gmail.com>
2019-07-21 03:19 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox