[MDEV-5595] Bug in Index on deletion in TokuDB Created: 2014-01-31 Updated: 2014-05-06 Resolved: 2014-05-06 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 10.0.7 |
| Fix Version/s: | 10.0.11 |
| Type: | Bug | Priority: | Major |
| Reporter: | Alexey Zilber | Assignee: | Unassigned |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | tokudb, upstream | ||
| Environment: |
CentOs, TokuDB 7.1.0 |
||
| Description |
|
Hi All, We are running into a very weird issue with slow and hanging queries on TokuDB 7.1.0. Here's some background and configs: Since beginning to write this post, we've identified the exact issue and it seems to be a bug in the way TokuDB handles indexes when an entry is deleted. Here's some background information as part of the original message I was writing, as well as our temporary workaround: Previously we were running on MariaDB 5.3/XtraDB with no issues. The reason we switched to TokuDB is for space savings. We are now experiencing terrible performance issues on an email table, causing us to have to truncate the table every few months. We have a cleanup script running that deletes everything from the table that's older then 50 days. There are around 180M rows in the table, consisting of emails. General config:
TokuDB specific config:
Things run perfectly fine until simple queries of the type: select * from `InBox` where `id`=12345 limit 1 Here's an explain (from the slave DB, prior to our latest truncate on the master), please note that the slave server is identical to the master:
The select also returns in (0.00 sec). Now here's one problem. If you do a query, that references an item that used to exist, but has been deleted. The query will scan the whole db. This can quickly kill the database: If you do an explain
or do a select:
But if you do it in an index that has never existed, this is not a problem:
As you can see by the execution times, the difference is huge, and any accidental access to an old, non-existant item is pretty catastrophic. Our current workaround, is never to delete. We will have to wait till the table fills up, then truncate it. Some additional worries from the previous message: Additionally, previously on InnoDB, we would do EXPLAIN statements and use the # of rows estimated. This was very accurate to the # of rows returned. If i were to do the statement without the explain like i could do with certain indexes, EXPLAIN SELECT * from BLAH use index(`sometimeindex`) where `sometimeindex` > NOW() - interval 1 day and the # of estimated rows in the explain statement would be nearly equal to that if i ran the query itself. But now if i do that, the # of rows returned in the explain doesn't actually change. We're worried that with the constant deletes, that the indexes are getting seriously messed up. This is the schema for the (obfuscated) InBox table:
Here's the DELETE sql:
Thank you! |
| Comments |
| Comment by Alexey Zilber [ 2014-01-31 ] | |||||||||||||||||||||||||||||||||||||||||||
|
To add some more info. This event is observable when we begin to delete data after aproximately 50 days of inserts. At that point, there's aprox. 170+ million rows, and 400GB of compressed data. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexey Zilber [ 2014-03-10 ] | |||||||||||||||||||||||||||||||||||||||||||
|
Could we assign this to someone? This is a very critical bug, possibly even blocker level, as the deletions cannot be performed on a huge tokudb table without rebuilding indexes. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2014-03-10 ] | |||||||||||||||||||||||||||||||||||||||||||
|
Hi Alexey, The issue has been discussed with TokuDB people, but none of us was able to reproduce the problem so far, so we are eagerly awaiting the new information from you. You wrote in the Google group:
and (about OPTIMIZE)
But you haven't given an update on either of the experiments. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Tim Callaghan (Inactive) [ 2014-03-10 ] | |||||||||||||||||||||||||||||||||||||||||||
|
The current work around is to optimize the table. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexey Zilber [ 2014-03-10 ] | |||||||||||||||||||||||||||||||||||||||||||
|
Optimize table is not workable on a multi-terabyte database after every delete. Not deleting at all seems to be the only solution for now. I will try doing further tests as per the MariaDB's team. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Tim Callaghan (Inactive) [ 2014-03-10 ] | |||||||||||||||||||||||||||||||||||||||||||
|
Alexey, partitioning might also be a workable solution for your use-case. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexey Zilber [ 2014-03-22 ] | |||||||||||||||||||||||||||||||||||||||||||
|
We may have run into a different scenario with this bug where it's more testable, but the implications are potentially worse. We noticed the same symptoms as we described initially. The table status:
This is the original query we were running:
We realized, when we compared the explain of this same query to the other DB (which at that point was not having this issue, but which started having the same issue a few hours later), that the query type went from a range type, to a ref type. We ran analyze table on 'MaskedTable1', which did nothing. We then ran optimize table on 'MaskedTable1' and this fixed the issue. Unfortunately, if fixed the issue for a approximately 8 hours. It seems the query optimiser is also perhaps having issues. We're attempting another work-around right now, that seems to be working. It's best shown via these explain statements. These were done on the same db, seconds after each other, with no optimise table run between them:
Based on the explains above, the workaround is to set active=0 right before we issue a DELETE. This is what led us to believe this issue is related to the original bug filed. Since this issue is becoming more critical, and is reproducible on even smaller tables now, I believe the bug needs to be escalated. Either it's an index issue or a big problem with the query optimiser. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2014-04-07 ] | |||||||||||||||||||||||||||||||||||||||||||
|
This is TokuDB issue. When it will be fixed upstream we will merge the new TokuDB with the fix. But as of TokuDB 7.1.5 it is not fixed yet. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Rich Prohaska [ 2014-04-28 ] | |||||||||||||||||||||||||||||||||||||||||||
|
tokudb 7.1.6 fixed the long point query times for deleted keys. see https://github.com/Tokutek/ft-index/issues/218. |