Phuong Ma <pma@commandprompt.com> writes:
> WHERE substr("ORDER_NUM", 1, 1) != 'W'; # (Orders NOT prefixed with W.)
> OR...
> WHERE substr("ORDER_NUM", 1, 1) = 'I'; # (Orders prefixed with I.)
> However, the first query runs in about 10-15 seconds, and the second
> query
> ran for over 40 minutes before I cancelled it.
What query plans does EXPLAIN show for each case? (And have you done
VACUUM ANALYZE lately?)
The change in the WHERE clause may be altering the planner's selectivity
guesstimates enough to cause choice of a less appropriate plan. Hard to
tell without seeing what EXPLAIN has to say, though.
regards, tom lane