- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
And they're only returning the frist result from the query...
Admin
I think the phrase "Cartesian Join" gives it away. (Twice.) Occasionally useful things, but ... not very often.
Admin
The ancient curse of the comma join lurks under the surface of the data lake waiting to trap the unwary.
Admin
Oh yes...
select frob, bar baz from meh, duh, gah where frob.thin = bar.gummy and bar.other = gah.shite and gargle = 'froob'
"oh, this doesn't return any results, let's do a left join!" .. frob.thin *= bar.gummy ..
<years later> Query fails because some unaware poor soul did an "ALTER gah add frob varchar(255)" and presto: ambiguous column!/there's a reason why some people regularly drink too much.
Addendum 2021-10-21 08:04: TIL that *= also is a "Multiplication Assignment"
(https://docs.microsoft.com/en-us/sql/t-sql/language-elements/multiply-equals-transact-sql?view=sql-server-ver15)
T-SQL:
declare @frob int = 5, @honk int = 10 select @frob *= 2 select @frob -- 10
select @honk *= @honk select @honk -- 100
honk
Admin
The aliases - are they original or the author's addition?
Admin
That was the submitter's addition, and I just went with it.
Admin
I'm reading this while working on this morning's coffee so it's nice the have the real WTF clearly labeled inline.
Admin
Me: "19 percent CPU? That's not so ba--" My brain: "Peta. The SI prefix for 10^15 is a P. We're off by 13 orders of magnitude." Me: "--aaaaaaaAAAAAAAA..."
Admin
My coffee: "17. We're off by 17 orders of magnitude."
Admin
Sure I'd love it if the database would just magically know what data I wanted without me having to write a query....
Admin
It's not so much about not writing a query. It's about writing a query that clearly communicates your intentions to the optimizer.
SELECT * FROM Employees WHERE LastName LIKE 'x%'
... is very different from ...
SELECT * FROM Employees WHERE SUBSTRING(LastName, 1, 1) = 'x'
The first communicates to the optimizer that it can seek directly to the 'x' section of an index for the values (if that turns out to provide better performance). The second tells it to run a function on every LastName and then filter the results. The second gives the optimizer far less room to consider alternate plans.
Admin
This morning I was reading my salad greens container and it said it was washed³. I was like, so as you progressed along each leaf, you washed each other leaf, and as you progressed along those you also washed each other leaf? So.... just like this crazy query.
Admin
I'm not even sure that there's an excuse based upon "oh, it must be auto-generated." I mean, what is so hard about autogenerating
... with optional ORDER BY and TOP and what not? I mean, seriously. I'll admit that my Mickey Mouse implementation above is terrible, but the worst you do (without suitable indexing and ordering within the database, is O(N) for the number of rows in the table. Even the stupidest automatic SQL generator can manage this.
Admin
Those table names might not be autogenerated. When I started working a little bit before year 2000, one car manufacturer I was working at, was using Oracle 7, but all database objects had a naming convention:
(example - simplified, off memory, just to give the idea) TAPP0023 was of course the table from the PP (= Piattaforma Progettuale = set of tools used to contain the bill of materials for the various car models) listing the car models TAPP0096 was the table for the list of parts available across the models TAPP0104 was the relation between the two above (because the request for the two tables had to be done in two different documents sent for approval, so the number would not end being contiguous).
and of course you would be joining a lot between TAPP096 and TASP0040 (the table from the "Siti Produttivi" = production plants) listing where such parts would be produceable.
Simple, isn't it?
Admin
Worse... Old mainframe shop. Log books (paper type) for everything... Need to write a job... ot to the book, look for next blanks space, write title and sign. The number on that line was the name of you jcl job. They employed (I mean abused) two interns to just write sequences for different things into log books as they filled regularly...
Admin
|select frob, bar baz from meh, duh, gah where frob.thin = bar.gummy and bar.other = |gah.shite and gargle = 'froob' | |"oh, this doesn't return any results, let's do a left join!" .. frob.thin *= bar.gummy .. |<years later> Query fails because some unaware poor soul did an "ALTER gah add frob |varchar(255)" and presto: ambiguous column! | |/there's a reason why some people regularly drink too much.
While I agree that in multi-table queries you should identify where each field comes from for future safety that's not what's happening here. This abomination specifies the same table to be queried three times. I'm surprised at the result, though--I would have thought the worst case here was just doing three times the work.
Admin
I'm surprised nobody noticed that this query is probably returning an incorrect result. While the intent is probably to get the minimum moddate where the rdate (whatever that is) is larger than sysdate-1095 (what kind of random number is that?), that where clause is not applied to the table that produces the minimum moddate. The end result therefore is the minimum moddate of any record in this table.
Admin
Pretty sure this is how Paula would do it -- it's so Brilliant!
Admin
Did anyone else notice that the 'From' clause embeds the phrase 'What the f'?
It was the first thing I saw, not being a dba!
Admin
Honestly who thought that a comma should mean full join? Please join when I ask for a join!
Admin
select Min(the.moddate) "ModifiedDate" From T_91CDDC57 revenge , T_91CDDC57 [is] , T_91CDDC57 mineth where mineth.rdate > sysdate-1095;
Right?
Admin
select Min(the.moddate) "ModifiedDate" From T_91CDDC57 revenge , T_91CDDC57 [is] , T_91CDDC57 mineth where mineth.rdate > sysdate-1095;
Right?
Admin
I've seen Oracle crap itself with bad query plan. We have a table with 20m or so rows. Usually query plan uses index and has to work with less than 100 rows. On some star alignment Oracle decides to go out of its way and somehow make a plan that works on 24P rows. Fun times.