Comment On The Query of Despair

Jeroen's colleague had the misfortune of being assigned to debug an intermittent, unspecified error in the one of the oldest of the legacy applications. "The good news is that I've isolated it to a database query," he told Jeroen, "the bad news is that I've isolated it to a database query." [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Re: The Query of Despair

2011-10-24 08:24 • by ParkinT
Rather than a "Wooden Table", this photograph was taken on a WHITEBOARD.

Re: The Query of Despair

2011-10-24 09:07 • by Spivonious (unregistered)
...

That's insane.

captcha: populus - boring game

Re: The Query of Despair

2011-10-24 09:07 • by trtrwtf (unregistered)
Probably true.

Re: The Query of Despair

2011-10-24 09:07 • by The poop of DOOM
Fr1st two words: SELECT ( SELECT. That's already very promising.

Also, not fr1st!

Re: The Query of Despair

2011-10-24 09:08 • by Matt (unregistered)
Holy Fuck, no human could write that!

Re: The Query of Despair

2011-10-24 09:13 • by SilentRunner
I don't get it. So much crap posted on The Daily WTF is for initiates only with no explanations for those of us with over 20 years programming experience who lack that finite bit of knowledge that makes YOUR WTF understandable.

Re: The Query of Despair

2011-10-24 09:13 • by Nagesh (unregistered)
364160 in reply to 364158
Matt:
Holy Fuck, no human could write that!

You are being corect: this is most likly Hibarnate.

Re: The Query of Despair

2011-10-24 09:13 • by frits
Looking at that image gave me a similar feeling to watching VanDamme dancing in the movie Kickboxer.

Re: The Query of Despair

2011-10-24 09:15 • by Ale (unregistered)
I've already seen a ten-page-long query. And it was used in a real application.
Thankfully, I've never had to debug it.

Re: The Query of Despair

2011-10-24 09:15 • by olaf (unregistered)
Why not tidysql the query instead of printing it out unreadable? (or printing it out at all)

Re: The Query of Despair

2011-10-24 09:16 • by C-Octothorpe
364164 in reply to 364161
frits:
Looking at that image gave me a similar feeling to watching VanDamme dancing in the movie Kickboxer.
What, nausea?

Re: The Query of Despair

2011-10-24 09:16 • by trollsolo (unregistered)
364165 in reply to 364160
I've seen many things do this. Use a beautifier. Sure it'll use more paper, but stable it together and it's worth it.

Re: The Query of Despair

2011-10-24 09:17 • by gobes
364166 in reply to 364163
olaf:
Why not tidysql the query instead of printing it out unreadable?

Because it would have made it longer.

Re: The Query of Despair

2011-10-24 09:17 • by dave (unregistered)
I feel for the his colleague.

Re: The Query of Despair

2011-10-24 09:19 • by Damien (unregistered)
The problem is on page 4, line 27. Isn't that obvious to everyone?

Re: The Query of Despair

2011-10-24 09:21 • by apaq11 (unregistered)
The worst part is I looked at that query and was like, oh hibernate probably generated that query. Then I looked again and from what I can see it doesn't look like it's aliasing tables/fields the way that hibernate would. This leads me to believe that someone probably wrote this...

Re: The Query of Despair

2011-10-24 09:23 • by frits
364172 in reply to 364164
C-Octothorpe:
frits:
Looking at that image gave me a similar feeling to watching VanDamme dancing in the movie Kickboxer.
What, nausea?
I think the colloquial term is "douche chills".

Re: The Query of Despair

2011-10-24 09:23 • by veggen
Seen a query of this size that was generated by an alien logic that my colleague wrote... and strangely enough, it was the only possible way to get the desired result as the DB structure was just as alien.

Re: The Query of Despair

2011-10-24 09:26 • by trtrwtf (unregistered)
364175 in reply to 364161
frits:
Looking at that image gave me a similar feeling to watching VanDamme dancing in the movie Kickboxer.


I'm feeling like I know more about frits than I want to know right now.

I'm off to have a shower.

Re: The Query of Despair

2011-10-24 09:28 • by Steve The Cynic
364176 in reply to 364159
SilentRunner:
I don't get it. So much crap posted on The Daily WTF is for initiates only with no explanations for those of us with over 20 years programming experience who lack that finite bit of knowledge that makes YOUR WTF understandable.

Well, I have over 20 years' programming experience, and evidently I have the necessary piece of knowledge. In fact, it's in the article. The picture shows a hard-copy of *one* SQL query. HTF does an SQL query get complex enough to be spread over six pages?

Re: The Query of Despair

2011-10-24 09:31 • by C-Octothorpe
364177 in reply to 364175
trtrwtf:
frits:
Looking at that image gave me a similar feeling to watching VanDamme dancing in the movie Kickboxer.


I'm feeling like I know more about frits than I want to know right now.

I'm off to have a shower.
That's more than I wanted to know about your relationship with frits...

Re: The Query of Despair

2011-10-24 09:31 • by C-Octothorpe
364178 in reply to 364172
frits:
C-Octothorpe:
frits:
Looking at that image gave me a similar feeling to watching VanDamme dancing in the movie Kickboxer.
What, nausea?
I think the colloquial term is "douche chills".
I totally forgot about that scene. Thanks for undoing hundreds of hours of therapy frits...

Re: The Query of Despair

2011-10-24 09:33 • by kjordan (unregistered)
364179 in reply to 364171
apaq11:
The worst part is I looked at that query and was like, oh hibernate probably generated that query. Then I looked again and from what I can see it doesn't look like it's aliasing tables/fields the way that hibernate would. This leads me to believe that someone probably wrote this...

I'm not even sure what kind of query you would have hibernate doing that it would do it like that. Hibernate seems to do it less in big queries now, but you might have more running to populate your objects if you don't have lazy loading turned on for relationships.

Re: The Query of Despair

2011-10-24 09:33 • by SuperQuery (unregistered)
364180 in reply to 364176
I've got one. Try being told to pull out info from 245 tables that all need to be related. To create another unassociated, mess of a db with..... :(
Although my is spaced a lot better :)

