Re: BUG #17246: Feature request for adoptive indexes

From: Pavel Borisov <pashkin(dot)elfe(at)gmail(dot)com>
To: Hayk Manukyan <manukyantt(at)gmail(dot)com>
Cc: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17246: Feature request for adoptive indexes
Date: 2021-10-26 19:15:04
Message-ID: CALT9ZEE4bceuuAra9n8Euz5=M_AxkYSVeLKJ=K41_m-p2csQLw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

>
> > I need to create following indexes:
>> > Create index job_nlp_year_scan on ingest_scans_stageing
>> > (`job`,`nlp`,`year`,`scan_id`);
>> > Create index job_nlp_year_issue_flag on ingest_scans_stageing
>> > (`job`,`nlp`,`year`,`issue_flag`);
>> > Create index job_nlp_year_sequence on ingest_scans_stageing
>> > (`job`,`nlp`,`year`,`sequence`);
>> > As you can see the first 3 columns are the same (job, nlp, year). so if
>> I
>> > create 3 different indexes db should manage same job_nlp_year structure
>> 3
>> > times.
>>
> I think now in many cases you can effectively use covering index to have
fast index-only scans without index duplication. It will help if you don't
have great selectivity on the last column (most probably you don't). E.g.:

CREATE INDEX ON table_name (`job`,`nlp`,`year`) INCLUDE (`scan_id`,
`issue_flag`, `sequence`)

But I consider the feature can be useful when there is a very little
selectivity in the first index columns. I.e. if (job`,`nlp`,`year') has
many repeats and the most selection is done in the last column. I am not
sure how often this can arise but in general, I see it as a useful b-tree
generalization.

I'm not sure how it should be done. In my view, we need to add an ordered
posting tree as a leaf element if b-tree and now we have index storage only
for tuples. The change of on-disk format was previously not easy in nbtree
and if we consider the change, we need an extra bit to mark posting trees
among index tuples. Maybe it could be done in a way similar to deduplicated
tuples if some bits in the tuple header are still could be freed.

Thoughts?

--
Best regards,
Pavel Borisov

Postgres Professional: http://postgrespro.com <http://www.postgrespro.com>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2021-10-26 19:37:49 Re: BUG #17246: Feature request for adoptive indexes
Previous Message Scott Mead 2021-10-26 15:23:41 Re: [BUG] Autovacuum not dynamically decreasing cost_limit and cost_delay