Re: [BUGS] BUG #11500: PRIMARY KEY index not being used
Wyatt Alt <wyatt.alt@gmail.com>
From: Wyatt Alt <wyatt.alt@gmail.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: Marko Tiikkaja <marko@joh.to>, Tom Lane <tgl@sss.pgh.pa.us>,
pgsql-bugs@postgresql.org
Date: 2025-10-04T04:00:27Z
Lists: pgsql-bugs
On Fri, Oct 3, 2025 at 8:19 PM David Rowley <dgrowleyml@gmail.com> wrote:
> I can't off the top of my head think of a way to
> do that with an enum column.
>
Casting the enum to text seems to work:
EXPLAIN SELECT 1 FROM orders WHERE order_id = 1 AND state = 'WAIT_EVENT';
QUERY PLAN
------------------------------------------------------------------------------------
Index Scan using orders_wait_event_idx on orders (cost=0.12..2.34 rows=1
width=4)
Filter: (order_id = 1)
(2 rows)
EXPLAIN SELECT 1 FROM orders WHERE order_id = 1 AND state::text =
'WAIT_EVENT';
QUERY PLAN
--------------------------------------------------------------------------
Index Scan using orders_pkey on orders (cost=0.42..2.65 rows=1 width=4)
Index Cond: (order_id = 1)
Filter: ((state)::text = 'WAIT_EVENT'::text)
(3 rows)