Subject | Re: [firebird-support] Is NOT IN or SMALLINT = 1 effici ent? |
---|---|
Author | Mark Rotteveel |
Post date | 2012-02-20T10:48:18Z |
On Mon, 20 Feb 2012 09:51:19 -0000, "venussoftop" <venussoftop@...>
wrote:
WHERE NOT EXISTS (SELECT 1 FROM tableb b WHERE b.iPKID = a.iTableBLinkID)
This will make it possible to use indices, which is a lot more efficient
than populating a list and then checking for existence in that list.
Use of a flag field will probably not be efficient either, as such fields
usually have low selectivity, making an index useless.
Mark
wrote:
> Hi allrecords
>
> I have tables that can allow me to filter data like this:
> SELECT a.*
> FROM tablea a
> WHERE a.iTableBLinkID NOT IN (SELECT b.iPKID FROM tableb b)
> ...
> these tables will grow over the years with more and more records
> cancelling each other out, so there really will be only few tens of
> which do not have a corresponding iTableBLinkID records at any givenpoint
> of timecould
>
> Or should I introduce a flag in tablea, something like iClosed SMALLINT
> which is default zero but set to 1 programatically so the same result
> be got likeInstead of the NOT IN clause, use a NOT EXISTS, for example:
> SELECT a.*
> FROM tablea a
> WHERE a.iClosed = 0
> ...
>
> Which is more efficient from SQL point of view?
WHERE NOT EXISTS (SELECT 1 FROM tableb b WHERE b.iPKID = a.iTableBLinkID)
This will make it possible to use indices, which is a lot more efficient
than populating a list and then checking for existence in that list.
Use of a flag field will probably not be efficient either, as such fields
usually have low selectivity, making an index useless.
Mark