Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Opening the admin page executes the following query:
SELECT DISTINCT(type) FROM watchdog ORDER BY type;
Adding an index on type improves the performance from 43 seconds to 1.19 seconds
I have 478235 records.
"I know it's a varchar column"
Comment | File | Size | Author |
---|---|---|---|
#22 | watchdog.HEAD-1015.patch | 1.42 KB | robertDouglass |
#20 | update183HEAD_1.patch | 1.44 KB | robertDouglass |
#16 | watchdog.HEAD-183.patch | 1.43 KB | robertDouglass |
#15 | watchdog.HEAD_0.patch | 1.4 KB | robertDouglass |
#13 | watchdog.HEAD.patch | 1.17 KB | RobRoy |
Comments
Comment #1
robertDouglass CreditAttribution: robertDouglass commentedThis should be addressed in 5 and backported to 4.7 and 4.6.
Comment #2
msameer CreditAttribution: msameer commentedMy bad. Looks like the server was a bit overloaded because I managed to execute the query without an index in about 5-6 seconds but still. The index improves the performance.
If you think that this should be in 5.x, I can work on a patch ?
Comment #3
robertDouglass CreditAttribution: robertDouglass commentedI'm in the process of benchmarking this. Please do roll a patch.
Comment #4
robertDouglass CreditAttribution: robertDouglass commentedI've now benchmarked this with 217905 rows in my watchdog table:
So yes, we're looking at a situation where with that number of watchdog rows, making an index speeds up the query by nearly three orders of magnitude.
Comment #5
robertDouglass CreditAttribution: robertDouglass commentedI just hate that issue responses don't respect the Input Format.
Standard Drupal core
Made an index on column 'type'
Comment #6
robertDouglass CreditAttribution: robertDouglass commentedHere's a patch against 4.7.
Comment #7
robertDouglass CreditAttribution: robertDouglass commentedAnd here's one for HEAD.
Comment #8
robertDouglass CreditAttribution: robertDouglass commentedForgot the new db case for postgres.
NOTE: because I've added this as upgrade 183 (I'm assuming it will get backported), there is NO case where the index might get added twice, so there is no need to check for the existence of the index before adding it.
Comment #9
robertDouglass CreditAttribution: robertDouglass commentedUpdated 4.7 version; forgot to add to the three database creation files.
Comment #10
chx CreditAttribution: chx commentedWhile I have no HEAD pgsql Drupal, I ran the update SQL statement on a pgsql database and it worked. So, it works, the advantage is tremendous -- get it in!
Comment #11
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedI don't think it is neccessary to backport to 4.7. People with a lot of watchdog entries and a habit of looking at their logs all the time can add it themeselves. ;)
Comment #12
webchickOk in that case, the update number needs increasing to 1000-something.
Comment #13
RobRoy CreditAttribution: RobRoy commentedCleaned up the patch for HEAD and put the update in the 1000 series.
Comment #14
robertDouglass CreditAttribution: robertDouglass commentedGerhard: I don't agree with not backporting - aren't we planning on having another 4.7.* release at some point? Why deny that version this improvement? Is there a real reason *not* to? There are certainly good reasons why it should be backported; it is the highest quality watchdog we know how to offer.
Comment #15
robertDouglass CreditAttribution: robertDouglass commentedRobRoy's patch missed the postgres case for new databases.
This patch puts the upgrade in 1015 - use it if the change won't get backported to 4.7.
Comment #16
robertDouglass CreditAttribution: robertDouglass commentedThis patch puts the upgrade in 183 - use it if the change will get backported to 4.7.
Comment #17
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedMy reason to not backport is that it is only an admin function that is affected and so the overall impact isn't that big and that I try to avoid sql updates in minor releases if at all possible.
Comment #18
RobRoy CreditAttribution: RobRoy commentedOops, I updated the wrong patch. Sorry about that, and thanks for the catch Robert. I would change the double quotes to singles in the pgsql db_query but I'm too tired and don't want to seem TOO anal, but I feel like core stuff should set a good example as that's how I learned a lot of my coding standards.
Since this is such a big improvement IMHO it's worth a backport since a huge query time like that could affect your whole site's performance say if you had a bunch admins looking at the watchdog table. And if 4.7 users don't hit update.php after their core update, no big whoop. They're not going to see any db errors so the impact on the stability of that branch isn't really affected. Just my $0.02.
Comment #19
robertDouglass CreditAttribution: robertDouglass commentedSo unless Gerhard changes his mind, #16 is the patch to go with, and it is RTBC. Chx has tested the postgres update.
@RobRoy... since I had the editor open to the line with the double quotes, I almost changed them and re-rolled, just for your benefit. But the whole file uses double quotes... and it would have been the only line with single, so I balked.
Comment #20
robertDouglass CreditAttribution: robertDouglass commentedsee, that was sneaky of me! I said #16 but that's the one that assumes the backport ;-) Just trying to force killes' hand, I guess. I'm uploading a copy of 15 to this follow up... this is the patch to use.
Comment #21
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #22
robertDouglass CreditAttribution: robertDouglass commentedoh, that was even sneakier. I uploaded the wrong friggin' patch!
deep breath...
Here is the right one.
Comment #23
robertDouglass CreditAttribution: robertDouglass commentedDries applied the right one.
Comment #24
(not verified) CreditAttribution: commentedComment #25
olo CreditAttribution: olo commentedI have an analogous problem in Drupal 6.0 with the same table ("watchdog"), but with the "uid" field, which isn't indexed yet.
When deleting multiple users, I can see in PostgreSQL logs that there are multiple UPDATE queries that occupy > 25 seconds:
duration: 35890.329 ms statement: UPDATE watchdog SET uid = 0 WHERE uid = 0
Adding an index fixes the problem:
CREATE INDEX watchdog_uid_idx ON watchdog USING btree (uid);
Should I file a new issue report?
Comment #26
Mumonkan CreditAttribution: Mumonkan commentedolo, i have seen the same problem. in drupal 5 though. i think (in our case) it is a cron process cleaning up deleted users. but i see the same trouble -- multi-second (often way way way too long!) queries of the form "UPDATE watchdog SET uid=0 WHERE uid=...". totally unacceptable, as it is locking the watchdog table all over the site (duh, of course watchdog is used by a ton of things), so the site gets ridiculously slow.
i find it kind of baffling this hasnt been addressed before. maybe people are zeroing out watchdog all the time, or simply have incredibly zippy servers (ha).
but fwiw, i agree that an index on uid would seem to be the (simple) solution. i would guess we would want to file this as a new report. but i figured i should comment, if for no other reason than to help some frustrated drupal admin find it via google. like i wish i had done a few weeks ago. haha