- 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
sigh
Admin
Its amazing how many 'database developers' don't know anything about little things like indexes and such.
(oh, and hopefully this is the very first comment, but i'm going to break tradition and not say...it)
Admin
I think they should call Luke in to do a code review
Admin
Admin
Lsat?
Admin
ZZZZZZZZzzzzzzzzzzzzzzzzzzzzzzzzzzz Boring. A fields wasn't indexed, and you made a whole frikkin story about it. This site is officially no longer entertaining.
Admin
This is not the WTF, this is just daily routine
Admin
He should have left it for John to fix. After all, it's not like he was going to get any credit for the fix, and the comedy value of Johns next fix may have been worth it.
Admin
Gotta agree - that was way longer than it should have been - shoulda just stayed in the Side Bar. Not enough new story fodder coming through?
Admin
On one hand side not using source control should be a strong signal of lack of quality on the side of developer as it is on the side of company (software team) as in The Joel Test
On the other hand side version control (source control) of databases is much harded than of code... though solutions such as Sqitch exist to help with this.
Admin
Just imagine the kudos John is going to get when Matt gets bored enough to wander through the DB indexing everything else that should be indexed!
Admin
True. Right up until the point that join plunges the company into bankruptcy.
Admin
A join that plunges a company into bankruptcy must be some really bad SQL...
Admin
Clearly you haven't worked that much with developers like John here - I would expect 'new_id' to be neither new nor an id.
Admin
Sounds like the Daily Dogbert to me.
Captcha 'consequat': What you eat after a kumquat.
Admin
But having re-read the story now... how can reversing the table can make thinks faster in a (assumingly relational) database?
On, say 10 million records, is "SELECT id, Name FROM foo WHERE (ID > 8000000 AND ID < 9000000);" really slower than "SELECT id, Name FROM foo WHERE (ID > 1000000 AND ID < 2000000);"??
And is reversing the table even possible? Wouldn't John have to reverse the table after every new insert again?
This story sounds weird...
Admin
This is trivial. I once outsourced. The site I got back just about worked (although quality assurance would fine a hundred bugs in an hour or two), but as people started to sign up started to slow very quickly. I took a look at the slow log and there's this 20 line query on two tables with only a hundred rows each full of unions, several joins and so on that returned thousands of rows. What was this for? To check if a user existed in a group. It actually worked, but incredibly slowly.
Admin
I'm wondering why there had to be a "new_id" in the frist place. Since that's not explained, I want to think that was TRWTF.
Admin
Which means that John's actually a noob (or a nitwit) ant TRWTF is how he is idolized.
Admin
Heh... I would go back and correct the typo, but what you said is much better, so I'll leave it.
Admin
"Its amazing how many 'database developers' don't know anything about little things like indexes and such. " The data goes into the database and comes back out right? No one said it needs to be fast :)
Admin
Admin
Anyone who says this shouldn't be near a database.
Admin
Admin
Or the query was a "select top 1 where new_id=@value"... then yes, a table scan but one which terminates after scanning only a small percentage of the table if he value is in a row near the beginning...
Admin
I'm going to guess that John's last name was "Crapper", as evidenced by how easily he put performance into the toilet.
Admin
Quoted For Undeniable Truth
Admin
Admin
More recently-added data was probably being accessed more often, so the value for new_id would be higher for new records. He probably reversed the whole table, ordering it by new_id desc. Or something. Only way I can think of that a table scan would be faster.
Admin
Admin
Admin
Admin
I'm betting 100 quatloos that John had no idea what a table scan is.
Admin
A table scan in the order of the column being searched would indeed find the lowest or highest numbers first depending on the natural sort order.
That said, Oracle, MSSQL and MySql will create a clustered index on the primary key by default. If he's added an additional column, he would have to explicitly add a non-clustered index to the new column. I'm not even sure it's possible to "sort" a table on anything but the primary key using the clustered index.
Matt should not have added the index without sending an explanation of why his fix worked to John. Give the guy the benefit of the doubt and a little education. If he won't listen, Matt needs to start looking for his next job.
Admin
A third-party developer with access to production?
Any place that I've worked, a third-party developer needs a background check to even work in an isolated development environment.
Admin
Unless I don't understand you - a possibility, I grant you - what do you think non-clustered indexes are for?
Admin
"an industry veteran and was held in very high regard" was TRWTF
Admin
new_id = max(id) + 1 - id
Gets the reverse order. But it still doesn't make sense to me.
If another table references the id then its all gone to heck. If the id isn't referenced, then how does it have any effect.
Admin
Admin
What's amazing is that "that John guy" will probably be allowed to live to produce offspring.
Admin
Admin
♫ We don't need no git/subversion ♫ We don't need no source control ♫
Admin
You notified the Office of No Longer Entertaining Sites, did you?
Admin
Can somebody explain to me why database people are just plain weird? It crops up in the stories here, and it just takes a few lines and you find out that:
Is there any hope?
Admin
No, there is not. We continue on from force of habit, nothing more. Now go read some Beckett, it'll all make sense.
Admin
Yes and no ... these people are all over the place. I can't begin to count how many Johns (hilarious name in this context) I've run into who have their hooks way into my client and the great challenge is loosening their grip without causing them to go postal and do some real damage to the customer before I can reign them in.
Admin
Duh, it's obvious.
No one asked to search the middle. So stagger a beginning and end entry towards the middle.
1,10,2,9,3,8,4,6,5
Then doing a search for large values or small values will be just as fast.
Admin
It's scary to think about, but he might have been iterating over each and every 'new_id', looking for the one he needed. In that way, yes, higher numbers would be slower than lower ones.
Admin
Bonus is that John has no idea why his cantations first got so many positive reviews, but now are failing again.
Admin
Do you think he'd be smart enough to stop the cursor? :)