Re: BUG #17246: Feature request for adoptive indexes - Mailing list pgsql-bugs

From Pavel Borisov
Subject Re: BUG #17246: Feature request for adoptive indexes
Date
Msg-id CALT9ZEE4bceuuAra9n8Euz5=M_AxkYSVeLKJ=K41_m-p2csQLw@mail.gmail.com
Whole thread Raw
In response to Re: BUG #17246: Feature request for adoptive indexes  (Hayk Manukyan <manukyantt@gmail.com>)
List 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

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: conchuela timeouts since 2021-10-09 system upgrade
Next
From: "David G. Johnston"
Date:
Subject: Re: BUG #17246: Feature request for adoptive indexes