Comment On Slowed Fusion

One of Fregas' clients was frustrated with their ColdFusion-based inventory & accounting system. They had paid another company with "a team of specialized ColdFusion experts" to custom-build their system, but were having problems as the system kept getting slower and slower. They were especially annoyed with this problem because they were sold on the fact that ColdFusion was very fast. While "speeding up" the system, Fregas came across quite possibly the slowest way to do a table record count ... [expand full text]
« PrevPage 1 | Page 2Next »

Re: Slowed Fusion

2005-10-18 11:43 • by Jonathan
whatever happened to the COUNT function in SQL itself?

Re: Slowed Fusion

2005-10-18 11:43 • by Ladislaus

One word: Brilliant!


Who's this genius, and where can I hire him/her?

Re: Slowed Fusion

2005-10-18 11:47 • by Anonymous Coward
Maybe they were good at cf but they sucked hard at SQL

Re: Slowed Fusion

2005-10-18 11:56 • by dotzie
This few-queries-instead-one approach is very, very common...

It's also an easiest way to earn some bucks and reputation too (because the performance gain is O(1) and not O(n), so it's usually noticeable), when you correct such faults.

Re: Slowed Fusion

2005-10-18 11:59 • by SheridanCat
I haven't had to write any ColdFusion in a few years, but as I recall
this is exactly the type of thing that inexperienced CF coders would
do.  I once attempted to help a coworker debug a 2000 line CF
program he wrote.  Oh, the humanity. 



ColdFusion's big benefit is also it's main problem.  It's easy to
get started with, thus a lot of crappy code that more or less works
gets written.



Sheridan

Re: Slowed Fusion

2005-10-18 12:10 • by Manni
47178 in reply to 47177

SheridanCat:

ColdFusion's big benefit is also it's main problem.  It's easy to get started with, thus a lot of crappy code that more or less works gets written.


A.K.A. - Visual Basic. I know I know, the VB zealot trouncing his own language. I've seen a lot of VB code like this before, where people don't bother to investigate the data source they're accessing to see if there's a better way.


And on that note, I'd like to use this icon because I've never seen anyone else use it: [pi]

Re: Slowed Fusion

2005-10-18 12:11 • by Manni
47179 in reply to 47178
Manni:

And on that note, I'd like to use this icon because I've never seen anyone else use it: [pi]



Uh...WTF?

Re: Slowed Fusion

2005-10-18 12:12 • by d4ddyo


My CF is sketchy as well, but there's something a bit disconcerting
about the "Request.InitechDatabase" reference.




I have no idea where
this "team of specialized ColdFusion experts" hails from, but it's a
perfect example of how the coder community can be it's own worst enemy.
The person who wrote this code is occupying a position that could be
held by someone who actually deserves it ;)


Re: Slowed Fusion

2005-10-18 12:21 • by tekiegreg

Ugggh so many better ways of doing this...


If CF if all I needed was the record count (not using the query results later) it's typical to just let SQL do it (SELECT Count(*) FROM bookings ....)


If I needed both the count and data there was always the given variable #q2.recordcount# that does the trick as well.


Sad....

Re: Slowed Fusion

2005-10-18 12:23 • by Pope Anonymous
47182 in reply to 47174
Ladislaus: You misspelled "Brillant."

Re: Slowed Fusion

2005-10-18 12:23 • by Ytram
47183 in reply to 47179
[pi]

Re: Slowed Fusion

2005-10-18 12:24 • by WIldpeaks

Ohh, Paula got a new job apparently...

Re: Slowed Fusion

2005-10-18 12:28 • by Tom K
A little SQL knowledge would have produced a statement like this 
that would have performed the entire task in a fraction of the time:

SELECT Client_Num, Count(*) FROM Bookings group by Client_Num

Unfortunately, there are too many "developers" out there who are so
ignorant of SQL.

Re: Slowed Fusion

2005-10-18 12:35 • by Xepol
Looks like the developer recently moved from PHP and MySQL. Its the ONLY place where code this stupid is considered industry norm.

Always get references for consultants, and preferably view a system they wrote in action.

Re: Slowed Fusion

2005-10-18 12:58 • by Joost_
47187 in reply to 47183
[p]

Re: Slowed Fusion

2005-10-18 13:01 • by anon
47188 in reply to 47186
hmm? i don't think i've ever seen any php/mysql code that used a loop
to count a record set. mysql does have count(), you know... not to
mention php has mysql_num_rows, which you get for "free" with the
database result.

Re: Slowed Fusion

