Why isn't PG using an index-only scan?

2025-09-17 Thread Jean-Christophe BOGGIO
Hello, I have this very simple query: INSERT INTO copyrightad (idoeu, idad, role, mechowned, perfowned, iscontrolled) SELECT o.idoeu, c.idad, LEFT(sipa_capacity1,3), sipa_mech_owned, sipa_perf_owned, sipa_controlled='Y' FROM imaestro.msipfl ip JOIN oeu o ON o.imworkid=ip.sipa_song_code JOIN a

Re: Indexes on expressions with multiple columns and operators

2025-09-17 Thread Frédéric Yhuel
Thank you Laurenz and Tom! I'm going to quote Tom's email here: On 9/17/25 16:41, Tom Lane wrote: =?UTF-8?Q?Fr=C3=A9d=C3=A9ric_Yhuel?= writes: Hello, in the following, I don't understand why: 1) the expression index isn't used in the first EXPLAIN The planner doesn't look for multi-clause ma

Re: Poor row estimates from planner, stat `most_common_elems` sometimes missing for a text[] column

2025-09-17 Thread Tom Lane
Matt Long writes: > Not to let perfect be the enemy of better, but we're facing a variant of > this issue that would not be addressed by the proposed patch. > ... > In this case, the effects of the proposed patch are not applied since the > most_common_elems array is not empty. I'm not a statistic

Indexes on expressions with multiple columns and operators

2025-09-17 Thread Frédéric Yhuel
Hello, in the following, I don't understand why: 1) the expression index isn't used in the first EXPLAIN 2) the number of estimated rows is completely off in the second EXPLAIN, whereas the planner could easily use the statistics of foo_f_idx. (SQL script attached, tested with master and v17)

Re: Indexes on expressions with multiple columns and operators

2025-09-17 Thread Frédéric Yhuel
On 9/17/25 16:57, Frédéric Yhuel wrote: Yes, Laurenz made a similar suggestion, but the problem is that I'm mostly interested in the estimated number of output rows... because in the real query, there's a very bad Hash Join above (the Nested Loop is *much* faster). BTW, I've also tested an

Re: Indexes on expressions with multiple columns and operators

2025-09-17 Thread Tom Lane
=?UTF-8?Q?Fr=C3=A9d=C3=A9ric_Yhuel?= writes: > Hello, in the following, I don't understand why: > 1) the expression index isn't used in the first EXPLAIN The planner doesn't look for multi-clause matches of that sort. You could apply a little ju-jitsu perhaps: regression=# EXPLAIN (ANALYZE, SUMM

Re: Indexes on expressions with multiple columns and operators

2025-09-17 Thread Laurenz Albe
On Wed, 2025-09-17 at 15:55 +0200, Frédéric Yhuel wrote: > Hello, in the following, I don't understand why: > > 1) the expression index isn't used in the first EXPLAIN > > 2) the number of estimated rows is completely off in the second EXPLAIN, > whereas the planner could easily use the statisti