This is more or less a D7 backport for the reason that I'm currently running daily into timeout issues in update.php and in other places on a very big site (~150.000 nodes). The main reason for this is the cache_clear_all() function that is using an very unperformant way to clear the tables with db_query("DELETE FROM {". $table ."}"); if a wildcard * is used. This is mostly the reason if we do a full cache clear.

The patch attached heavily speeds up the cache clear process by not deleting every single item and do a truncate on the whole table. My cache_filter table had 150.000 entries today and you can count yourself that this *must* run into a PHP timeout and heavy DB stress!

Comments

hass’s picture

Found another place in update.module that could better use TRUNCATE.

hass’s picture

StatusFileSize
new603 bytes

Not that I care much about D5 any longer, but here is a patch if you'd like to commit.

hass’s picture

Issue tags: +Performance
hass’s picture

Status: Needs review » Reviewed & tested by the community

~2 seconds for clearing all monster caches... this is such a great boost - you can really feel it - everywhere a full cache clear is executed - and this happens often in Drupal modules!

This patch is sooo trivial... I could simply set it RTBC myself... this are backports of #452936: Use db_truncate() in cache_clear_all()

gábor hojtsy’s picture

Version: 6.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Needs review

1. Let's verify this works in the supported database engines. Since TRUNCATE is not part of any SQL standard. http://www.postgresql.org/docs/8.1/static/sql-truncate.html looks to support it but we need to look back to as much in versions as we support.

2. Fixes go first to Drupal 7.

3. Please do not RTBC your own patches.

hass’s picture

Version: 7.x-dev » 6.x-dev

This has already been implemented in D7 some months ago (see #4)... with db_truncate() and TRUNCATE TABLE {table} works 100% with PgSQL and MySQL - only SQLite requires some special handling. Therefore we are fine in D6 and D5 to use it as is.

gábor hojtsy’s picture

That it works in D7 databases doe not mean it works in D6 databases. D6 and D5 has different DB requirements, and we need to check according to that.

hass’s picture

Ok, looking though the database servers documentation:

MySQL 4.1: http://dev.mysql.com/doc/refman/4.1/en/truncate-table.html looks working.
PgSQL 7.4: http://www.postgresql.org/docs/7.4/interactive/sql-truncate.html looks also working.

Do we need to test every version up to the current to verify?

damien tournoud’s picture

Status: Needs review » Reviewed & tested by the community

TRUNCATE is supported by both MySQL and PostgreSQL on versions we support on D6. Looks good to go.

But @hass: never *ever* mark as RTBC your own patches again.

hass’s picture

*Sry*

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Committed to Drupal 6, thanks.

Status: Fixed » Closed (fixed)
Issue tags: -Performance

Automatically closed -- issue fixed for 2 weeks with no activity.