- 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
Because your app will have to take care of the errors that arise when the integrity is being violated. In any good app, you will add code to check that integrity is not being violated in the first place, rather than relying on obscure SQL error messages that will more often than not tell you that something went wrong but not what, let alone what you must do to avoid the problem.
Database integrity rules should be the absolutely last safety net, and you shouldn't rely on them for the correct functioning of your app.
Admin
I was going to be witty and say "Yeah, because everyone knows that we will never have/need more than 10 levels of hierarchy" or "10 levels of hierarchy are enough for everybody". But then I realized that an organization having a hierarchy more than frigging 10 levels deep probably has worst problems than its database scheme :(
Admin
OH MY GOD!
this is, IMHO, The Real WTF (TM)!!
you sir, should not be allowed anywhere near a database!!
Admin
holy crap!
thats the real wtf, right there!
CAPTCHA: clueless, do i need to say more??
Admin
@pid is a parameter and contains a single value
Admin
Wow - this-one stunned me for a moment, this has to be an even bigger wtf than the original article...
I really wonder why using a database at all if you think like that... Flat files all the way then! Or maybe XML? :P
Admin
WRONG
The WTF here is that the DBA, me, tried for several weeks to help the developer, a contractor who was hired to write a complete application -- database and all, and still wound up stratching his head every day. The two examples posted in the WTF entry are near the end of the project when I just couldn't take it any more. You can only push on a rope for so long before realizing it isn't moving the object at the other end. Here are some of the more memorable quotes from the developer:
"T-SQL doesn't have an IF statement" (I told him it did and that the SQL Books Online explained it very well)
"I don't know much about SQL" (I did not ask WTF he was developing a database app, then)
"I don't know how to use ISNULL. Can you send me an example?" (I did. It took three more releases before he used it)
"Why is putting the entire update process and all of the logging for the updates in a single transaction a bad thing?" (We had to explain that a problem with the last record in the import could cause the entire import and all of the associated logging telling us where the problem is to be rolled back. He got upset that we didn't tell him how we wanted the import to work.)
"This table shouldn't need indexes"
The REAL WTF (tm) IMHO is that a .NET developer who admits he doesn't know much SQL would still try to develop a .NET/SQL application without seeking the guidance of a SQL expert.
Admin
The varchar isn't wasting resources.
It's allowing for the possibility of unexplected errors or truncation when you have multiple varchar(8000) in one table.
At least in MS SQL the storage limit for one row of data is just over 8000 bytes (unless the evil text or image datatype is used).
Admin
Are you nuts? Data integrity belongs in the database, where it can be set up once and used by everything that accesses the data. It should not be left up to the application to implement (or not) at the developer's whim.
Putting it in the database means that integrity is consistently enforced. Leaving it up to the app makes it hit or miss.
Admin
I once had to rerun an update procedure whose cursor-based routine to transform some imported data took so long to run that during the run I had to write a query to show me what % of the progress had completed thus far. It took about 90 minutes to run...every day.
Basically it stepped through each product in the table, checked its code in a monstrous switch statement, then updated that specifc product's product line.
I replaced it with a half-dozen statements of the form UPDATE [Products] set ProductLine = 'Foo' Where ProductCode in ('Foo1', FooTwo','Foo Accessories')
Unfortunately it only runs 180 times faster than the cursor method (30 seconds).
Admin
The thing is, that's the attitude of EVERY major application vendor- even PeopleSoft and Siebel (both owned by Oracle). They do tell you its OK to leave foreign keys in development environments, so you can verify the app is really keeping an eye on things, but, to speed up production, they'll tell you to get rid of them.
That attitude has always baffled me; I agree with posters who wonder why you should be using an RDBMS if you're not going to actually use it. And, what's really funny is, these companies go to the trouble to make versions compatible with all the major RDBMSs, and then, go and basically turn off the fucking things. Why don't they just use their own serialization scheme, if they're going to do that?
Admin
Yeah, you rock.
Now, it seems like there's a user who needs his password reset, so get back to work!
Admin
You are absolutely correct, sir! Key fields, both primary and foreign, are for optimization only according to the inventor of the RDBMS (E. F. Codd). The only necessary constraint is that there be no duplicate rows, according to Codd. Key fields can notionally subvert this constraint. Of course, as a practical matter, a complex database with no keys and no duplicate rows in child tables (absent the keys) will probably be unusable in real time for anything except as a write-only repository. As you point out, appropriate design requires analysis of the data and the uses to which it will be put before implementation. This argues for at least some rudimentary knowledge of data design principals on the part of programmers who have to deal with stored data.
Admin
You so need to get your hands on his code... I'm guessing he wasn't much of a .Net developer either and an archeological dig in his code would reveal many a WTF for future posts.
Admin
Perhaps, but I looked at it this way:
1. Removing the GROUP BY saved a little time because it isn't needed. The results are identical whether it is used or not
2. ISNULL is faster than CASE in that CASE must completely evaluate the subquery each time. ISNULL on the other hand will stop being evaluated (though the subquery will continue) as soon as the value of the subquery is no longer null
3. The original CASE statement ran the entire subquery twice: once to see if the value was null and return 0, once to return the value if it isn't null. This is just waste.
Admin
I'm no expert in .NET so I won't go poking around there and wouldn't dare criticize him for a topic I know little about myself.
However, there were some parts of his code I did see (huge multiple-line dynamic SQL constructors) that I would have done a different way...say, using a parameterized stored procedure instead of dynamic SQL.
Admin
You sir, are correct.
And you can see them both in the season premier of BSG tonight at 9 on Sci Fi, just like it says in the ad.
As the kids are so fond of saying these days, "rrowl."
Admin
The real WTF: SQL Server, try using a real database.
Admin
Too true, Too true. If this was 1980 and you were developing on a mainframe. Indexes are usually necessary for large tables? I'd say that they're always necessary for large tables. If perhaps you want to get data back at some point. You might find that perhaps it's not the overhead of the keys that are causing you slowdowns, but the lack of any indexes. Learn to use explain. Use a primary key. You'll be amazed at the speedup.
Admin
Ah, a developer willing to learn. They make the job worth while.
I don't see the WTF here though. This describes most of my DBA interactions. As a contractor, as soon as I train one set of duhvelopers to developers I have to leave to work with another set of duhvelopers
And I agree that many DBA's are brainless twits. That is a good thing (for me at least)
Captcha: bedtime, already?
Admin
You're one of those condescending DB2 users, aren't you? :)
Admin
You know, it's funny. You think many DBA's are brainless twits...I think many developers are brainless twits.
We are probably both right
Then again, I've also met some DBAs who I think are brainless twits and no doubt I've met some DBAs and developers who think I am.
Twittery is in the eye of the beholder.
yo no soy "brainless twit"
Admin
I second that emotion!
Admin
Admin
Maybe a stored proc... but at the very least he should be using a parameterized query. If it's actually string concating, then I do smell some wonderful WTF'ery in the works on the code side.
Admin
In J.T.'s organization, it's the responsibility of the developer to understand SQL and databases well enough to create tables, understand keys and data types in the database and optimize queries. It's apparently the responsibility of the DBA to mock the developers.
My solution? Fire both Frank AND J.T. and get a competent development staff that doesn't include DBAs.
Admin
A developer willing to learn? From the cadence of the original post, I'd say the developer was an arrogant, over-inflated moron. If the post describes most of your DBA interactions, then you should re-evaluate the one constant in all of those relationships.
Admin
Hoo boy! WIth a 'philosophy' like that, I'd hate to have to maintain the crap you develop.
Are you related to Paula?
Admin
"P.P.S. Hmm BSG girls. And both of these were cylons. Kinda like an everyready girlfriend. She just keeps... oh sorry wrong blog."
< roflol > nice! < roflol />
Admin
What! I do believe FileMaker forces the implementation of indexes and primary keys if any relationships are defined.
I have moved on from that little system. I think it's a fine system nonetheless.
Admin
Frankly, regarding database architecture, there is just too much to know. Your average client-side developer is a specialist in what he does. You need a specialist in databases as well. Unless you're just building mom & pop web apps.
Admin
Care to post some of your own data designs so we can see just how well that works?
Oh, and do you manage the database servers too?
Gee, I'd hate to be your boss. I mean, I'd have to pay you a MFT of money to do all that work and then, I'd be scared shitless you'd be hit by a truck. What's more: No one could ever criticize your code because you'd have complete control over it from one end to the other. That's just not good practice in any business transaction; accounting, HR, sales or development. If one person does everything from one end of a project to the other you're going to have a very one-dimensional outcome.
<ahem>
Now to respond to your weak point: If a company hires a developer to write a .NET web-based application with a SQL backend then it is the responsibiltiy of that developer to either know the SQL needed to do his job or to ask for assistance when needed if they don't. This developer did not do the first and did little of the second.
Admin
Nope, just a condescending Oracle developer! :)
Admin
A village is missing their idiot, I think I have found him!
Admin
Admin
The "app will maintain data integrity" thing comes from MySQL. MySQL's MYISAM tables (the default kind) do not support foreign keys . If you try to create one, it accepts and silently ignores the request. These same tables do not support transactions; if you do this:
BEGIN TRANSACTION
DELETE FROM MyTable
ROLLBACK
That DELETE statement actually operated outside of the transaction. Not that you get any indicator to this effect -- no warning or anything.
Admin
keys are bad? WTF??? Mod this comment down as troll!
Admin
This is the WTF for me in the whole story. As much of a know-it-all DBA nazi J.T. has been up to this point (not a bad thing mind you), optimizing queries *should* have been his domain. Frank's responsibility at this point should have been limiting to informing J.T. what he's trying to get out of the query, and J.T. should have provided that for him. Not to mention, there should have been some discussion between the 2, with J.T. designing the table based on the input from Frank. Namely, Frank shouldn't be determining the indices to be used for the tables (and in some cases, not even the specific type, though he should be providing useful clues to help J.T. determine the best data types to use).
Admin
That is why people who "learn" sql by using MySql should be kept away from the keyboard.
Admin
Ahem... Some of us PHP-tards know how to build proper databases... Even some of the self-taught ones. Personally, I take quite a bit of pride in what I create.
Admin
Admin
If we worked together on the project, you'd be right. 100%.
However, Frank was a developer who worked for a vendor whose job it was to deliver a complete product including the database.
My job is to protect the database environment from bad code. I was not consulted during the design or development of the application. I only came across the inefficiencies after the application was near go-live.
Admin
Let me add to that. The reason I looked at the SQL code in the first place was because the application, under load, was timing out because the query was taking too long when performed by a few hundred users at the same time. We eventually came up with a totally different way of solving the problem that was my idea and the developer's implementation. So, we did eventually work together to make the end result better.
Admin
"It was a small, 3800% decrease."
So how do you decrease something by more than 100%? That's quite a trick to have it complete before you start running it!
Admin
Because it makes debugging your application something close to beiong possible?
Admin
"Wait a minute, you mean there is a company out there with a real DBA that has enough power to actually enforce the rules? " [snip]
Can I work there?
Admin
I actually see this as part of the source of many software failures. Regardless of how pointless the developer thinks the data is, the client may think of it as the most important thing in the world. It doesn't matter if the client is a huge multi-million dollar conglomerate or the mom and pop store down the street, thier data is thier businesses life blood. They each need to know exactly how much thier sales were each day, what the value of each transaction was, or the name of thier outside contacts. The actual dollar amount doesn't matter here. Even the local comic book collector with his stuff in boxes in the basment thinks this data is important enough to save, and the reliability of the data is highly important to him.
So yes, every application needs this type of reliability guaruntee.
Admin
OMFG!
Just stay the f*ck away from ANY database ever created... for the rest of your natural LIFE!!!
(>_O)
please... for the sake of humanity...
stay away!
*...runs away from the reality distortion field being generated by this WTF of WTF's!!!...*
Admin
Ah, well that makes a whole lot more sense. The story didn't bring that point across. And, given that, I'd agree with your position.
Admin
Ah. DBAs. The most underappreciated overworked people in the world. . .
For the competent developer, there's NOTHING better than a competent DBA.
For the competent developer, there's NOTHING worse than an incompetent DBA.
For the incompetent developer, there's NOTHING worse than a competent DBA.
And when you combine an incompetent developer with an incompetent DBA you end up wreaking havoc that shall plague the world until the end of time.
** Martin