Hi
I was using a query previously, that was efficient
select * from table where pred1 and pred2 and pred3;
Later I was asked to introduce new ones, but they were not based on
table columns but variables declared in SP.
select * from table where pred1 and pred2 and pred3 and variable1
='number1 and variable2 =number2;
so in turn this translates to pure mathematical comparison, sometimes
simple like 2=2,
I;ve added only 2 of them in the ex above, but actually there are 13
(does this influence the path, duh!!). Anyways, what happened was,
after they were added, it started doing a table scan, and was very
very inefficient. Later, I converted the additional predicates into
simple if loops, and executed the original query, and SP was very
fast.
Is there any database logic connected to doing a table scan? or any
registry/variable setting I can do so db2 doesnt do the table scan?
Please advise, since my team has done this mistake in many places,
and rolling back is going to be a pain in backside.
I was using a query previously, that was efficient
select * from table where pred1 and pred2 and pred3;
Later I was asked to introduce new ones, but they were not based on
table columns but variables declared in SP.
select * from table where pred1 and pred2 and pred3 and variable1
='number1 and variable2 =number2;
so in turn this translates to pure mathematical comparison, sometimes
simple like 2=2,
I;ve added only 2 of them in the ex above, but actually there are 13
(does this influence the path, duh!!). Anyways, what happened was,
after they were added, it started doing a table scan, and was very
very inefficient. Later, I converted the additional predicates into
simple if loops, and executed the original query, and SP was very
fast.
Is there any database logic connected to doing a table scan? or any
registry/variable setting I can do so db2 doesnt do the table scan?
Please advise, since my team has done this mistake in many places,
and rolling back is going to be a pain in backside.
Comment