2005-10-18 13:03 • by Colin
47189 in reply to 47185
Anonymous:
A little SQL knowledge would have produced a statement like this 
that would have performed the entire task in a fraction of the time:

SELECT Client_Num, Count(*) FROM Bookings group by Client_Num

Unfortunately, there are too many "developers" out there who are so
ignorant of SQL.




SELECT Client_Num, Count(1) FROM Bookings group by Client_Num

Would actually be faster since the * will have to replace each column....


Re: Slowed Fusion

2005-10-18 13:04 • by Ytram
47190 in reply to 47187
[3.14159]

Re: Slowed Fusion

2005-10-18 13:19 • by anon
47191 in reply to 47190


Um, unless I'm missing something wouldn't it be even easier to do something like:





Re: Slowed Fusion

2005-10-18 13:21 • by anon
47192 in reply to 47191


Doh! I should say that would be easier.



I meant:



select count(*) from bookings

where client_num = '#client_num#'

and bookings_active_indicator = "Y";



It's like he did half a selection???

Hard to tell

2005-10-18 13:26 • by Maurits
OK, here's my version of the equivalent single SQL statement:

SELECT [ActiveBookings] = COUNT(*) FROM Bookings WHERE bookings_active_indicator = 'Y'

But it's kind of hard to tell whether stuff was snipped in the loops, or whether the sole purpose of this code was to populate the bookingsCount variable?

Re: Slowed Fusion

2005-10-18 13:40 • by Jeff S
47194 in reply to 47189
Anonymous:
Anonymous:
A little SQL knowledge would have produced a statement like this 
that would have performed the entire task in a fraction of the time:

SELECT Client_Num, Count(*) FROM Bookings group by Client_Num

Unfortunately, there are too many "developers" out there who are so
ignorant of SQL.


SELECT Client_Num, Count(1) FROM Bookings group by Client_Num

Would actually be faster since the * will have to replace each column....



No.  COUNT(*) is nothing like SELECT * other than the fact that they both use the asterisk character to denote something.

Re: Slowed Fusion

2005-10-18 13:44 • by Jeff S
47195 in reply to 47185
Anonymous:
A little SQL knowledge would have produced a statement like this 
that would have performed the entire task in a fraction of the time:

SELECT Client_Num, Count(*) FROM Bookings group by Client_Num

Unfortunately, there are too many "developers" out there who are so
ignorant of SQL.


Close.


SELECT Client_Num, Count(*)
FROM Bookings group by Client_Num
WHERE bookings_active_indicator = 'Y'


By the way, I love thecolumn name "bookings_active_indicator" ....


The grouping on client_num depends if there is some code in there that was snipped that displays the count per client.  Otherwise, of course, just a single count w/o any grouping would be needed to returned the total.

Re: Slowed Fusion

2005-10-18 13:46 • by RevMike
47196 in reply to 47189
Anonymous:
Anonymous:
A little SQL knowledge would have produced a statement like this 
that would have performed the entire task in a fraction of the time:

SELECT Client_Num, Count(*) FROM Bookings group by Client_Num

Unfortunately, there are too many "developers" out there who are so
ignorant of SQL.




SELECT Client_Num, Count(1) FROM Bookings group by Client_Num

Would actually be faster since the * will have to replace each column....





Whether or not this is faster is sensitive to database product and
version.  Many SQL optimizers look for Count(*) specifically and
optimize its calculation.



Furthermore, the performance of this query could be substantially
affected by the indexing scheme.  It is a pretty reasonable guess
that Client_Num is indexed. An ordered index could be traversed very
easily in order to calculate the counts, but a tree index might have
all the counts pre-calculated.



My messagae here is that if this query is important to the performance
profile of your application, there is no substitute for benchmarking.

Re: Slowed Fusion

2005-10-18 13:55 • by Craig
47197 in reply to 47174

Anonymous:


One word: Brilliant!



Alright, people... The Brillant and IsTrue jokes are played out. Know when a good thing is no longer good and let it go. Just let it go...

Re: Slowed Fusion

2005-10-18 14:01 • by Mike R
47199 in reply to 47178
Manni:

SheridanCat:

ColdFusion's big
benefit is also it's main problem.  It's easy to get started with,
thus a lot of crappy code that more or less works gets written.


A.K.A. - Visual Basic. I know I know, the VB zealot trouncing his
own language. I've seen a lot of VB code like this before, where people
don't bother to investigate the data source they're accessing to see if
there's a better way.


And on that note, I'd like to use this icon because I've never seen anyone else use it: [pi]





Oh! you mean this: ?

Re: Slowed Fusion

2005-10-18 14:07 • by JohnO
47200 in reply to 47197
Anonymous:

