Subject | RE: [firebird-support] Fastest way to query tables and views and return no records. |
---|---|
Author | Svein Erling Tysvær |
Post date | 2009-03-03T08:09:49Z |
Just to explain what you effectively did. The optimizer saw that it had no index that could be used to help getting what you specified in the WHERE clause, and decided it had to look through every single row in your table/view to fetch rows that satisfied your criteria. WHERE 1=0 can be useful in optimization when you want to eliminate the use of certain indexes, but used the way you did, I'd say it clearly shows how a human mind differs from Firebirds logic ('just return an empty set, 1=0 is never true' vs. 'is 1=0 true for this row? No, let's check the next row to see whether 1=0 is true there...').
Thanks for a nice giggle,
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of esbreidenbach
Sent: 3. mars 2009 00:04
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Fastest way to query tables and views and return no records.
Hi,
I have a routine I use in my application which runs a separate query
on every table and view in the database. The purpose of these queries
is really just to obtain the field definitions of the underlying
table, not to return any actual data.
The routine uses the following generic SQL:
Select * from TableName/ViewName where 1 = 0;
My problem is that these queries can run very slowly on views which
are really meant to have additional where clause statements, and even
on tables with large numbers of records. The intention of the where
clause "where 1 = 0" was to eliminate any query activity, but it is
not working out this way.
Is there a query which I can execute that will run very fast (and
return no data), or any other ideas on how to do what I want?
Thanks,
Thanks for a nice giggle,
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of esbreidenbach
Sent: 3. mars 2009 00:04
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Fastest way to query tables and views and return no records.
Hi,
I have a routine I use in my application which runs a separate query
on every table and view in the database. The purpose of these queries
is really just to obtain the field definitions of the underlying
table, not to return any actual data.
The routine uses the following generic SQL:
Select * from TableName/ViewName where 1 = 0;
My problem is that these queries can run very slowly on views which
are really meant to have additional where clause statements, and even
on tables with large numbers of records. The intention of the where
clause "where 1 = 0" was to eliminate any query activity, but it is
not working out this way.
Is there a query which I can execute that will run very fast (and
return no data), or any other ideas on how to do what I want?
Thanks,