Posted in Development | Posted on 01-24-2007 | 6,406 views
So I'm constantly surprised by MySQL. I ran across a stored procedure today that had this in it:
A quick google search turned up this doc that describes this feature. Basically, you can use this to tell MySQL to figure out how many rows would have been returned in a query if you had left off the limit operator. It obviously slows down the query, but is not as slow as rerunning the query without the limit. (And here is a scary question - have you ever seen code that did total counts like that?) To use this feature you have to follow up with an immediate select found_rows(). Check the documentation for more information.
Anyone know if SQL Server has something like this?


Anyways, in SQL server you can follow up a query with select @@rowcount to get the rows affected by the last query (including inserts, updates, deletes). PS - I'm sure you know this, but CF now returns a recordcount for ins, upds, dels...
It works pretty fast, but I've wondered myself if this is the best implementation of the concept.
Try this on MySQL 5.x:
select SQL_CALC_FOUND_ROWS * from entries limit 2;
show full columns from entries;
select found_rows();
found_rows(); actually returns the result from the previous query, that would be the number of fields in the table in question.
Bummer...
I've tried different versions of Connector/J - no luck.
count(0) is faster than count(*) by the way.
Note that I had to add "useDynamicCharsetInfo=false" in the Connection String of the datasource (I'm using BlueDragon, but I'm sure that ColdFusion administrator has the equivalent).
Hope that helps!
http://bugs.mysql.com/bug.php?id=25978
But thanks for the notice ;)
[Add Comment] [Subscribe to Comments]