Anonymous:


One word: Brilliant!



Alright, people... The Brillant and IsTrue jokes are played out. Know when a good thing is no longer good and let it go. Just let it go...



But...if you have to do it, at least spell brillant right.

Re: Slowed Fusion

2005-10-18 14:11 • by Martin Carolan
47201 in reply to 47176
Actually, it is still only 1 query, but he's shifting the data logic
from the database layer to the web layer. That's the wtf as the
database layer uses complex algorithms to increase performance, and it
doesn't require all of the data to be sent to the web layer then
processed.

Re: Slowed Fusion

2005-10-18 14:18 • by WIldpeaks
47202 in reply to 47195

By the way, I love thecolumn name "bookings_active_indicator" ....


I wouldn't be surprised if they used a char(1) for it in addition...

Re: Slowed Fusion

2005-10-18 14:24 • by Mung Kee
47204 in reply to 47197
Anonymous:

Anonymous:


One word: Brilliant!



Alright, people... The Brillant and IsTrue jokes are played out.
Know when a good thing is no longer good and let it go. Just let it
go...





Seriously, they make it into almost every thread don't they.

Re: Slowed Fusion

2005-10-18 14:26 • by Mung Kee
47205 in reply to 47199
Mike R:
Manni:

SheridanCat:

ColdFusion's big
benefit is also it's main problem.  It's easy to get started with,
thus a lot of crappy code that more or less works gets written.


A.K.A. - Visual Basic. I know I know, the VB zealot trouncing his
own language. I've seen a lot of VB code like this before, where people
don't bother to investigate the data source they're accessing to see if
there's a better way.


And on that note, I'd like to use this icon because I've never seen anyone else use it: [pi]





Oh! you mean this: ?




I haven't the slightest idea of what to make of that icon.  Very peculiar. 

Re: Slowed Fusion

2005-10-18 14:32 • by suidae
47207 in reply to 47205
Mung Kee:
Mike R:
Manni:

And on that note, I'd like to use this icon because I've never seen anyone else use it: [pi]





Oh! you mean this: ?




I haven't the slightest idea of what to make of that icon.  Very peculiar. 




It's a slice of a pizza pie, whats so weird about that?

Re: Slowed Fusion

2005-10-18 14:52 • by Mung Kee
47208 in reply to 47207
Anonymous:
Mung Kee:
Mike R:
Manni:

And on that note, I'd like to use this icon because I've never seen anyone else use it: [pi]





Oh! you mean this: ?




I haven't the slightest idea of what to make of that icon.  Very peculiar. 




It's a slice of a pizza pie, whats so weird about that?




Trust me, I love a pie every bit as much as the next guy.  I'm just not sure of what possible context it could be used.

Re: Slowed Fusion

2005-10-18 15:00 • by TPS Reports, anyone?
47209 in reply to 47180
d4ddyo:


My CF is sketchy as well, but there's something a bit disconcerting
about the "Request.InitechDatabase" reference.




I have no idea where
this "team of specialized ColdFusion experts" hails from, but it's a
perfect example of how the coder community can be it's own worst enemy.
The person who wrote this code is occupying a position that could be
held by someone who actually deserves it ;)







Initech.  Office Space ( http://www.imdb.com/title/tt0151804/ ).  Concerned yet?

Re: Slowed Fusion

2005-10-18 15:07 • by meh
47210 in reply to 47207
count(*) vs count(column).  count(*) means "count all rows that match the WHERE".  count(column) means "count all rows that match the WHERE AND column IS NOT NULL."

SELECT count(*) FROM table WHERE x IS NOT NULL

is the same as:

SELECT count(x)

Some databases can optimize the count(*) into an O(1) operation, some always perform a table scan.

Re: Slowed Fusion

2005-10-18 15:15 • by Maurits
47211 in reply to 47210
Anonymous:
count(*) vs count(column).  count(*) means "count all rows that match the WHERE".  count(column) means "count all rows that match the WHERE AND column IS NOT NULL."

SELECT count(*) FROM table WHERE x IS NOT NULL

is the same as:

SELECT count(x)

Some databases can optimize the count(*) into an O(1) operation, some always perform a table scan.


There's also COUNT(DISTINCT x) which counts the number of different non-null values of x across the rowset.

Re: Slowed Fusion

2005-10-18 15:18 • by Milton Waddams
47212 in reply to 47209
Anonymous:
d4ddyo:


My CF is sketchy as well, but there's something a bit disconcerting
about the "Request.InitechDatabase" reference.




I have no idea where
this "team of specialized ColdFusion experts" hails from, but it's a
perfect example of how the coder community can be it's own worst enemy.
The person who wrote this code is occupying a position that could be
held by someone who actually deserves it ;)







