Subject | Re: [firebird-support] Update with a Sub Select |
---|---|
Author | Arno Brinkman |
Post date | 2003-07-30T19:23:05Z |
Hi,
EXISTS(SELECT Bar.id FROM Bar WHERE Bar.id = Foo.id)
This means Foo will be NATURAL and for Bar a index is used.
Regards,
Arno Brinkman
ABVisie
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird links :
http://www.firebirdsql.com
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/
Nederlandse firebird nieuwsgroep :
news://80.126.130.81
> Maybe someone can explain this to me.Correct, A index that has Foo.id (as first or only field) is being used.
>
> When I do an UPDATE with a sub SELECT, the Query Plan shows a table
> scan.
>
> However, if I change the IN clause to use explicit values (say some
> comma delimited integers), it uses my index.
>
> Something like:
>
> UPDATE Foo
> SET val=0
> WHERE id IN ( 1,2,3,4 );
> This shows the query using the index on Foo.id.
> UPDATE FooCorrect, see it as : that it internally is converted to :
> SET val=0
> WHERE id IN ( SELECT Bar.id FROM Bar );
>
> This shows the query performing a table scan on Foo.
EXISTS(SELECT Bar.id FROM Bar WHERE Bar.id = Foo.id)
This means Foo will be NATURAL and for Bar a index is used.
Regards,
Arno Brinkman
ABVisie
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird links :
http://www.firebirdsql.com
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/
Nederlandse firebird nieuwsgroep :
news://80.126.130.81