6.0.0-alpha10
5/17/25

[#6198] One loop less
Summary One loop less
Queue Ansel
Type Enhancement
State Resolved
Priority 1. Low
Owners mrubinsk (at) horde (dot) org
Requester duck (at) obala (dot) net
Created 02/03/2008 (6313 days ago)
Due
Updated 02/04/2008 (6312 days ago)
Assigned
Resolved 02/04/2008 (6312 days ago)
Milestone
Patch No

History
02/04/2008 08:48:36 PM Chuck Hagenbuch Comment #10 Reply to this comment
Aliasing something as desc or default will result in a  sql sintax
error as DESC and DEFAULT are reserved words.
Alternately you can quote the columns as identifiers. Unfortunately 
there isn't a cross-db way to do that, but you can look at Rdo for 
examples.
02/04/2008 08:43:36 PM Michael Rubinsky Comment #9 Reply to this comment
I understand using the sql alias in the select statement, but why
would we need to rename the table columns to do this?
Aliasing something as desc or default will result in a  sql sintax
error as DESC and DEFAULT are reserved words.
Cool. I sure am getting a lesson in SQL today :)



Thanks. I'm gonna create this as another ticket and do the changes 
after every thing else I'm in the middle of settles down...



Thanks again!
02/04/2008 08:30:38 PM Duck Comment #8 Reply to this comment
I understand using the sql alias in the select statement, but why
would we need to rename the table columns to do this?
Aliasing something as desc or default will result in a  sql sintax 
error as DESC and DEFAULT are reserved words.


02/04/2008 08:22:55 PM Michael Rubinsky Comment #7 Reply to this comment
With a little renaming of
table columns the parameters replace loop could be replace either.
for example the gallery_desc becomes gallers_description and you can
select columns with "AS" sql alias inside select statement.
I understand using the sql alias in the select statement, but why 
would we need to rename the table columns to do this?


02/04/2008 07:43:30 PM Michael Rubinsky Comment #6
State ⇒ Resolved
Reply to this comment
The first loop is the fetchAll, the second create objects.
Ah, of course. MDB2_Results:: does the loop. Forgot about that...



Thanks.


02/04/2008 07:29:41 PM Duck Comment #5 Reply to this comment
- Don't use SELECT *
What's the rationale for this? In this case we actually do want all
the columns. Is there a performance issue with '*' vs putting all the
column names in the query explicitly?
One step less, some servers tends to access table headers to read 
column list before processing the request.
- Combine the fetchAll db driver with the loop that creates
galleries objects
I don't see how this is reducing the number of loops, your just
replacing a for loop for a while loop from what I can tell. Also,
with your change we're no longer catching any errors that the
->fetchAll() (->fetchRow() in your version) call can return.
The first loop is the fetchAll, the second create objects. With while 
you fetch the result and create the object in one loop. If you wish, 
the row variable can be checked for errors, but is not needed as the 
statement is executed and checked before. With a little renaming of 
table columns the parameters replace loop could be replace either. for 
example the gallery_desc becomes gallers_description and you can 
select columns with "AS" sql alias inside select statement. Reducing 
the attribute selection only to one loop. Now the are 3, not needed.
02/04/2008 07:15:49 PM Michael Rubinsky Comment #4 Reply to this comment
k. Thanks for the info, committed that part of the patch as well.
02/04/2008 07:06:05 PM Jan Schneider Comment #3 Reply to this comment
- Don't use SELECT *
What's the rationale for this? In this case we actually do want all
the columns. Is there a performance issue with '*' vs putting all the
column names in the query explicitly?
If not a performance gain, this is a least good practice. And I'm 
pretty sure this *is* a performance difference, at least on some RDBMs.
02/04/2008 06:13:50 PM Michael Rubinsky Assigned to Michael Rubinsky
State ⇒ Feedback
 
02/04/2008 06:13:30 PM Michael Rubinsky Comment #2 Reply to this comment
- Don't use SELECT *
What's the rationale for this? In this case we actually do want all 
the columns. Is there a performance issue with '*' vs putting all the 
column names in the query explicitly?
- Combine the fetchAll db driver with the loop that creates galleries objects
I don't see how this is reducing the number of loops, your just 
replacing a for loop for a while loop from what I can tell. Also, with 
your change we're no longer catching any errors that the ->fetchAll() 
(->fetchRow() in your version) call can return.
- As all fields are prefixed with "gallery_id" don't str_replace but
use substr(), is faster
Agreed, thanks.
- countGalleries caches results but never returns it if recalled, as
this was not noticed till now I guess that is never recalled so
remove the parameters serialization
Yea, I thought I already took that out after I realised that we very 
rarely need to obtain the count for the same gallery more than once 
per page load. Thanks for catching that.


02/03/2008 11:38:12 PM Duck Comment #1
Priority ⇒ 1. Low
State ⇒ New
New Attachment: Ansel.diff Download
Queue ⇒ Ansel
Summary ⇒ One loop less
Type ⇒ Enhancement
Reply to this comment
- Don't use SELECT *

- Combine the fetchAll db driver with the loop that creates galleries objects

- As all fields are prefixed with "gallery_id" don't str_replace but 
use substr(), is faster

- countGalleries caches results but never returns it if recalled, as 
this was not noticed till now I guess that is never recalled so remove 
the parameters serialization

Saved Queries