- 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
The only thing this is faster at, is in filling a screen with one query.
Admin
It's a faster way to get your Lines of Code (LOC) metric up.
Admin
If Ted had just enough knowledge to be dangerous, given the outcome, I'm wondering what that knowledge is, and what its source is.
Admin
If column "updater" is not unique, Ted's code will update much more than only the row with change = @change.
Admin
In that case, your first task is to stop using silly prefixes.
Admin
Given the naming conventions, I'm going to be generous and assume that
updater
is the primary key oftbl_updater
. Our submitter didn't have anything to say on the subject beyond, "This is what the query should be," so it's a good assumption.Admin
Apparently Ted thinks it's faster to set the "date" column twice. Kudos for creativity!
Admin
I don't say this often, but too bad they weren't using MySQL. It has a quirk where it doesn't allow using a subquery that references the same table in the WHERE clause of an UPDATE or DELETE query.
Admin
I was going to say this. But the more I looked at this code, the more I believe there's a good possibility that updater is null.
Admin
Maybe Ted learned that from some Atari shareware database package back in the day.
Admin
Oh, it's faster alright. In the future, anyone who looks at the code will instantly understand Ted's "value" to the project. Much time saved.
Admin
It gets slower a lot faster
Admin
Maybe Ted's original method was to print out the database tables, put the printouts on a wooden desk, take photos and give the photos to his teenage daughter to mark with a highlighter.
Admin
Is it rude to point out that is in fact faster than his neurons firing?
Admin
They are both one-liners, so it wouldn't actually move a needle in that regard - and even if you break them down in two lines, well, it's still a 1:1 ratio to the broken down original statement :-)
Admin
well, it is certainly faster. Rather have one query that is slightly slower than needed, than have the original six querys with a sub-query in each. Of course it is faster.
Admin
Classic case of premature optimization:
Admin
And not even in backticks, so it will be treated as a function...
Admin
I've worked with a Ted. I responded to his "It's still faster this way."
"Show me."
My Ted then proceeded to run benchmarks that showed that his individual statements that updated a single field each finished in less time than it took my version of the code to update all of the fields... by about a second on average, on operations that took minutes.
I added up all of his individual statements times, to come up with a value that was about 5 seconds slower than 6 times longer than the overall job. "This isn't faster. This is 1/6th the speed, and it also doesn't update the entries consistently, because while you were running all of your individual statements, we got a new match, and it's only had some of the fields cleared." Of course, that wouldn't be possible here, since @change isn't updated between each of those jobs and I assume it only has values that are already in the change database. We were looking for a situation, however, and new entries with that situation could be added in the middle of a run. Oh, and we'd never find that partially updated entry if we weren't looking for it, because the last field cleared was part of the condition we were looking for.