Initech.  Office Space ( http://www.imdb.com/title/tt0151804/ ).  Concerned yet?




It can't be that Initech.  That one burned down.

Re: Slowed Fusion

2005-10-18 15:22 • by kipthegreat
47213 in reply to 47212
Anonymous:
Anonymous:
d4ddyo:


My CF is sketchy as well, but there's something a bit disconcerting
about the "Request.InitechDatabase" reference.




I have no idea where
this "team of specialized ColdFusion experts" hails from, but it's a
perfect example of how the coder community can be it's own worst enemy.
The person who wrote this code is occupying a position that could be
held by someone who actually deserves it ;)







Initech.  Office Space ( http://www.imdb.com/title/tt0151804/ ).  Concerned yet?




It can't be that Initech.  That one burned down.




When I read that I figured company names were changed to protect the (arguably not) innocent..

Re: Slowed Fusion

2005-10-18 15:22 • by Ytram
47214 in reply to 47209
Anonymous:
d4ddyo:


My CF is sketchy as well, but there's something a bit disconcerting
about the "Request.InitechDatabase" reference.




I have no idea where
this "team of specialized ColdFusion experts" hails from, but it's a
perfect example of how the coder community can be it's own worst enemy.
The person who wrote this code is occupying a position that could be
held by someone who actually deserves it ;)