Re: The Query of Despair

2011-10-24 09:34 • by frits
364181 in reply to 364178
C-Octothorpe:
frits:
C-Octothorpe:
frits:
Looking at that image gave me a similar feeling to watching VanDamme dancing in the movie Kickboxer.
What, nausea?
I think the colloquial term is "douche chills".
I totally forgot about that scene. Thanks for undoing hundreds of hours of therapy frits...
If you've had the mispleasure of seeing that scene, no matter how long and far you try to stuff the memory, the pain will always be there.

Re: The Query of Despair

2011-10-24 09:37 • by The poop of DOOM
364182 in reply to 364181
frits:
C-Octothorpe:
frits:
C-Octothorpe:
frits:
Looking at that image gave me a similar feeling to watching VanDamme dancing in the movie Kickboxer.
What, nausea?
I think the colloquial term is "douche chills".
I totally forgot about that scene. Thanks for undoing hundreds of hours of therapy frits...
If you've had the mispleasure of seeing that scene, no matter how long and far you try to stuff the memory, the pain will always be there.

Seriously guys, I haven't seen that movie yet. Could you please put spoiler tags around this?

Then again, at least I've been warned now.

Re: The Query of Despair

2011-10-24 09:44 • by Bas (unregistered)
Awesome.. the mail reads "The platform is very slow and produces a lot of errors. Could you check this?"

Re: The Query of Despair

2011-10-24 09:44 • by Nagesh
If this is Orcle, Tomas Kyte can certenly help with it.

Re: The Query of Despair

2011-10-24 09:44 • by Anon (unregistered)
364185 in reply to 364176
Steve The Cynic:
HTF does an SQL query get complex enough to be spread over six pages?


I'd bet on generating reports that require aggregate functions while not actually using any aggregate functions.

My own record in reporting is a page and a half on one SQL-query (unbeautified). 7K of text, optimized the heck out of, to run in under two seconds every few hours.

Re: The Query of Despair

2011-10-24 09:47 • by someone (unregistered)
Oh my god... it's full of stars.

Re: The Query of Despair

2011-10-24 09:48 • by I. G. E. (unregistered)
364187 in reply to 364182
The poop of DOOM:
frits:
C-Octothorpe:
frits:
C-Octothorpe:
frits:
Looking at that image gave me a similar feeling to watching VanDamme dancing in the movie Kickboxer.
What, nausea?
I think the colloquial term is "douche chills".
I totally forgot about that scene. Thanks for undoing hundreds of hours of therapy frits...
If you've had the mispleasure of seeing that scene, no matter how long and far you try to stuff the memory, the pain will always be there.

