Project

General

Profile

Actions

Feature #24307

closed

sys_history: optimize indexes

Added by Juergen Deisenroth almost 14 years ago. Updated over 13 years ago.

Status:
Closed
Priority:
Should have
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2010-12-07
Due date:
% Done:

0%

Estimated time:
PHP Version:
5.3
Tags:
Complexity:
Sprint Focus:

Description

The combined database key "recordident (tablename,recuid,tstamp)" for the table "sys_history" at the the file "typo3_src-4.5.0beta2/t3lib/stddb/tables.sql" works like the three single keys:
recordident_1 (tablename)
recordident_2 (tablename,recuid)
recordident_3 (tablename,recuid,tstamp)
But there is no sql statement using all three columns and the key generation is wasting resources. It should be changed to "recordident (tablename,recuid)". A second reason for the change is the high cardinality for the combination of tablename and recuid, so the third column has no positive effect.

Add a new key "tstampident (tablename,tstamp)" for clearing the history at t3lib_TCEmain::clearHistory() because the delete statement (WHERE tstamp<... AND tablename=...) uses only the first column "tablename" from the key "recordident" with a very poor cardinality at a large history table.

On our system the slow query reported at http://bugs.typo3.org/view.php?id=14852 is gone.
(issue imported from #M16698)


Files

16698.diff (467 Bytes) 16698.diff Administrator Admin, 2011-01-13 15:28
16698_02.diff (538 Bytes) 16698_02.diff Administrator Admin, 2011-01-13 23:20

Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #22986: Slow query in sys_history due to missing key on tstamp / tablenameClosedChristian Kuhn2010-06-24

Actions
Actions #1

Updated by Ernesto Baschny almost 14 years ago

Sounds logical. So you propose is to:

alter table sys_history drop KEY `recordident`;
alter table sys_history add KEY `recordident_1` (`tablename`,`recuid`);
alter table sys_history add KEY `recordident_2` (`tablename`,`tstamp`);

Right? Christian Kuhn, what do you think? See attached patch (diff).

Actions #2

Updated by Christian Kuhn almost 14 years ago

I'll take a look, soon.

Actions #3

Updated by Steffen Kamper almost 14 years ago

sounds good, but please rename the indizes, simply use

tablename_recuid  (tablename, recuid);
tablename_tstamp  (tablename, tstamp);

Actions #4

Updated by Christian Kuhn almost 14 years ago

mysql (afaik) background: mysql can use keys over multiple fields if they are given in where in a row:

In our current example:
KEY recordident (tablename,recuid,tstamp)
> where tablename = foo and recuid = 42 and tstamp = 123 -> mysql uses full key.
> where tablename = foo and recuid = 42 > mysql uses key on tablename and recuid
> where tablename = foo and tstamp = 123 -> mysql uses key on tablename, but not on tstamp (it can't, because there is recuid in between).

--> if there are only queries like
> where tablename = foo and recuid = 42
> where tablename = foo and tstamp = 123
it would be better to key those two independ from each other like Juergen suggested. This seems to be the case in all current core queries.

Attached patch also changes the storage engine to InnoDB, which won't harm at this point and improves locking for this table.

For the cardinality: recuid and tstamp both have pretty much the same cardinality for me.

Actions #5

Updated by Christian Kuhn almost 14 years ago

Sent to core list.

Actions #6

Updated by Patrick Broens almost 14 years ago

Committed to trunk rev 10068

Actions #7

Updated by Susanne Moog over 13 years ago

  • Target version deleted (4.5.0)
Actions

Also available in: Atom PDF