Subject | RE: [firebird-support] Re: Differents results using EXISTS |
---|---|
Author | Sasha Matijasic |
Post date | 2008-03-26T10:19:37Z |
> I'm confused too, Sasha. I used to write EXISTS(SELECT 1...) myself,1100 columns??? Where did you find that beast? :)
> but changed to EXISTS(SELECT *...) - most likely after being convinced
> by someone on this list (Claudio, Ivan or Ann?) that they were
> equivalent.
>
> Testing a tiny, interactive bit by running
>
> SELECT COUNT(*)
> FROM <VariousTablesWithVariousNumberOfRows>
> WHERE EXISTS (SELECT [1 | *] FROM
> TableWithOver1100ColumnsAnd250000Rows)
>
> a few times, doesn't indicate any difference and even
>
> SELECT COUNT(*)
> FROM TableWithOver100000Rows
> WHERE EXISTS (SELECT [1 | *] FROM
> TableWithOver1100ColumnsAnd250000Rows)
>
> only needs about 0.1 seconds to return the value (increasing to almost
> three seconds if I add WHERE to 'join' the tables, but still without
> any visible difference between * and 1 - in fact, even EXISTS(SELECT
> FIRST 1 1... seems to be only marginally slower).
>
> Though Seans and Nandos argument that SELECT 1 is more readable is a
> fair point, and no-one has suggested any drawbacks whatsoever with this
> option, so I guess I might be changing my habit again...
>
I hope you don't have to work with that and you generated it for the test.
What Sean said about difference between optimizer and "sql-rewriter" sounds right (thanks Sean for pointing that out), and I can't explain your results, but I guess "select * from TableWithOver1100ColumnsAnd250000Rows" and NOT returning result set is not that expensive after all.
And of course, I agree with Nando that for the sake of readability select 1 is better than select *, actually I use select null (and no, I don't think null is "faster" than 1, I just like it more).
Sasha