- 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
1.) Acquaint oneself with database 2.) ?????????? 1000000.) Profit!
Admin
I think Paula is correct...it's just about profit...
Mobocracy
Admin
Is is just me, or are WAY to many WTF's related to SQL. It seems that SQL is just about the biggest WTF there ever was. It is Sooo easy to get wrong (and get a "reasonable" result) that I suspect that we should all go back to first principles and say that databases are a general WTF, and let it go at that. Of course, the little "database" that I implemented in high school (back in the 60's) was done in Fortran, but that is another story.
Admin
Time for the mandatory mock the Microsoft user comment...
Get yourself a proper database! Oracle and IBM DB2 both support indexes on functions or expressions so this could happily be an indexed query.
Admin
Great idea! My next foreign key relationships will be fractal functions.
Admin
If any one on this thread thinks that it is a good idea to do what this article discribes....then do us that will be fixing your code in the future a favor , and swallow a bullet and get out of the business...
Mobocracy
Admin
To anyone who doesn't find the typo objectionable:
This isn't some artsy blog where you can say precision doesn't matter. This is a technology blog, and it's read by programmers. If you make that kind of mistake in your code, you're gonna find yourself with serious problems. It's natural for us to expect a higher standard here.
And c'mon, it's not like this was a long article and the two numbers were separated by lots of space. They're essentially right next to each other. He could have copied and pasted and then added commas.
I realize this seems like a stupid thing to get worked up over, but these kinds of typos are far too common here to just let slide.
Admin
All you perfectionists out there:
All you need to do is reward Alex on mistake-free days by visiting all his sponsors' links, and withhold your clicks when you see mistakes.
Or stop complaining.
Anything else is hypocritical.
Admin
In all online discussion forums, the size and virulence of the arguments is inversely proportional to the importance of the subject under discussion.
Admin
Win!
Admin
Admin
I mean... one typo per set of brackets - that's an appalling error rate. Maybe you need an Editor?
Admin
you guys are so anal.
Admin
I always kind of assumed that if you do things right, Sql Serevr will work ok (using indexes and such) and if you just hack your way to the data, it'll be slow. This is confirmation. And btw, you can also force an index in sql... I was speaking of the automatic precached type.
Disclaimer: I just read that and it sounded too violent. Not the intention at all, but I don't know how to rephrase it to make it milder.
Admin
Moreover, when referring to Muphry's Law, I SHOULD have made the typoes myself to be fun. My bad english have more spirit and humour than I have. It's fucking hilarious.
Admin
Or in Sql Server just make a computed column of the calculated value (o.ShipToCustomerId / 1000000), index that column and then join on an actual column rather than a formula.
Admin
Any responsible developer will provide access methods to pick the two apart.
-Harrow.
Admin
"Just because I can't (or don't want to) do X doesn't mean I can't see the problems when somebody else does X. And if you don't like this comment, let's see you do better."
FTFY ;-)
captcha: nibh (National Institutes for Bodily Health, I presume)
Admin
Admin
It probably isn't that slow. With code like that running their information systems they probably don't have many customers/
Admin
That's "soitenly". "Cointently" is when 2 people are intent on the same thing at the same time. Also, Nyuck is the old Soviet Union-style spelling. Preferred, today, is "nyuk".
Admin
"I'm Sorry, your company must have less than '1000000' customers. Please delete a customer account and try again."
Admin
Admin
There are WAY too many WTFs related to many programming languages.
No. It is not a perfect language, but it isn't a terrible one for what it is (a language to query relations out of a RDBMs). It is people who use it ways not intended for it, or that are oblivious to the basics of SQL and relational database theory (which should be part of any undergrad CS/MIS curriculum) that are to blame, not the language.
This would be akin to blaming Java or C# or whatever for the WTFs that inept programmers code with them.
In this particular example (a WHERE clause based on comparing one id against a mathematical expression of another id is a programming WTF, not a SQL one.
Imagine the following construct in your favorite language:
No matter the language of your choosing, the WTF is on the programmer, not the language. This example WTF is orthogonal to the SQL example.
If by "reasonable" result you mean just the data, then you are partially right. And I say partially because there are well-known methods to make sure such things never happen. But the truth of the matter is that what matters is not just the result, but the performance and maintainability of the system that spits out the result, and the ease by which you can have confidence that the result is correct in the first place.
I'd say that, without knowing anything about the submitted WTF, if that is only one instance, it's something we can stomach. But if that is the general pattern across the system, it is a major brain fart. My experience has been that people who commit those errors all over the place simply don't how to use a RDBMS and have never put an ounce of effort in picking up a book on SQL. They are usually the same people who create tables with fields named temp1, temp2 and temp3 where they throw everything and the kitchen sink. And that's simply the SQL equivalent of unstructured programming. In this time and age, the blame falls squarely on the programmer.
And what kind of first principles are we speaking off? What alternatives do you see today over RDBMS for systems and enterprises? Yes, we could go NoSQL or fall back to the older models (network and hierarchical.)
But I could bet one of my balls that the same type people who commit such SQL WTFery would create equivalent monstrosities in any DB model you can think off. The onus still falls squarely on the programmer.
Admin
Admin
This is great. I thought the legacy SQL in the code base I've been maintaining was bad. Now I know it could be at least 1000 times worse.
Admin
Don't be a Cherkov (Soviet Union spelling retained).
Admin
Admin
The Cold War is over due to Global Warming - but the spelling endures
Admin
or to catch the pedents.
Admin
Admin
Catch me if you can
Admin
Admin
Perhaps because a) most of the site's followers understand it b) posting lots of SQL wtf's drags a bigger SQL crowd, posting new SQL wtf's c) many other wtf-y places are so laden with NDAs that you don't dare post them d) the editor doesn't understand some other wtfs and they never get posted
Personally, I skip most of the code wtfs these days; the best ones recently have been the job interview stories..
Admin
Wow.... So you think that's OK do you??
Admin
The real wtf here is people trying to -even remotely- justify this monstrosity...
Admin
I know! Fully agree... I thought the DailyWTF audience was supposed to be developers who actually had a clue, but judging by some of the comments lately it seems that the people on here are very similar to the people who produce the WTF's!!!!
Admin
Dude I think you should check out the editors website... I think Alex understands more than you seem to think....
Admin
Admin
Thinking that this crowd of ORM loving devs could recognize a database design issue is going a bit far. Seriously nobody has even brought up the horrible queryplan this where clause will generate? "Indexes Schmindexes..."
Admin
I smell an Oracle Douche...
Admin
People still say this?
How lame.
Admin
Aaah, ChickenPox++... Memories...
Admin
Oh come on, you can easily write a SQL query to select all transactions for a single customer without having to resort to division in the query statement...
SELECT * FROM table WHERE ShipToCustomerId IN (1000000,1000001,1000002,1000003, .... 1999999);
Admin
Oh my. The WTFs in this comment thread are more plentiful and sometimes even bigger than that of the article.
Admin
Your original and superior comment is a breath of fresh air.
Admin
You know sometimes we have to put some fun in our job ... so maybe he tried to make a good joke to his future co-worker.
It's way funnier than your boss who works in IT since 20 years and tells you "I create private function so they don't appear in intellisense"
Admin
Did the developer responsible also write the custom "database synchronization" algorithm used in one of our records management products?
That system distinguishes "locally-added records" from "records in the master database" by using ID's greater than or equal to 1000 for the local records, and ID's less than 1000 for records that were already on the server. During the synchronization process, the local records with ID's >= 1000 are INSERT'ed into the master database, and UPDATE statements are generated for the ones below 1000. Of course, such nonsense with the ID numbers is fine as long as you hide the evidence, so the last step in the process "re-sequences" all those pesky >= 1000 ID numbers so that they all start from 1 again in the master database.
All that was only for ID's generated by the program (which were supposed to represent sequence numbers in collections of related records, i.e. Person -> Person Allergies -> Allergy 1, Allergy 2, Allgery 3).
For auto-generated identity columns (mostly primary keys), the software reconfigures the Access database at start-up to auto-increment backwards, so that it could later tell which records were added locally and which ones were already in the master database by checking the sign of the primary key value.
Clearly, though, more zeros is superior and I would much happier with this system if it used 1,000,000.
Admin
Admin
jrh,
"But why do otherwise decent developers throw out good practice when they get to the database?"
I don't, I've just seen a fair number of systems with different requirements. And my contention wasn't that this was "good practice," just that it wasn't "sick" or worthy of a WTF.
"Would you have a class where the CustomerID and the OrderID are stored in the same property and leave it up to the class user to pick the two apart?"
Trick question. A table or, more properly relational variable, stores a set of propositions with a common predicate, and the state of the table (the assigned relational value) constitutes a true statement about the world. A class is a common set of methods for a set of objects that have no particular meaning, though the definition of a class is highly dependent on the vagaries of your style of OOP.
The two are, logically, completely unrelated and anyone who tries to map tables to classes ought to punch themselves in the face. Though, the fact that they're already creating a ton of useless work by recreating the DBMS, poorly, might be punishment itself.
"If you have a compound key you, you need to either use a compound key or a surrogate key."
I wouldn't just load two values into a single column like that for the hell of it, I'm assuming the person had some requirement that it be stored like that. Usually that requirement is someone else's design decision.
Once you've designed a schema one way, it can be expensive to change it, so I wouldn't be surprised to see a mildly problematic design like this persist for a long time.
"As for your theory that it's not "so awful to load two number into one by means of simple arithmetic", well I guess that's true as long as you don't need your database to scale in any way."
Okay, show me how this will prevent scaling the number of concurrent users. You did say "any" way.
I already suggested how it will be hard to scale: "It's generally a bad idea to store two values as one, since it makes them unavailable to relational operators." To expand on that, you lose declarative integrity through foreign key constraints, and you'll have to babysit the optimizer with, e.g. function-based indexes, partitioning and such.