- 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
How about 1,000,000? It that OK?
Admin
0.000001st
Admin
At first glance it may seem sick, but it's possible that the application code has a relationship where thing2.id = thing1.id * 1000000 (semi-analgous to dates stored like: year10000+month100+day), and so they propagated that into the db relationships instead of mapping it properly.
I'm not saying it's a good thing to do, but I've seen it done.
Admin
I feel like my brain just exploded into 1,000,000 pieces.
Admin
Looks to me like they use order IDs on the form XXXXXXYYYYYY where XXXXXX is the customer ID and YYYYYY is a squence number. Yes, it could have made sense to split this up into two columns in the database, but this method works just as fine for finding orders for a customer.
Admin
It's generally a bad idea to store two values as one, since it makes them unavailable to relational operators. But, really, SQL itself is such a mess that the right way of doing things becomes a hassle.
And the reality is that many identifiers (phone numbers, SSNs, VINs, MAC addresses) are really composites of smaller identifiers, so you're often stuck.
Keep in mind that in SQL, to join on a compound key requires the following every time you join:
FROM A INNER JOIN B ON A.col1 = B.col1 and A.col2 = B.col2
(Yes, you can use NATURAL JOIN iff the column names match.)
It's not all that bad, but a lot of people do avoid it, and some other tasks become a little more complicated. So normally you wind up with surrogate keys all over the place and your system is littered with useless, unreadable surrogate IDs. In this case, I don't think it's so awful to load two numbers into one by means of simple arithmetic.
Admin
Autoincrement by whole numbers is for chumps. I want my ID incrementing by 0.0000001!
For my next table, it's going to increment by number of sunday's since the epoch.
Admin
Admin
And before anyone blames this on the submitter, how do you know that the original submission had the error? Besides, an editor is supposed to catch stuff like this. AKA TRWTF.
Admin
Admin
The requirements were "All ShipToCustomerIds must be evenly divisible by 1000000." They're just saving space in the database!
Admin
Not only sick, also slow. That query doesn't use indexes and in the case of Sql Server you will have to recompile stored procedures on each use because of that.
Admin
I did something like this a few month ago : I needed some row to appear in a query but I didn't want to had a field to my table and my class to be able to distinct them from the others, so their ids begin at 10000 :)
It's like tetris,it's ugly but it's really fun.
Admin
Hey... if it works...! :D All is fair, in Love and SQL.
(Captcha: "dignissim", what I'd like to think is Jiddish for "dagnabbit".)
Admin
It's not sick, it's genius! Just multiply two integers together and store the result to save space!
Huh. I wonder why customer 3's second order is exactly the same as customer 2's third order?
Admin
The attitude that you can't criticize someone unless you can do better is senseless. I'm not an aeronautical engineer, but I can still see that someone whose airplane won't take off is doing it wrong. Similarly, I'm not a tech blogger, but I can see that Alex often makes errors that would be caught if he re-read his posts with a critical eye --- that is, he's doing it wrong.
Admin
ಠ_ಠ
Admin
Admin
QFT! I really hate the "yeah, let's see you do better" comeback. Steve Jobs pulled that on an iPad critic the other day and it's weak. Just because I can't (or don't want to) do X doesn't mean I can see the problems when somebody else does X. And if you don't like this comment, let's see you do better.
Admin
Ben, I'm going to give you the benefit of the doubt and assume you are a good developer outside of SQL.
But why do otherwise decent developers throw out good practice when they get to the database? 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? If you have a compound key you, you need to either use a compound key or a surrogate key.
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.
Admin
Well it's obvious that since everything gets stored as integers, we might as well encode all of our attributes into the integer ID column. Everything with ID greater than 1000000 has a customer associated with it, grouped by 1000000's (so, to make things convenient, 1000000-1999999 are associated with customer ID 1, 2000000-29999999 with customer ID 2, etc.). Then if the ID is divisible by 3 then it is the invoice for a sale, sale ID + 1 is a returned item, sale ID + 2 is reserved for special cases and extra storage if necessary. If the sum of the digits is 10, then it was a sale of a TV, sum = 11 is sale of camara, sum = 12 is the sale of a digital storage device, ... The quantity is encoded as the ID mod 200 (because nobody will ever need to buy more than 200 of anything)
This way we can save storage by reducing the columns that we need to store and just using carefully constructed IDs.
"I'm sorry, but our invoicing system is unable to determine an appropriate ID for your order. Do you want to:
Captcha: iusto - I iusto rite gud cood, entil I startd wreeding TDWTF.
Admin
Ouch.
And what about SQL Server's Unique Identifier type? Try porting that logic over to any other database... :P
Admin
Admin
Why not divide by 1.21 gigawatts for a time machine?
Admin
Admin
Or Alex could be intentionally leaving in the typos just to drive the Grammar Nazis insane.
Admin
Admin
Well, if the plane doesn't fly, even with no knowledge of aeronautics, I think it's fair to say they're doing it wrong. A plane is supposed to fly or it's not a plane. A plane that can't fly can rightly be criticized. You'd have a point if it's not that it can't fly at all, but that it can't fly in this particular set of conditions (say a volcanic cloud of ash hovering overhead). It's not the best example, but let's see you do better!
A better example would be to say that you can't criticize Uwe Boll movie unless you've made your own big budget movie based on a video game and inexplicably managed to get big name stars to sign up for it. Therefore, nobody's allowed to say Alone in the Dark was total shit. Another example would be, you can't criticize the president unless you've been president of the US.
Admin
Admin
Remember that the next time you watch a sporting event. Thinking of that... why do we have coaches at all? They're not any better than the players; how could they possibly tell a player that they're doing it wrong.
Admin
Or Alex is merely human and thus prone to mistakes, like the rest of us. You don't call that TRWTF.
Admin
Amateur. My single table database can store anything and has its customer records on a modulus of 17.
Admin
Admin
It is times like this that I wish I had a machinegun.
Admin
The same concept can be applied to this site. We understand the basic premises of running a website/blog and of the English language and are therefore able to see that it is indeed "done wrong."
Further, even if the "do it better" argument was valid, I think that by submitting corrections the users are, in fact, doing it better. The complaint is not about the site, its design, or its content. It is about the grammar and spelling of the articles, everything else is secondary to this debate/argument.
(Note: That being said, I am not a grammar nazi. I generally just ignore any mistakes I see. However, I am a logic nerd and will freely point out glaring errors in applying basic logical reasoning to a situation that I come across.)
Admin
No, everybody, please, continue to comment on things that you don't understand. You add to the entertainment value of this site.
Admin
You kid, but I've worked with something like this.
My second job was at a medical software company (1991 or so). The frequently-used database tables were optimized around the limitations of the programming language/database (which originated in the late 60's or early 70's and whose name is synonymous with a childhood disease) and the disk storage system.
I remember one table specifically - it was a data dictionary, and the original programmers (also in the early 70's, I believe) had determined that storing the primary key (DE, for Dictionary Entry) as two values - DE DIV 23 and DE MOD 23 - would provide the most efficient access.
When I got there, the technology had progressed far beyond needing such things, but like most legacy systems, it hadn't been changed.
Admin
Unless God's goal is to prevent that particular airplane from taking off, in which case:
Admin
And I'll get out on a limb here, but I think incorrectly copying a number in a humorous story is somewhat less important in the grand scheme of things than an airplane falling out of the sky and killing all the passengers on board. Perhaps Alex doesn't care very much about an occasional grammar error or typo because he does not suffer from obsessive-compulsive disorder.
Admin
1.21 gigawatts? The only thing that can produce 1.21 gigawatts is a bolt of lightning! I hope you've got a really good surge protector on your server.
Admin
A millionth of a customer is still a customer. Just a very small one.
(I never do this but, well..) Captcha: aptent - a poorly constructed application server.
Admin
Admin
Cointently! Nyuck Nyuck!
Admin
I can't believe you idiots spend this much time arguing over typos. This is ridiculous. Typos are not "the real WTF", "the real WTF" is that anyone gives a shit. It's a blog, not his job, it doesn't have to be perfect. Stop wasting your time and ours.
Admin
How are they going to have a big party for the millionth customer? Sorry, you would have been the millionth customer, but we overflowed your id back to zero, so the original customer zero is receiving your order and your prize.
P.S. Customer 0 is the special back door customer id that gives you administrative privileges on the site. Planned rather well I would say...
Admin
Admin
I really don't think this is in WTF territory (it isn't good, but I have encountered reasons to do so [curse the stupid middle-tier]). It is obvious that the db requires each table to have non-composite primary key. This is probably because of the limitation imposed by the middle-tier. If the business requirement states that a single "cui" can never have more than 1 million distinct "ShipToCustomer" (i.e. 1000 addresses), then this is one way of skinning the problem. [Yes, I did say it's not ideal as you can use a segregate key in a associate table, this will eliminate a table.]
co is obviously the Company table, and cu is the Customer table. I guess cui is "ShipToCustomer" which is CustomerAddress table.
I have seen "object-oriented db" design (i.e. 1 lookup table). I have seen "design" with duplicate facts across 3 dbs and 2 servers, handling 200 orders and require 200GB DASD. This is no way in the level of WTF.
Admin
Admin
I want to meet the consultant that programmed this.
Admin
maybe I needing later