Subject | Is NOT IN or SMALLINT = 1 efficient? |
---|---|
Author | venussoftop |
Post date | 2012-02-20T09:51:19Z |
Hi all
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 records which do not have a corresponding iTableBLinkID records at any given point of time
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 could be got like
SELECT a.*
FROM tablea a
WHERE a.iClosed = 0
...
Which is more efficient from SQL point of view?
Please advise
Thanks and regards
Bhavbhuti
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 records which do not have a corresponding iTableBLinkID records at any given point of time
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 could be got like
SELECT a.*
FROM tablea a
WHERE a.iClosed = 0
...
Which is more efficient from SQL point of view?
Please advise
Thanks and regards
Bhavbhuti