Re: Table with many NULLS for indexed column yields strange query plan

2020-03-09 Thread greigwise
Seqscans are not disabled. Also, this is PostgreSQL 10.11 if that helps. Costs are as follows: seq_page_cost --- 1 random_page_cost -- 1.5 It is odd that it does not just do a seqscan on table3. It's a very small table... only like 36 rows. I'd think the

Re: Table with many NULLS for indexed column yields strange query plan

2020-03-08 Thread Tom Lane
"Peter J. Holzer" writes: > How is the selectivity of "type"? Would an index on that column help? The EXPLAIN results say that the "type = 'Standard'" condition is completely not selective: in both plans, there is no "Rows Removed by Filter" indication where it's applied, indicating that it did

Re: Table with many NULLS for indexed column yields strange query plan

2020-03-08 Thread Peter J. Holzer
On 2020-03-05 18:08:53 -0700, greigwise wrote: > I have a query like this: > > SELECT "table1".* FROM "table1" > INNER JOIN "table2" ON "table2"."table1_id" = "table1"."id" > INNER JOIN "table3" ON "table3"."id" = "table2"."table3_id" > WHERE "table3"."number" = '' > AND ("table2"."type") IN

Table with many NULLS for indexed column yields strange query plan

2020-03-05 Thread greigwise
I have a query like this: SELECT "table1".* FROM "table1" INNER JOIN "table2" ON "table2"."table1_id" = "table1"."id" INNER JOIN "table3" ON "table3"."id" = "table2"."table3_id" WHERE "table3"."number" = '' AND ("table2"."type") IN ('Standard') ; table2 has a large number of NULLS in the