- 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
I'd be more worried about exposing UserIDs to the end user.
Admin
Quite.
Admin
This requires updating all the foreign keys during the merge.
Admin
Still less work than pointlessly maintaining GUIDs when you're not merging.
Admin
GUIDs are lousy in indexes though.
Admin
GUIDo ninjas NOT wanted!
[GU]UIDs might be OK as keys in small tables, but will bloat indexes on bigger tables.
A competent developer who spends 2~4 weeks studying query planning, normalization and indexes will usually make a better DBA than most DBAs.
Admin
Arrgh... Once again mixing DBA [ADMINISTRATOR] with a Database DEVELOPER.... two different roles....and both completely distinct from C#/VB/C++/et.al. Developers....
Admin
Anyone want to ELI5 what the hell this is even trying to do?
Admin
If this is MS SQL, then all they need to do is return @@IDENTITY.
Assuming the table has an Identity column, which if it doesn't, it should..
http://technet.microsoft.com/en-us/library/ms187342.aspx
Admin
It's a function that's trying to return the next integer higher than the max of the named column. All the rest is guesswork, but it's likely this is being used to insert a new record. Obviously, the correct approach is to simply replace this function with an auto-incrementing index on the table. Then if you need to retrieve the index of the record just inserted (which is NOT what the code does), then you may employ SCOPE_IDENTITY or OUTPUT, as noted.
Admin
Admin
What does a DBA actually do? Most the ones I've had the unfortunate experience of meeting were idiotic pencil pushing monkeys.
Admin
Admin
Something something monkey something football.
Admin
When in doubt just throw feces
Admin
argh... Giving developers a bad name, cmon now! A number of us pride ourselves on predominantly working VERY close to the database (or solely in the database) and would shudder to see such code.
Admin
For those unfamiliar with what Marle was suggesting and why.
Having the UserLoginName as an identity field means you can't (usually) specify it during the insert, it is automatically assigned a (max + increment) value preventing race conditions.
SCOPE_IDENTITY then retrieves the UserLoginName of the record you have just created for output.
@@IDENTITY is not used because if the table has a trigger that does an insert to another table with an identity field the other table's created identity would be returned.
Admin
The DBA should have fixed this by declaring an index on the UserLoginName column. No code changes necessary.
Also, someone should point out to Merle that they are using Firebird and therefore there's no such thing as SCOPE_IDENTITY().
Admin
Triggers are forbidden in most large databases (that I came across, at least), along with CLR functions... Just based on experience it could lead to very huge problems.
Admin
Wait a minute, didn't $i just say that last week? Come to think of it, how did $i wait a minute? Was $i awakened by another identity performing faster tham me?
Admin
Admin
Me 2
Admin
Luddites!
Admin
That still does not make it anything near correct, leaving a central WTF in place. The only correct way to do something like this is to let the only instance make the ID incrementation that can do it, and that is the DB itself during the INSERT.
Therefore the pattern is indeed: use an auto-incremented ID column (the concept exists in virtually every DB, even MySQL), just do the frickin' INSERT already and ask the database afterwards to get the ID it generated for you. I learned that pattern when I did my very first PHP-based web site ages ago. No wonder current Software has to many problems with concurrency when apparently developers have no idea what they are doing.
About the GUID vs. integer ID thing: GUIDs have their uses. As soon as you are dealing with distributed data, you are in trouble when using just integer IDs. So, it depends: are you looking for a local ID or does it have to be globally unique (sic)? GUIDs exist for a reason.
Admin
Joking apart, there is a general understanding between developers and DBAs that programming (stored procedures and such) is largely the domain of the developers, and when it comes to things like optimisation and keeping the damn thing running in the first place, that's where the DBAs have the expertise.
Also, the phrase "developers" is used very loosely by Marle. Some people develop cancer; that doesn't make them developers, not even if they develop the programmatic equivalent of cancer.
Admin
FTFY. I'm an ass!
Admin
MAX()+1 was bad back in the days when you had to work without triggers or autoincrement columns. It's even worse now.
As I recall my preferred workaround was to add one to a column in a nextid table, then select the result, then insert into the desired table, then commit, as this would at least ensure that two clients couldn't retrieve the same id. (There was of course contention for ids for otherwise unrelated tables but that was the least of their problems.)
Admin
Depends on the purpose of the DB.
For example, if you know your dataset is limited (the amount of active customers for a local homebuilder), it's better not to normalize the data.
I've seen DBAs normalize to save space, and put the address into a separate table.
Some of our customers live in the same address, why duplicate that data?
But then, one person at that address moves and the other doesn't. How do you update the address?
Obviously you could create a new instance, but then if your UI can't do that, then your fried.
So, yeah, I'm beginning to learn that the traditional solutions employed by DBAs doesn't work for all needs.
Admin
TRWTF is stored procedures, period.
Admin
TRWTF is stored procedures, period.
Admin
To the contrary, this firebirdsql.org page strongly suggests the opposite!
The SQL syntax shown in the article is MS-SQL, not Firebird.
Admin
Not WTF here. Person unsure about SQL, but good enough to actually know some of the syntax attempts a fix and submits it for review.
Fix is reviewed and found wanting. Note providing direction sent back.
Looks good to me. Maybe the RealWTF is simply that they actually did a code review at all?
Admin
If my wife and I enter the same address into a system, the text values may be the same, but the system better treat them as two different addresses, because that's what they are, even if they're currently equal to each other.
Admin
Again:
Luddites!
Admin
It's a fairly basic WTF, but it's still a WTF. As I mentioned earlier, I've seen someone lose their job for making this mistake.
Admin
That's true, since one is your address and one is your wife's, but I would sure do a lot less recycling if people would recognize that my address equals my husband's address (and my kids' address). We get three of everything from our college (where our son will attend in the fall) and we barely want one!
So there is at least one instance where the addresses should be recognized as being the same.
Admin
My wife and I are smart enough not to subscribe to the same mailing lists.
Addendum (2014-04-01 14:15):
My wife and I are smart enough not to subscribe to the same mailing lists.
But if we did both sign up to receive a particular piece of literature, then I would expect that we both receive a copy.
Admin
To all who think the DBA's "solution" is correct, I dare you to implement the recommended fix in the "real world." TRWTF is the existence of the stored procedure.
Based on the original procedure, the following statements have >50% odds of being true:
Admin
I'm also choking on the irony.
Admin
I'm guessing that a lot of your work could end up on this site.
Admin
Sure, I'm stupid. Thanks.
We went to the same college, we are separate people, we get two. We didn't "sign up" for any of it. I guess you didn't graduate from college.
Admin
I graduated from a college that you can contact via phone, email, fax, etc...to ask them to only send one.
Admin
Basically, my point is that the burden is on YOU to only have one sent, not them. That is the mistake that you made with your initial comment.
Admin
Rubbish!
Admin
It's a joke, buddy.
Admin
He has a point. Sloppy coding infers sloppy procedures in other areas so changing the underlying table by changing UserLoginName to an Identity column may break more than it fixes.
Which is I assume why Marle said "look into" making the suggested changes.
Admin
Silly developer, not realizing that providing fast, highly concurrent, ACID compliant, data efficiently while adhering to all necessairy compliance and uptime is closer to the duties of a DBA.
It seems you're not that concerned with 'the data', you could always pipe your output to /dev/null. That'll be really fast bro, really fast!
Don't confuse your lack of understanding of the role outside of development, as the DBAs lack of understanding of 'data'. Pretty sure any good DBA with years of experience has a much better understanding of 'data' than a good dev with years of experienc
Admin
Dog: That's a fitting name for you. I suggest you keep it, perhaps add 'female' to the front of it to make it more accurate... you know, focus on data quality.
It's time to feast on crying developer tears, this is my favourite part on this site. Today is a especially good day, as the developer tears seem to be emitting from plump newborn babies, making it akin to eating 'develop tears veal'.
Ok crying developers, as you overfill my cups with your delicious tears, realize a couple of things:
1- You are agreeing with your favourite whipping boy, Nagesh. Full stop. That alone should make you question your existence, but let's continue on.
2- The more you cry and scream, the more obvious it is that you aren't a big time developer and probably worked in mid tech boring ass shops without a major tech department to put your ego in the trash bin where it belongs.
If you SERIOUSLY feel that a developer can do the job of a DBA, you are working in the most simple of environments and always have. It is rather comical watching you guys think you know what being a DBA providing 5 9's uptime (most of you don't even know what that means and have to google it, you're so far removed from operations), in a highly concurrent environment (read over 5000 transactions per second per DB), on data sets terabytes upon terabytes, and that's just on the SQL Relational database side! You think you could handle a Hadoop or Google Elastic search digesting hundreds of gigs a day and handle all bottlenecks along the line?? LOL. The ego and delusion here is off the hook.
3- The crying about not having access to sensitive data or environments, shows a complete lack of understanding of security policy on the enterprise, federal, payment card or finance industries. It means you have worked in a shop that doesn't really have anything that anyone really wants, writing apps that no one really cares about as it really has no exposure.
Please, do continue to cry more. You fillith thy cup.
Admin
And if the table is highly concurrent and huge? Also, why are the DBAs looked to provide band-aids for developer mistakes? It's as if the DBAs are the 'garbage collection' for the devs implementing worst-practices.
How about you fix your code so it doesn't suck and fits to the standards of a experienced developer instead of creating potentially massive IO, wasted memory, another index to be maintained every single time the base table changes, and more options for the query optimizer to review?
Admin
The problem is that there are a lot of DBAs who have the attitude shown by people like you and JJ from today's story, but most of them have the skills of JJ, rather than someone like you who can actually back up and justify what he's saying. I've been lucky to put myself in a position to work with more people like you, but from what I've heard about in this industry (these sites, user group meetings, etc), there are a lot of DBAs who will do something a given way "just because", and that's not acceptable. They would have probably produced a blank stare after reading your second paragraph.
That being said, there are a similar number of developers who act this way, but it's a bit different. DBAs go into the front end code far less often than developers touch the databases, so I can understand that DBAs are a bit more defensive of their territory.