Re: Partitioned index can be not dumped

From: Alexander Pyhalov <a(dot)pyhalov(at)postgrespro(dot)ru>
To: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Partitioned index can be not dumped
Date: 2021-06-30 19:28:42
Message-ID: b62ec70dab88a1f441c18e69f1c4f696@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Álvaro Herrera писал 2021-06-30 21:54:
> On 2021-Jun-30, Alexander Pyhalov wrote:
>
>> I've seen the following effect on PostgreSQL 14 stable branch.
>> Index, created on partitioned table, disappears from pg_dump or psql
>> \d
>> output.
>> This seems to begin after analyze. Partitoned relation relhasindex
>> pg_class
>> field suddenly becomes false.
>
> Yeah, that seems correct.
>
> I didn't verify your test case, but after looking at the code I thought
> there was a bit too much churn and the new conditions looked quite
> messy
> and unexplained. It seems simpler to be explicit at the start about
> what we're doing, and keep nindexes=0 for partitioned tables; with
> that,
> the code works unchanged because the "for" loops do nothing without
> having to check for anything. My proposal is attached.
>
> I did run the tests and they do pass, but I didn't look very closely at
> what the tests are actually doing.
>
> I noticed that part of that comment seems to be a leftover from ... I
> don't know when: "We do not analyze index columns if there was an
> explicit column list in the ANALYZE command, however." I suppose this
> is about some code that was removed, but I didn't dig into it.

Looks good. It seems this comment refers to line 455.

445 if (nindexes > 0)
446 {
447 indexdata = (AnlIndexData *) palloc0(nindexes *
sizeof(AnlIndexData));
448 for (ind = 0; ind < nindexes; ind++)
449 {
450 AnlIndexData *thisdata = &indexdata[ind];
451 IndexInfo *indexInfo;
452
453 thisdata->indexInfo = indexInfo =
BuildIndexInfo(Irel[ind]);
454 thisdata->tupleFract = 1.0; /* fix later if partial */
455 if (indexInfo->ii_Expressions != NIL && va_cols == NIL)
456 {
457 ListCell *indexpr_item =
list_head(indexInfo->ii_Expressions);
458
459 thisdata->vacattrstats = (VacAttrStats **)
460 palloc(indexInfo->ii_NumIndexAttrs *
sizeof(VacAttrStats *));

Also I've added non-necessary new line in test.
Restored comment and removed new line.
--
Best regards,
Alexander Pyhalov,
Postgres Professional

Attachment Content-Type Size
v4-0001-Set-relhasindex-for-partitioned-tables-correctly.patch text/x-diff 4.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Rahila Syed 2021-06-30 19:36:11 Column Filtering in Logical Replication
Previous Message Ibrar Ahmed 2021-06-30 19:26:55 Re: Commit fest manager