Re: [HACKERS] Proposal: Local indexes for partitioned table - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: [HACKERS] Proposal: Local indexes for partitioned table
Date
Msg-id 20180124162006.pmapfiznhgngwtjf@alvherre.pgsql
Whole thread Raw
In response to Re: [HACKERS] Proposal: Local indexes for partitioned table  (David Rowley <david.rowley@2ndquadrant.com>)
Responses Re: [HACKERS] Proposal: Local indexes for partitioned table
List pgsql-hackers
David Rowley wrote:

> 10. You've added code to get_relation_info() to handle partitioned
> indexes, but that code is skipped due to:
> 
> /*
> * Make list of indexes.  Ignore indexes on system catalogs if told to.
> * Don't bother with indexes for an inheritance parent, either.
> */
> if (inhparent ||
> 
> The new code should either be removed, or you should load the index
> list for a partitioned table.

I realized that this wasn't an oversight after all.  You can invoke this
code, and it fails in current master:

CREATE TABLE at_partitioned (col1 INT) PARTITION BY RANGE (col1);
CREATE INDEX ON at_partitioned (col1);
CREATE TABLE at_regular2 (col2 INT);
SELECT col2 FROM at_regular2 fk LEFT OUTER JOIN at_partitioned pk ON (col1 = col2);

fails with:
ERROR:  could not open file "base/16384/16395": No such file or directory

where the mentioned path corresponds to the index filenode:

alvherre=# select oid::regclass, relkind from pg_class where relfilenode = '16395';
           oid           │ relkind 
─────────────────────────┼─────────
 at_partitioned_col1_idx │ I
(1 fila)


The error comes from get_relation_info called for at_partitioned, where the
rte->inh flag is false.  So this is the correct behavior:  we consider the
table on its own, not as an inheritance parent, and so the code is not skipped.
Backtrace:

(gdb) bt
#0  errfinish (dummy=0)
    at /pgsql/source/master/src/backend/utils/error/elog.c:414
#1  0x0000564936f79365 in mdopen (reln=<optimized out>, 
    forknum=forknum@entry=MAIN_FORKNUM, behavior=behavior@entry=1)
    at /pgsql/source/master/src/backend/storage/smgr/md.c:606
#2  0x0000564936f7983b in mdopen (behavior=1, forknum=MAIN_FORKNUM, 
    reln=0x5649382f8dd0)
    at /pgsql/source/master/src/backend/storage/smgr/md.c:922
#3  mdnblocks (reln=0x5649382f8dd0, forknum=MAIN_FORKNUM)
    at /pgsql/source/master/src/backend/storage/smgr/md.c:875
#4  0x0000564936eeb6ea in get_relation_info (root=root@entry=0x5649382ef398, 
    relationObjectId=16385, inhparent=<optimized out>, 
    rel=rel@entry=0x5649382f0198)
    at /pgsql/source/master/src/backend/optimizer/util/plancat.c:377
#5  0x0000564936eeee55 in build_simple_rel (root=root@entry=0x5649382ef398, 
    relid=2, parent=parent@entry=0x0)
    at /pgsql/source/master/src/backend/optimizer/util/relnode.c:182
#6  0x0000564936ec6f23 in add_base_rels_to_query (
    root=root@entry=0x5649382ef398, jtnode=<optimized out>)
    at /pgsql/source/master/src/backend/optimizer/plan/initsplan.c:113

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


pgsql-hackers by date:

Previous
From: John Scalia
Date:
Subject: Documentation update
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] Patch: Add --no-comments to skip COMMENTs with pg_dump