Seriously guys, I haven't seen that movie yet. Could you please put spoiler tags around this?

Then again, at least I've been warned now.

I have seen it, and I haven't a clue what scene they may be talking about. In a Van Damme movie, what kind of *censored* even notices anything except the fighting scenes?

Re: The Query of Despair

2011-10-24 09:50 • by Lockwood
http://tinyurl.com/QueryOfDespairReaction

That's the first thing that sprung to mind when I saw that printout.

Also, they need a highlighter to make it have some more colour to discern various bits of it.

Re: The Query of Despair

2011-10-24 09:51 • by frits
364189 in reply to 364187
I. G. E.:
The poop of DOOM:
frits:
C-Octothorpe:
frits:
C-Octothorpe:
frits:
Looking at that image gave me a similar feeling to watching VanDamme dancing in the movie Kickboxer.
What, nausea?
I think the colloquial term is "douche chills".
I totally forgot about that scene. Thanks for undoing hundreds of hours of therapy frits...
If you've had the mispleasure of seeing that scene, no matter how long and far you try to stuff the memory, the pain will always be there.

Seriously guys, I haven't seen that movie yet. Could you please put spoiler tags around this?

Then again, at least I've been warned now.

I have seen it, and I haven't a clue what scene they may be talking about. In a Van Damme movie, what kind of *censored* even notices anything except the fighting scenes?
I'm sorry that I don't distinguish one type of fiction and choreography from another.

Re: The Query of Despair

2011-10-24 09:52 • by Canthros (unregistered)
364190 in reply to 364176
Steve The Cynic:
HTF does an SQL query get complex enough to be spread over six pages?

Regrettably, my second or third thought was, "I really hope that wasn't one I had to write." After another, closer look, it isn't (I never had to write anything against a schema with Dutch table names).

I wound up writing a hideous abomination of an 8+-way union, once. IIRC, it was a bunch of reporting queries that needed to be squished together, so the individual queries weren't terrible, there were just a lot of them.

It's also possible that it's a bunch of MS Access queries that have been strung together, which might explain the SELECT (SELECT thing at the start. Access has traditionally had some curiously quaint restrictions on query size that tends to turn any even moderately complex query into a maze of small, twisty queries, all alike.

Finally, it could just be that whoever created that thing had no idea what they were up to.

Re: The Query of Despair

2011-10-24 09:55 • by Anon (unregistered)
364191 in reply to 364185
Selffix: aggregate functions = somewhat complex aggregate functions, like AVG .. OVER ... RANGE BETWEEN .. etc.

Re: The Query of Despair

2011-10-24 09:56 • by C-Octothorpe
364192 in reply to 364182
The poop of DOOM:
frits:
C-Octothorpe:
frits:
C-Octothorpe:
frits:
Looking at that image gave me a similar feeling to watching VanDamme dancing in the movie Kickboxer.
What, nausea?
I think the colloquial term is "douche chills".
I totally forgot about that scene. Thanks for undoing hundreds of hours of therapy frits...
If you've had the mispleasure of seeing that scene, no matter how long and far you try to stuff the memory, the pain will always be there.

Seriously guys, I haven't seen that movie yet. Could you please put spoiler tags around this?

Then again, at least I've been warned now.
Just remember: what has been seen, cannot be unseen.

Re: The Query of Despair

2011-10-24 09:57 • by D (unregistered)
There is no hope. The best you can do is put the beast down. Burn the document, wipe the drives, torch the building... Oh, and flush the site with holy water just to be on the safe side.

Re: The Query of Despair

2011-10-24 10:01 • by Anon (unregistered)
364195 in reply to 364190
Canthros:
a bunch of MS Access queries


No. Please, just - no. *horrified*

Re: The Query of Despair

2011-10-24 10:03 • by boog
That's pretty bad, but in my experience such queries are usually a result of
1) lack of SQL know-how and
2) extensive CTRL+Cing-and-CTRL+Ving.

This massive beast is most likely a handful of copies of several smaller-but-ever-so-slightly-different beasts all JOINed and UNIONed together. Example:

