Re: Index not used in certain nested views but not in others

2025-05-13 Thread Tom Lane
Markus Demleitner writes: > On Tue, May 13, 2025 at 10:12:46AM -0400, Tom Lane wrote: >> Oh, well, that's your problem. The source tables' column types >> need to match. Otherwise the UNIONs don't get flattened and you >> don't get indexscans. > A... *source* tables. Sure, once I'm out of

Re: Index not used in certain nested views but not in others

2025-05-13 Thread Markus Demleitner
Dear Tom, On Tue, May 13, 2025 at 10:12:46AM -0400, Tom Lane wrote: > Markus Demleitner writes: > > SELECT > > CAST(ssa_dstype AS text) AS dataproduct_type, > > CAST(NULL AS text) AS dataproduct_subtype, > > CAST(2 AS smallint) AS calib_level, > > ... > > Oh, well, that's your p

Re: Index not used in certain nested views but not in others

2025-05-13 Thread Tom Lane
Markus Demleitner writes: > You see, when creating the "big", 30-tables view, I do cast all > columns to common types in the view statement that actually make up > the view. The original SQL fragments look like this: > SELECT > CAST(ssa_dstype AS text) AS dataproduct_type, > CAST(NULL

Re: Index not used in certain nested views but not in others

2025-05-13 Thread Markus Demleitner
Dear Tom, Dear Laurenz, Thanks for your pointers -- that was already helpful. On Thu, May 01, 2025 at 06:58:45AM +0200, Laurenz Albe wrote: > On Wed, 2025-04-30 at 17:02 -0400, Tom Lane wrote: > > It's hard to be sure when you've shown us no table definitions and > > only fragments of the view de

Re: Index not used in certain nested views but not in others

2025-05-03 Thread Tom Lane
"Peter J. Holzer" writes: > On 2025-04-30 17:16:47 +0200, Markus Demleitner wrote: >> dfbsspec.raw_spectra is about 23 Megarows, >> -> Parallel Seq Scan on raw_spectra (cost=0.00..2626995.66 rows=5803266 >> width=756) (actual time=0.137..6841.379 rows=4642657 loops=5) > It estimates that it ha

Re: Index not used in certain nested views but not in others

2025-05-03 Thread Peter J. Holzer
On 2025-04-30 17:16:47 +0200, Markus Demleitner wrote: > There is another view made up of about 20 tables, looking somewhat > like this: [...] > The first view, ivoa.obs_radio, is just a few hundred records, > dfbsspec.raw_spectra is about 23 Megarows, [...] >

Re: Index not used in certain nested views but not in others

2025-04-30 Thread Laurenz Albe
On Wed, 2025-04-30 at 17:02 -0400, Tom Lane wrote: > Markus Demleitner writes: > > So, when the SELECT statement on dfbsspec.ssa stands along in the view > > definition, Postgres does the right thing; when the exact same query > > stands in a UNION ALL with other tables, Postgres doesn't use the >

Re: Index not used in certain nested views but not in others

2025-04-30 Thread Tom Lane
Markus Demleitner writes: > So, when the SELECT statement on dfbsspec.ssa stands along in the view > definition, Postgres does the right thing; when the exact same query > stands in a UNION ALL with other tables, Postgres doesn't use the > index. Hu? It's hard to be sure when you've shown us no

Re: Index not used in certain nested views but not in others

2025-04-30 Thread Ron Johnson
On Wed, Apr 30, 2025 at 3:51 PM Markus Demleitner < msdem...@ari.uni-heidelberg.de> wrote: > Dear List, > > I know how tedious mails with a subject of the type "I don't understand > what the planner does" are, but on this one I'm really stumped. > Regrettably, the situation is also a bit complex.