BUG #17997: Assert failed in validatePartitionedIndex() when attaching partition index to child of valid index - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #17997: Assert failed in validatePartitionedIndex() when attaching partition index to child of valid index
Date
Msg-id 17997-a044c27aef95daf8@postgresql.org
Whole thread Raw
Responses Re: BUG #17997: Assert failed in validatePartitionedIndex() when attaching partition index to child of valid index
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      17997
Logged by:          Alexander Lakhin
Email address:      exclusion@gmail.com
PostgreSQL version: 16beta1
Operating system:   Ubuntu 22.04
Description:

The following script:
create table t(a int) partition by range (a);
create index on t(a);
create table tp1(a int) partition by range (a);
create table tp1_1 partition of tp1 for values from (1) to (10);
create index on only tp1(a);
alter table t attach partition tp1 for values from (1) to (100);
create index on tp1_1(a);
\d+ t
\d+ tp1
alter index tp1_a_idx attach partition tp1_1_a_idx;

outputs:
                                      Partitioned table "public.t"
 Column |  Type   | Collation | Nullable | Default | Storage | Compression |
Stats target | Description 
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
 a      | integer |           |          |         | plain   |             |
             | 
Partition key: RANGE (a)
Indexes:
    "t_a_idx" btree (a)
Partitions: tp1 FOR VALUES FROM (1) TO (100), PARTITIONED

                                     Partitioned table "public.tp1"
 Column |  Type   | Collation | Nullable | Default | Storage | Compression |
Stats target | Description 
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
 a      | integer |           |          |         | plain   |             |
             | 
Partition of: t FOR VALUES FROM (1) TO (100)
Partition constraint: ((a IS NOT NULL) AND (a >= 1) AND (a < 100))
Partition key: RANGE (a)
Indexes:
    "tp1_a_idx" btree (a) INVALID
Partitions: tp1_1 FOR VALUES FROM (1) TO (10)

(Note that tp1_a_idx is invalid, but t_a_idx is valid.)

and triggers an assertion failure with the following stack trace:
Core was generated by `postgres: law regression [local] ALTER INDEX
                        '.
Program terminated with signal SIGABRT, Aborted.

warning: Section `.reg-xstate/1943764' in core file too small.
#0  __pthread_kill_implementation (no_tid=0, signo=6,
threadid=140492487026624) at ./nptl/pthread_kill.c:44
44      ./nptl/pthread_kill.c: No such file or directory.
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6,
threadid=140492487026624) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=140492487026624) at
./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=140492487026624, signo=signo@entry=6) at
./nptl/pthread_kill.c:89
#3  0x00007fc6f4027476 in __GI_raise (sig=sig@entry=6) at
../sysdeps/posix/raise.c:26
#4  0x00007fc6f400d7f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x000055b6a19eb40f in ExceptionalCondition (
    conditionName=0x55b6a1ff8800 "!parentIdx->rd_index->indisvalid",
fileName=0x55b6a1fea7e0 "tablecmds.c", 
    lineNumber=19206) at assert.c:66
#6  0x000055b6a038ea9d in validatePartitionedIndex
(partedIdx=0x7fc6e68a3ec8, partedTbl=0x7fc6e68a2368)
    at tablecmds.c:19206
#7  0x000055b6a038d581 in ATExecAttachPartitionIdx (wqueue=0x7ffe57073d00,
parentIdx=0x7fc6e68a3ec8, 
    name=0x61d000019da0) at tablecmds.c:19087
#8  0x000055b6a03009bc in ATExecCmd (wqueue=0x7ffe57073d00,
tab=0x61900003d6c8, cmd=0x61900003ba08, 
    lockmode=4, cur_pass=10, context=0x7ffe57073fd0) at tablecmds.c:5287
#9  0x000055b6a02fc7a5 in ATRewriteCatalogs (wqueue=0x7ffe57073d00,
lockmode=4, context=0x7ffe57073fd0)
    at tablecmds.c:4969
#10 0x000055b6a02f90b2 in ATController (parsetree=0x625000005d60,
rel=0x7fc6e68a3ec8, cmds=0x625000005d90, 
    recurse=true, lockmode=4, context=0x7ffe57073fd0) at tablecmds.c:4546
#11 0x000055b6a02f8395 in AlterTable (stmt=0x625000005d60, lockmode=4,
context=0x7ffe57073fd0)
    at tablecmds.c:4193
#12 0x000055b6a11f5eb2 in ProcessUtilitySlow (pstate=0x61900003b798,
pstmt=0x625000005e60, 
    queryString=0x625000005218 "alter index tp1_a_idx attach partition
tp1_1_a_idx;", 
    context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0,
dest=0x625000006120, qc=0x7ffe570748b0)
    at utility.c:1328
#13 0x000055b6a11f448b in standard_ProcessUtility (pstmt=0x625000005e60, 
    queryString=0x625000005218 "alter index tp1_a_idx attach partition
tp1_1_a_idx;", readOnlyTree=false, 
    context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0,
dest=0x625000006120, qc=0x7ffe570748b0)
    at utility.c:1077
#14 0x000055b6a11f1b86 in ProcessUtility (pstmt=0x625000005e60, 
    queryString=0x625000005218 "alter index tp1_a_idx attach partition
tp1_1_a_idx;", readOnlyTree=false, 
    context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0,
dest=0x625000006120, qc=0x7ffe570748b0)
    at utility.c:530
#15 0x000055b6a11ed0bd in PortalRunUtility (portal=0x625000025a18,
pstmt=0x625000005e60, isTopLevel=true, 
    setHoldSnapshot=false, dest=0x625000006120, qc=0x7ffe570748b0) at
pquery.c:1158
#16 0x000055b6a11ede34 in PortalRunMulti (portal=0x625000025a18,
isTopLevel=true, setHoldSnapshot=false, 
    dest=0x625000006120, altdest=0x625000006120, qc=0x7ffe570748b0) at
pquery.c:1315
#17 0x000055b6a11eaa90 in PortalRun (portal=0x625000025a18,
count=9223372036854775807, isTopLevel=true, 
    run_once=true, dest=0x625000006120, altdest=0x625000006120,
qc=0x7ffe570748b0) at pquery.c:791
#18 0x000055b6a11d492d in exec_simple_query (
    query_string=0x625000005218 "alter index tp1_a_idx attach partition
tp1_1_a_idx;") at postgres.c:1274
#19 0x000055b6a11e247a in PostgresMain (dbname=0x62900001b358 "regression",
username=0x6250000020f8 "law")
    at postgres.c:4632
#20 0x000055b6a0e0301f in BackendRun (port=0x614000000440) at
postmaster.c:4461
#21 0x000055b6a0e01723 in BackendStartup (port=0x614000000440) at
postmaster.c:4189
#22 0x000055b6a0df74dd in ServerLoop () at postmaster.c:1779
#23 0x000055b6a0df59fe in PostmasterMain (argc=3, argv=0x6030000006a0) at
postmaster.c:1463
#24 0x000055b6a078750e in main (argc=3, argv=0x6030000006a0) at main.c:198

Reproduced on REL_11 .. master.


pgsql-bugs by date:

Previous
From: jian he
Date:
Subject: range canonicalization function make corner case failed.
Next
From: Tom Lane
Date:
Subject: Re: BUG #17997: Assert failed in validatePartitionedIndex() when attaching partition index to child of valid index