SELECT (bunch of crappy columns)
FROM (bunch of crappy tables)
WHERE (bunch of crappy conditions)
AND item_type = "XYZZY"
UNION
SELECT (the same crappy columns)
FROM (the same crappy tables)
WHERE (the same crappy conditions)
AND item_type = "PLUGH"
UNION
...

I bet if you format it, it'd take (at most) only a couple months and all your remaining sanity to refactor it into something mentally-parsable.

Re: The Query of Despair

2011-10-24 10:08 • by C-Octothorpe
364198 in reply to 364197
boog:
That's pretty bad, but in my experience such queries are usually a result of
1) lack of SQL know-how and
2) extensive CTRL+Cing-and-CTRL+Ving.

This massive beast is most likely a handful of copies of several smaller-but-ever-so-slightly-different beasts all JOINed and UNIONed together. Example:

SELECT (bunch of crappy columns)
FROM (bunch of crappy tables)
WHERE (bunch of crappy conditions)
AND item_type = "XYZZY"
UNION
SELECT (the same crappy columns)
FROM (the same crappy tables)
WHERE (the same crappy conditions)
AND item_type = "PLUGH"
UNION
...

I bet if you format it, it'd take (at most) only a couple months and all your remaining sanity to refactor it into something mentally-parsable.
Which is exactly why he shouldn't try to RE the bitch and should just rewrite it from scratch based on specs (HA!) or expected behavior...

Re: The Query of Despair

2011-10-24 10:10 • by WC (unregistered)
Am I the only one here that wishes he (or she) could attempt to clean that up and then refactor it? :D

Inside that ugly mess is some beautiful code, just trying to come out.

Re: The Query of Despair

2011-10-24 10:11 • by Ross (unregistered)
364200 in reply to 364193
Nuke the site from orbit. It's the only way to be sure.

Re: The Query of Despair

2011-10-24 10:12 • by Canthros (unregistered)
364201 in reply to 364195
Anon:
Canthros:
a bunch of MS Access queries


No. Please, just - no. *horrified*

I think I'm wrong about that, anyway. Looks like the beginning is caused by the first column being an aggregate (count) in a correlated subquery against a different table.

But, yeah. When I was decoding Access queries, many oaths were sworn and curses invoked.

Re: The Query of Despair

2011-10-24 10:12 • by Daniil S. (unregistered)
Just out of sheer curiosity, I really wish to see this query in full.

Re: The Query of Despair

2011-10-24 10:26 • by Zylon
Obligatory grammar snark:

"I don't think anyone can help me," the his colleague wrote.

CHOOSE ONE OR THE OTHER ALEX.

Re: The Query of Despair

2011-10-24 10:28 • by trtrwtf (unregistered)
364206 in reply to 364202
Daniil S.:
Just out of sheer curiosity, I really wish to see this query in full.


As a wise man once said, "Just remember: what has been seen, cannot be unseen."

Re: The Query of Despair

2011-10-24 10:28 • by boog
On the plus side (for Jeroen's colleague), since this SQL was submitted as a CodeSOD instead of a Representative Line, I assume it implies some semblance of sanity in the rest of the source.

Re: The Query of Despair

2011-10-24 10:30 • by trtrwtf (unregistered)
364208 in reply to 364205
Zylon:
Obligatory grammar snark:

"I don't think anyone can help me," the his colleague wrote.

CHOOSE ONE OR THE OTHER ALEX.


There's only one Alex writing this, grammar boy.

(I gots to keep up my grammar Nazi rep, yo)

Re: The Query of Despair

2011-10-24 10:30 • by My Name Is Missing (unregistered)
I once helped out on a project with a SQL query that long that took 70 seconds to complete on average (not good for a web app!). I fixed it by extracting the relevant data from the database and doing the search in RAM, reducing the query time to sub second. Some things are best not done with a relational database.

Re: The Query of Despair

2011-10-24 10:30 • by The poop of DOOM
364210 in reply to 364207
boog:
On the plus side (for Jeroen's colleague), since this SQL was submitted as a CodeSOD instead of a Representative Line, I assume it implies some semblance of sanity in the rest of the source.

To apply for Representative Line, it should be a line, not six pages.
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Add Comment