[MDEV-32233] TRUNCATE table does not clear table statistics Created: 2023-09-23  Updated: 2023-09-23

Status: Open
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.5
Fix Version/s: 11.4

Type: Bug Priority: Major
Reporter: Michael Widenius Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: None


 Description   

Truncate table does not call delete_statistics_for_table(), which means that after truncation all table statistics will be wrong.

Fix:
Call delete_statistics_for_table() before calling ha_truncate() in Sql_cmd_truncate_table::handler_truncate().

We have to decide if this is a bug (in which case we should fix this in 10.4/10.5) or a feature, in which case we should fix this in 11.4.



 Comments   
Comment by Elena Stepanova [ 2023-09-23 ]

Strictly formally, it cannot be a bug because the documentation that we have (which isn't much) claims that engine-independent statistics are only updated by ANALYZE or by manual update of statistical tables.
Thus, even adjustments to statistics which are made upon ALTER or DROP TABLE are in fact an undocumented feature.

That said, it seems unlikely that users should cherish stale statistics of a truncated table, so probably, if deletion doesn't affect much TRUNCATE execution time, they shouldn't mind. Of course, a question can be raised why TRUNCATE t deletes statistics while DELETE FROM t doesn't, but since TRUNCATE differs from DELETE in many aspects, it won't be anything unique.

Generated at Thu Feb 08 10:29:50 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.