- 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
"No one is empowered to fix it or address the root cause"
That's the real WTF
Admin
Yeah, I was going to say the same thing, especially if "No one is empowered to ..." means "No one is allowed to ..."
Admin
I see things like this (magic numbers and all), and I wonder what all the other queries in the system look like. Hard to imagine this one is uniquely bad, particularly if there's a LOTFIL code generator used all over the place,.
Admin
How about the WTF of a reader blocking other readers/writers
Admin
So many WTFs ...
Admin
It will affect the number of rows returned if the join query isn't unique. If FL2.FLFILTYP = 'A1' AND FL2.FLLOTNBR = SALLSTDM.SLLOTNBR returns 2 rows. Then it'll multiple the output by 2^10. Now image it returns 10 rows. That would take a while.
Admin
Why wouldn't it affect the count? Every further join could reduce the total amount of rows if there is nothing to match it with. If the last table alone is empty, the count would be 0.
Admin
I feel the need to confess that I am prone to do the same thing. -> joining <sometable> n+1 times always seems to be easier than to faff around with PIVOT and so far -IME- does not have any ..bad|negative|whatever.. outcomes.
/of course (what, me? !NEVER!) one would do something sensible with the joins itself and not blindly doing something but shite happens. //also I feel the need to mention that I am not not the creator of aforementioned :wtf:, I cannae remember the last time I used mySQL so this neither affected not effected me ;-)
Admin
It's a good thing that table and column names can't be longer than 8 characters or I'd accuse this whole schema of being needlessly miserable, even before this particular query turned up.
Admin
dkf I can't tell you the NBR of times I've come across this TYP of problem.
Admin
When Remy wrote this:
I believe Remy actually meant "they/them " or "he/him" in place of "it".
Admin
WHERE 1=1 is NOT a WTF. It is an old trick for building dynamic queries from user supplied filters where there could be zero or one or more where clauses to tack on to the base query. It has no impact at all.
Admin
Except for the fact that there's more than zero filters in this case. You'd kinda think an automated query generator would recognise that simple case.
Admin
Admin
As to the blocking reader, the story tells us this ghastly query is part of a larger procedure. So I'm betting its something like this:
If you (IOW that dev or DBA shop) don't know what a transaction is, this may be the only way to avoid dirty reads leading to dirty writes.
Admin
Or maybe even "she/her". The first programmer I ever met was a woman. Er. My own mother.
Admin
Since all of the joins are with the same table and the same ON condition, the number of rows in each join will be the same. If the last one is zero rows, so is the first one.
However, a join creates a cross product, so if each join is with multiple rows, the size of the result will multiply, not shrink.
Admin
I have to admit this is the first time I've read one of these where I involuntarily said the WTF phrase out loud.
Admin
Agree that it will multiply the row counts! In which case, "ew, dat's nastay!"
If he can't fix the query generator, is it possible to interject some sort of preprocessing stage at the database where it recognizes the string pattern in the query and replaces it with the intended line?
Admin
If we assume this is a special case of a more general query built in response to some user selections, I wonder how it performs if the 10 joins are each on different conditions still against the same table? IOW, what if each of the
Fx.FLFILTYP = "A1"
comparisons are different constants, not all "A1"?Still gonna be ugly.
I don't work with MySQL, but I also wonder if
count(*)
is less efficient than count(1), or count(ThePKField)?Admin
I'll tell you more: the first known programmer to live was a woman.
Admin
The code is marginally simpler with the
1 = 1
case.Firstly, if there are no filters, you don't haver to omit the
WHERE
clause from the query you are building.Secondly, you don't need the special code to detect whether this is the first filter or not. For every filter including the first one, you can add
AND (filter-n)
to the where clause.Admin
That's the problem with kowtowing to political-agenda speech.
"He" is the proper singular/third-person pronoun, period. Not "they," not "he/she"...
As Shakespeare would have said, "Save your face from the putrid gash and grow a pair."
Admin
I smell a converted DB2 database - why else would the column names be no more than 8 characters?
Admin
The 1=1 clause indicates that this was not generated by an ORM. Someone actually created this query by hand, for…. reasons.
Admin
Except singular they has been around for centuries before all the gender stuff even became a thing.
https://public.oed.com/blog/a-brief-history-of-singular-they/