Performance: Slow query in ping.module ping_cron()
Wesley Tanaka - November 19, 2008 - 13:59
| Project: | Drupal |
| Version: | 6.x-dev |
| Component: | ping.module |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Discovered as a part of investigating using Drupal with millions of nodes:
The SQL query in ping_cron() does a full table scan of the {node} table

#1
#2
Tested, and looks good.
Ping module is not in core in D7, so this should go straight into D6.
#3
Is this better because changed has an index, but created does not? (I did not look that up). Also, can we have the comment capitalized and have a dot at the end?
#4
Both changed and created have indexes, but whatever versions of MySQL that I have tried do not make this optimization of splitting the OR clause into two separate queries to avoid the full table scan.
The order of the queries is just a heuristic to try to get the second query to be short-circuited out most of the time.
Patch file edited directly to capitalize comment and add a period
#5
Why are we not using our %d placeholder in the query then?
#6
@Gabor,
That was an oversight when I initially RTBC'd this. I have fixed that in this version.
#7
I did not originally use %d placeholders because the original code did not use %d placeholders.
Given that we're cleaning that up, I'd also suggest switching the double quoted strings to single quoted ones (single quotes being faster). I have edited the patch to do this and am attaching it here.
Otherwise this %d version of the patch looks good to me.
#8
Thanks, committed to Drupal 6.
#9
Automatically closed -- issue fixed for 2 weeks with no activity.