6
There’s a difference in performance if you do:
//seleciona todos os itens da tabela
$cmd = "SELECT * FROM produtos";
$produtos = mysql_query($cmd);
//conta o total de itens
$total = mysql_num_rows($produtos);
instead of running a query: SELECT count(*) FROM produtos
to count the number of occurrences in the database? NOTE: disregard mysql/mysqli usage
,@bigown is possible to sql sequinte? SELECT Count(name),durancao FROM products
– Ricardo
Yes, it’s possible, but you lose most of the advantage. This way the count should be made and will traffic a much greater amount of data than just the count . But if you need this data there is no better solution. But this is already a gain in worry to bring everything.
– Maniero
A way that I didn’t know worked but seems to work, is
MAX(ROWNUM)
.– Gustavo Cinque
@Gustavocinque I do not know well the implementation of this, if there can be gap between numbers. I don’t know if it’s reliable. Do you have any information that shows that it is? Not to accept results that are only correct by coincidence.
– Maniero
I don’t have, @bigown. As far as I know,
ROWNUM
is the line count of the result, and withMAX()
i get the highest value of lines. I see this function being widely used by frameworks based onjsf
(richfaces
for example), where the maximum result of a grid is calculated in this way, and also the limit of the pages is calculated, using them in clausesWHERE
.– Gustavo Cinque
I’m looking for this in the Mysql documentation and I’m not finding anything, even if there is this. Although I understand that if it exists it should work as you explained. I just don’t know if there is gaps in a sequence that makes the last line number the same as the line count.
– Maniero
Sorry, confused, rownum is not from Mysql. It is oracle.
– Gustavo Cinque
As far as I can see, there is no way to reproduce this pattern in Mysql...
– Gustavo Cinque