A very clever question for PHP, SQL. In general, there is approximately such a huge query to the database
select book.*, lol as l, puk as p, boom as b, group_concat( separator '|') as id, .......................... from xxx as px left join ............... left join ................. right join ................ left join ................... where book>8000 group by x.id
Displays approximately 50,000 results as arrays. There is a php code that must then process the result. Processing takes place in a loop using php
for() { if($dsf[$i]=='лол'){ //печатаем } elseif($dfs[$i]=='ололо') { //печатаем } else { continue; } }
Here is how I rewrote all of the above.
select * from ( select book.*, lol as l, puk as p, boom as b, group_concat( separator '|') as id, .......................... from xxx as px left join ............... left join ................. right join ................ left join ................... where book>8000 group by x.id ) as zzz where xz = 'лол' or xz='ололо'; for() { if($dsf[$i]=='лол'){ //печатаем } if($dfs[$i]=='ололо') { //печатаем } }
I draw your attention to the fact that in the second version the condition check occurs in SQL, and then the same thing in PHP. Unlike the first option, the second handles fewer results and does not use continue.
Question:
And what actually works faster? And which option is more correct?