Project

General

Profile

Actions

Bug #17189

closed

Replace DELETE FROM with faster TRUNCATE TABLE

Added by John Angel about 17 years ago. Updated over 13 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2007-04-04
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
4.1
PHP Version:
4.3
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Instead of:

$query = 'DELETE FROM '. $components['TABLE']. (strlen($where) ? ' WHERE ' . $where : '');

Should be:

if(strlen($where))
{
$query = 'DELETE FROM '. $components['TABLE']. ' WHERE ' . $where;
}
else {
$query = 'TRUNCATE TABLE '. $components['TABLE'];
}

Ref source:
t3lib/class.t3lib_sqlparser.php:1367
t3lib/class.t3lib_db.php:427
sysext/adodb/adodb/adodb-perf.inc.php:662

Ref mysql doc:
http://dev.mysql.com/doc/refman/5.0/en/truncate.html

(issue imported from #M5370)

Actions #1

Updated by Ingo Renner about 17 years ago

This doesn't work as the behavior of DELETE is different from TRUNCATE, TRUNCATE will also reset the auto increment sequence, DELETE won't. This could produce unexpected results.

Actions #2

Updated by John Angel about 17 years ago

What unexpected results might occur because Autoindex is reset to zero?

We are talking about clearing the cache?

Actions #3

Updated by Ingo Renner about 17 years ago

you didn't mention that...

Actions #4

Updated by Dmitry Dulepov about 17 years ago

Firsts, we need to check how dbal works with this. Secondly, truncate is identical to delete in speed for innodb tables.

Actions #5

Updated by John Angel about 17 years ago

Yes, interesting:

"TRUNCATE tbl_name is mapped to DELETE FROM tbl_name for InnoDB and doesn't reset the AUTO_INCREMENT counter."

Anyway, not all tables are InnoDB nor automatically converted to InnoDB when upgrading from older installation.

Actions #6

Updated by John Angel over 16 years ago

DELETE FROM cache_pages takes ages comparing to TRUNCATE cache_pages. Obviously it is extremely slower even for InnoDB.

Every time before deleting FE cache from admin panel, I have to do TRUNCATE manually, because cache_pages is 15 GB.

Actions #7

Updated by Hartmut Plehn over 16 years ago

We have the same problem: Clearing the fe cache from within the backend takes several minutes and reduces page delivery performance, truncating the cache_* tables directly takes less than a second.

Actions #8

Updated by Christian Boltz about 16 years ago

TRUNCATE on InnoDB is no longer mapped to DELETE since MySQL 5.0.3 (except if foreign keys reference to the table, which isn't the case for cache_hash AFAIK).

This means TRUNCATE is really faster. Much faster.

I would really like to see the patch applied.

But: If I get the patch right, it changes the behaviour for all tables since it is in a global function. If you really want to be sure you don't break anything, add a whitelist of truncate'able tables to the function.

Actions #9

Updated by Lars Houmark over 15 years ago

This ones seems no to be a difficult one to solve and at the same time it could speed up cache clearing for big sites.

One site I have been working with is almost going down when clearing the page cache, since DELETE FROM cache_pages takes forever and locks the table.

Since TRUNCATE no longer is mapped to DELETE in InnoDB it seems even more needed to have this one changed.

Actions #10

Updated by Lars Houmark over 15 years ago

Hi Ingo,

Please have a look at this one.

I have seen a TYPO3 website go down completely, because of cleaning the cache or updating the TS code. The website have around 20.000 pages and because of extensions with parameters, the cache_pages and cache_pagecontent have around 40.000 records each. Doing the delete is sooooo slow, and because of wait time for the DELETE, the queue in those tables gets enorm and MySQL crashes more or less hard. As a temporary work-around we run a TRUNCATE on the 3 cache_tables and the we click the backend button.

Thanks,

Lars

Actions #11

Updated by Dmitry Dulepov over 15 years ago

We are going to have a new caching framework in TYPO3 v 4.3. I am not sure that this issue still applies.

Actions #12

Updated by Ingo Renner over 15 years ago

the new framework uses TRUNCATE

Actions #13

Updated by Dmitry Dulepov over 15 years ago

Lars, you should use InnoDB for cache tables anyway. If you have such long delays it means you use MyISAM, which is bad because of rea/write locks.

Actions #14

Updated by Dmitry Dulepov over 15 years ago

Closing the issue because it is no longer relevant

Actions

Also available in: Atom PDF