- 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
Don't be silly. Registry entries are limited to 1024 characters.
Admin
What is a better way of doing this in SQL?
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( REPLACE(REPLACE(REPLACE( REPLACE(REPLACE( REPLACE(Documents.Destination,' ',''),')', ''),'(',''),'-',''),'/',''),'.',''),'*',''), ',',''),';',''),'',''),'-','')
Admin
It's kinda a wtf, but I won't call it horrendous: a. certainly shouldn't be all on one line. Better to be rewritten in a way usable as a stored proc. at least the query plan would be saved. b. there seems to be replaces which could, at the least, be placed in a user defined function. TRWTF is that standard SQL doesn't have anything to aggregate character class replacements into a single statement. c. That's one mother of a query. I just bet it can be broken down into views that could (and should) be used elsewhere. d. There appear to be a few redundancies to the query itself... but sometimes that's good in a query, performance wise. e. as mentioned, there are SQL injection issues in various parts of the query.
"SELECT TOP REPLACE_NUMBER_OF_ROWS_TO_RETRIEVE" " AND History.TRDateTime > 'REPLACE_WHERE_CLAUSE_CRITERIA' " even if there's no issue with injection with the software as written, the query plan is going to be generated every time the SQL is executed.
But there are some Possible benefits. a. you get all the data you need with a single transaction. Transactions are expensive. (not that you couldn't get the data you need in multiple queries within a single transaction, either, but that could potentially be more complicated. I'm not sure how SQL server handles locking tables for transactions in joins, but it seems to do pretty well in avoiding transactions where the locking order causes the whole transaction to fail. If you start handling that manually, you may potientially cause more transaction locking issues (but then again, you may be able to avoid them, too). b. as it is gotten within a single transaction, you can be certain the data is, to whatever transaction isolation level set, valid.
Also, you CAN index views, but regardless, if the views aren't indexed, the query plan generator would likely be doing the same thing with the views as with the original query.
Admin
btw, excellent username; can't stop laughing.
Admin
Sorry, I should have specified SQL Server... An assumption I made. Can't speak for Oracle, TerraData, etc.
Admin
To me TRWTF is anyone say this is done for optimization. How fast does reading the configuration file have to be? Most programs read it once at startup, put the results into some king of global var and then never tough the configuration file ever again. So how does it really matter how "fast" it is to read it from the database? How slow is 5-6 readable queries compared to this monster?
Admin
Your not too bright, are you?
Admin
Admin
It tried to perform an invalid INSERT INTO query.
Admin
That's assuming you were able to walk to the HR department under your own power, or you're not locked in the tape vault...
PS - I do realize you're trolling, I just wanted to throw in a BOFH reference.
CAPTCHA: genitus - how appropriate
Admin
Who's to say that this query isn't already using views?
Admin
True, however this leads to another WTF, and that is "where are the naming standards", which on a (very likely) 100+ table DB, it could get a little messy.
But like another poster said, this could be an intention "f-you" to all developers who have to maintain this beast.
captcha - uxor
Admin
Your manager doesn't just say "okay, when do you want it"?
Admin
Bloody hell, someone needs relax a bit. And, it's "you're not too bright". But you knew that.
Admin
If that runs, it is GENIUS.
Admin
I am always amazed that business managers will say "I MUST have real-time reports" but are unwilling to actually portion off the required budget to then set up even a basic OLAP data mart to do it, but have the audacity to whine like babies when the reports or other parts of a system take a huge amount of time to run because it has to query dozens of tables on a production system that is being used elsewhere.
Admin
FTFY.
Admin
Gotta gleam the cube, man!
Admin
Manager: What, you're telling me that I can't have a blazing fast enterprise application running on a massive relational database AND have real-time repoting of hugely complex reports for free?!?!?!?!
You're fired!
captcha: damnum - again, how appropriate (one more and it's a captcha hat-trick for me!)
Admin
This: I remember once having to write a type of "points" system that would limit the amount of reports a user can generate per (configurable timespan). They can generate 50 "easy" reports before hitting their limit, but if they generate, for example, a massive year end report, then they won't be able to generate another for an hour/day/whatever.
This had the nice side-effect of forcing the business user to actually THINK about what they want before just asking for 200k records, which they would dump to excel and promptly never look at again.
captcha: genitus... HAT-TRICK! woo hoo!
Admin
Gigantic SQL query aside, I can see two problems:
1- It's not escaped, there are loose (no, I don't mean lose) ampersands in there! 2- Why is the query an attribute and not the content of the tag? I.e.,
as opposed to
But of course, TRWTF is SQL (or was it XML? I can never remember).
Admin
Indexing a computed column isn't so bad, but setting up the indexed view in SQL Server is so tricky on any substantial database that it's fairly accurate to say the indexed view is "not supported"
Admin
Admin
Thanks, that's what I actually meant but I forgot the exact details since it was 4-5 years since I came across this issue. I can recall many rediculous limitations, and ending up abandoning it altogether.
Admin
The complex replacements seem to be replacing the hyphen twice. When I see this I must suspect that another character was meant, and thus the code is not eliminating everything that the programmer expects it to.
-Harrow.
Admin
+1 for wrist guards and pool copers
Admin
I suspect you are wrong. There are two different hyphen characters, but not all character sets support both, so the second one got converted to the first in the process of moving from the code editor to the web page.
Admin
Admin
Admin
It's Great Sqlthulhu!
Admin
Worked with that product for a few years. We all miss the old RAIMA database !!!
hehehe
Admin
I don't get what this code is supposed to do. My best guess is that it tries to delete all of human history?
Admin
Neither are you. It would actually be battery, not assault. And then you could have made the pun yourself.
Admin
thats what she sad
Admin
Why would she be sad about that?
Admin
Admin
I'm afraid I owe dgvid an apology; I had registry values (which can be up to 1 MB) confused with registry key names (which are limited to 255 characters). There's no reason* this couldn't go in the registry.
Oops.
*Aside from the fact that it shouldn't exist in the first place, of course. And the bit of the documentation where it says long registry values should go in files instead.
Admin
I've seen and worked with a lot worse! Some queries were stretching to just over 12,000 lines. Yes, OVER TWELVE THOUSAND! I've also fixed shitloads of bugs in these monsters and cut some of them in nearly half.
Admin
You are right in your wishful thinking. However, I see queries like that quite often.
Be sure to NEVER EVER refactor such a thing. Generally, nobody remembers old business rules and why they were there. "Documentation? Which documentation? We have one which is nearly up to date. Just "some" changes are not there. You'll have to find out which." So, they are just left in place. Refactoring impossible. If you do you will have to take the responsibility when the business people notice that the results are different from what they were before. And if you tell them at that moment that YOU made this change I don't want to be in your shoes.
So don't change a hi-tech 16 valves 4 cylinder engine into a spinning wheel just because it makes a car run, too. You won't get very far.
But I agree that it is difficult understand what exactly this thing is really producing. And when you imagine that the entire query is maybe only executed to retrieve a list of ID_FAX_LOGs (the rest is not used but you never know, so leave it) in order to produce a different report...
Admin
You mean like:
Is that so hard? To someone who writes SQL once a year perhaps, but to someone who does this for a living?
There are some limitations, like that you can't use aggregates, which I guess has to do with some difficulty in knowing which rows should be updated when rows in the underlying tables (or views) get updated. (It doesn't seem too hard to me, but I've never written a RDBMS so I really can't say.) Or maybe that feature just didn't seem important enough.
Admin
| | v ^ TRWTF is
Admin
sry
Admin
Huh?
captcha: eros
Admin
Vegeta, what's the Analyzer say about the lines of code?
IT'S OVER TWELVE THOUSAAAAND punches computer
Admin
Speaking from experience, it's more fun when the original report was outright wrong and performed incorrect calculations, and you're told to change the new one back to give bad results so it matches the old reports.
Admin
TRWTF is the database not supporting regular expressions and forcing crap like this
Admin
Admin
My boss did that with a feature once. Demanded repeatedly to know why it had been taken out or, if broken accidentally, why the testers hadn't noticed that it had broken. The answer, of course, was that it had never been implemented. In fact, no one but him could even remember it being asked for or mentioned before.
Admin
amischiefr, I'd like you to meet Little Bobby Drop Tables, Bobby, I'd like you to meet amischiefr. I'm sure you'll be seeing a lot of each other.
Admin