Subject | Performance issue: Index not used in query plan |
---|---|
Author | kapsee |
Post date | 2006-07-26T00:13:14Z |
I have the following schema:
table keyvaluepairs(k integer, v integer)
index keyvalue_idx on keyvaluepairs(k)
table validkeys(k integer)
For example, when I do a
select v from keyvaluepairs where k = 1
it uses the index keyvalue_idx and is pretty fast.
But when I do a
select v from keyvaluepairs where k in (select k from validkeys)
it stops using the index and does a full scan on keyvaluepairs and is
slow.
I realize I could use a join instead of the nested select which would
fix the problem but I need to use this SQL to create a view and using
a join would prevent the view from being updateable.
I tried to specify the plan
select v from keyvaluepairs
where k in (select k from validkeys)
PLAN (keyvaluepairs INDEX (keyvalue_idx))
but it said "unable to use index "
Any clues as to how to fix this performance issue ?
Thanks.
table keyvaluepairs(k integer, v integer)
index keyvalue_idx on keyvaluepairs(k)
table validkeys(k integer)
For example, when I do a
select v from keyvaluepairs where k = 1
it uses the index keyvalue_idx and is pretty fast.
But when I do a
select v from keyvaluepairs where k in (select k from validkeys)
it stops using the index and does a full scan on keyvaluepairs and is
slow.
I realize I could use a join instead of the nested select which would
fix the problem but I need to use this SQL to create a view and using
a join would prevent the view from being updateable.
I tried to specify the plan
select v from keyvaluepairs
where k in (select k from validkeys)
PLAN (keyvaluepairs INDEX (keyvalue_idx))
but it said "unable to use index "
Any clues as to how to fix this performance issue ?
Thanks.