Initech.  Office Space ( http://www.imdb.com/title/tt0151804/ ).  Concerned yet?




What's there to be concerned about?  Alex is simply using that reference to anonymize the actual company name.



Seriously, do you think there are very many coders that would not know what Office Space is?

Re: Slowed Fusion

2005-10-18 15:36 • by John Bigboote
47215 in reply to 47197
Anonymous:

Anonymous:


One word: Brilliant!



Alright, people... The Brillant and IsTrue jokes are played out.
Know when a good thing is no longer good and let it go. Just let it
go...





I agree. I think we can start getting some mileage out of "brilant" though.

Re: Slowed Fusion

2005-10-18 15:41 • by kipthegreat
Alex Papadimoulis:



<cfquery name="q1" datasource="#Request.InitechDatabase#">
SELECT * FROM Clients
</cfquery>
<cfloop query="q1">
<cfquery name="q2" datasource="#Request.InitechDatabase#">
SELECT * FROM Bookings WHERE Client_Num = '#Client_Num#'
cfquery>
<cfif q2.recordcount GT 0>
<cfloop query="q2">
<cfif q2.bookings_active_indicator IS "Y">
<cfset bookingsCount = bookingsCount + 1>
</cfif>
</cfloop>
</cfif>
</cfloop>




This is the first ColdFusion code I've ever seen.. Is this Java-like pseudocode accurately representing what is going on?



bookingsCount = 0;

q1 = "SELECT * FROM Clients";

q1_results = run_query(q1);

for (i = 0; i < length(q1_results); i++)

{

  q2 = "SELECT * FROM Bookings WHERE Client_Num = '" + q1_results[i].Client_Num + "'";

  q2_results = run_query(q2);

  if (length(q2_results) > 0)

  {

    for (j = 0; j < length(q2); j++)

    {

      if (q2_results.bookings_active_indicator == "Y")

      {

        bookingsCount = bookingsCount + 1;

      }

    }

  }

}




Sincerely



Gene Nixon the Great

Re: Slowed Fusion

2005-10-18 15:50 • by kiriran
47218 in reply to 47215
thats pretty sad. and they cant be experts on coldfusion either. ever heard of myquery.recordcount ? of course the SELECT COUNT(*) is the best way doing it but if they had little CF knowleged, they would know at least recordcount.

Re: Slowed Fusion

2005-10-18 15:56 • by Manni
47219 in reply to 47199
Mike R:
Manni:

SheridanCat:

ColdFusion's big benefit is also it's main problem.  It's easy to get started with, thus a lot of crappy code that more or less works gets written.


A.K.A. - Visual Basic. I know I know, the VB zealot trouncing his own language. I've seen a lot of VB code like this before, where people don't bother to investigate the data source they're accessing to see if there's a better way.


And on that note, I'd like to use this icon because I've never seen anyone else use it: [pi]




Oh! you mean this: ?


Bastard! How did you do it? I saw that Ytram tried and got the same results as me.


Stupid forum software, can't even insert a picture of a slice of pizza. Wow, I never thought i'd get a chance to say that. Rubber baby buggy bumper.

Re: Slowed Fusion

2005-10-18 15:59 • by Richard Nixon
47220 in reply to 47219
Manni:
Mike R:
Manni:

SheridanCat:

ColdFusion's big benefit is also it's
main problem.  It's easy to get started with, thus a lot of crappy
code that more or less works gets written.


A.K.A. - Visual Basic. I know I know, the VB zealot trouncing his
own language. I've seen a lot of VB code like this before, where people
don't bother to investigate the data source they're accessing to see if
there's a better way.


And on that note, I'd like to use this icon because I've never seen anyone else use it: [pi]




Oh! you mean this: ?


Bastard! How did you do it? I saw that Ytram tried and got the same results as me.


Stupid forum software, can't even insert a picture of a slice of
pizza. Wow, I never thought i'd get a chance to say that. Rubber baby
buggy bumper.





I'll give it a shot too.

Re: Slowed Fusion

2005-10-18 16:02 • by Ytram
47221 in reply to 47219
[pi]
Manni:
Mike R:
Manni:

SheridanCat:

ColdFusion's big benefit is also it's main problem.  It's easy to get started with, thus a lot of crappy code that more or less works gets written.


A.K.A. - Visual Basic. I know I know, the VB zealot trouncing his own language. I've seen a lot of VB code like this before, where people don't bother to investigate the data source they're accessing to see if there's a better way.


And on that note, I'd like to use this icon because I've never seen anyone else use it: [pi]




Oh! you mean this: ?


Bastard! How did you do it? I saw that Ytram tried and got the same results as me.


Stupid forum software, can't even insert a picture of a slice of pizza. Wow, I never thought i'd get a chance to say that. Rubber baby buggy bumper.



C'mon Manni, it's easy!  [pi]


If that doesn't work, oh man I'll look like such an ass.  I want to vacuum.

Re: Slowed Fusion

2005-10-18 16:04 • by Ytram
47222 in reply to 47219
Manni:
Mike R:
Manni:

SheridanCat:

ColdFusion's big benefit is also it's main problem.  It's easy to get started with, thus a lot of crappy code that more or less works gets written.


A.K.A. - Visual Basic. I know I know, the VB zealot trouncing his own language. I've seen a lot of VB code like this before, where people don't bother to investigate the data source they're accessing to see if there's a better way.


And on that note, I'd like to use this icon because I've never seen anyone else use it: [pi]




Oh! you mean this: ?


Bastard! How did you do it? I saw that Ytram tried and got the same results as me.


Stupid forum software, can't even insert a picture of a slice of pizza. Wow, I never thought i'd get a chance to say that. Rubber baby buggy bumper.



I've got it!! 

Re: Slowed Fusion

2005-10-18 16:04 • by OneFactor
47223 in reply to 47215
John Bigboote:
Anonymous:

Anonymous:


One word: Brilliant!



Alright, people... The Brillant and IsTrue jokes are played out. Know when a good thing is no longer good and let it go. Just let it go...




I agree. I think we can start getting some mileage out of "brilant" though.


I'm just wondering if Alex is too scared to say "Brillant was my typo, Paula actuall got it right"

Re: Slowed Fusion

2005-10-18 16:23 • by Manni
47225 in reply to 47222
Ytram:

I've got it!! 



I hate you all. Yes you looked like an idiot at first, only partly due to the fact you thought you were displaying pizza icons, but you've slightly redeemed yourself. Should I put the IMG tags in manually then? Screw that, then I'll look like the idiot that can't make pizza on the screen, and whose messages look like <img src="lbahbhla"> because the forum software will undoubtedly convert my tags to plain text.


Maybe you can do those icons, but look what I can do! *jumps in the air* I can do it way better than Stuart.


And about the Initech stuff...if this is the first article you've read on the The Daily WTF, Alex (the forum administrator and site owner) anonymizes the code by replacing company names with "Initech". Why? Because it's a reference from "Office Space", a movie about how inept corporate America is when it comes to software development, employee morale, and proper managerial structure.


You've been warned. The next "warning" will be an aluminum bat to your knees. Try ice skating in the Olympics after that.

Re: Slowed Fusion

2005-10-18 16:29 • by whojoedaddy
47227 in reply to 47219

Hmm, I like 

Re: Slowed Fusion

2005-10-18 16:46 • by Ytram
47229 in reply to 47225
Actually all I did was quote the guy that got it working right, and then I just cut and pasted his pizza [:P]



Of course, from now on, I'll have to return to this thread and cut and paste and see if it works across threads.



When the moon hits your eye

Like a big

That's amore...



(8 slices = one pizza pie)
« PrevPage 1 | Page 2Next »

Add Comment