[MDEV-25546] LIMIT partitioning does not respect ROLLBACK Created: 2021-04-27 Updated: 2022-04-22 Resolved: 2022-04-22 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Partitioning, Versioned Tables |
| Affects Version/s: | 10.3, 10.4, 10.5, 10.6 |
| Fix Version/s: | 10.3.35, 10.4.25, 10.5.16, 10.6.8, 10.7.4, 10.8.3 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Elena Stepanova | Assignee: | Aleksey Midenkov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Description |
LIMIT partition temporarily populated in transaction is not used anymore after ROLLBACKNote: There can be a race condition/non-determinism during MTR execution of the test case, as statistics on an InnoDB table is not precise (described in not-a-bug If we have several empty (not full) LIMIT partitions, rows are put in the first one first, when it's overflows then next, etc – that's the expected behavior. It affects both explicit and implicit (including auto-created) partitions. The test case below is for explicit ones, to be applicable to all versions which support system versioning.
|
| Comments |
| Comment by Aleksey Midenkov [ 2022-03-28 ] | ||||||||||||||||||||||||||||||||||||
Proposed fixvers_info->hist_part must be reverted on rollback for each table that was changed by transaction. vers_info->hist_part is initalized as first history partition in check_vers_constants() and then recalculated in vers_set_hist_part(). vers_info is stored in TABLE object (in part_info). Processing each TABLE on rollback is not possible without help of storage engine: ha_rollback_trans() can access only handlertons and the more detailed data about what was changed by transaction is known only by storage engine. InnoDB stores knowledge about what tables were modified into trx->mod_tables. This data is processed on partial rollback for trx-versioning needs (0b89a42ffc7). The structure is map with key dict_table_t *. Proposed InnoDB changes:1. trx_rollback_to_savepoint_low() calls mod_tables.rollback() not only for partial rollback but for full rollback as well (savept == NULL). Changes for p. 2:1. Generally there is no stored connection between dict_table_t and TABLE. The connection is done only by innodb_find_table_for_vc() for vcol needs. handler::ha_open() has TABLE object, handler::ha_open() calls handler::open() without TABLE object. That is virtual interface implemented by ha_innobase::open(). The goal is to supply TABLE to ha_innobase::open() and assign it to dict_table_t. That can be done like that in handler::ha_open():
handler::ha_open() first tries to call open2() which by default returns HA_NOT_IMPLEMENTED. ha_innobase has this interface: we rename ha_innobase::open() to ha_innobase::open2() and pass table_arg argument. 2. innodb_find_table_for_vc() now is not needed. We remove that function and table->vc_templ->mysql_table member. As far as I'm concerned this condition holds all tests except one below case:
The condition it cannot hold is this:
But this is OK, since TABLE member will be updated at each ha_innobase::open2() call. | ||||||||||||||||||||||||||||||||||||
| Comment by Aleksey Midenkov [ 2022-03-28 ] | ||||||||||||||||||||||||||||||||||||
|
marko Please review the above proposed changes to InnoDB. | ||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-03-29 ] | ||||||||||||||||||||||||||||||||||||
|
As far as I understand, there is no prototype implementation of the proposed idea yet. I would like to see a prototype both for the earliest suggested version and for 10.6, where the InnoDB transaction commit was heavily refactored. The InnoDB dict_table_t actually corresponds to TABLE_SHARE in the SQL layer and not TABLE. The TABLE is a table handle or a cursor, which would roughly correspond to row_prebuilt_t in InnoDB. It is unclear to me how the proposed idea would work on incomplete transactions that were recovered after the server was killed and restarted. A quick look in the code suggests that trx_t::mod_tables are only being updated for recovered transactions that are in the XA PREPARE state (and will remain in that state until an explicit commit or rollback statement). When it comes to innodb_find_table_for_vc(), nikitamalyavin should know this code. I think that it is unfortunate that the MySQL 5.7 implementation was imported to MariaDB 10.2 without thorough review. Implementing MDEV-17598 and MDEV-22361 would allow us to eventually remove that code. When it comes to partitioned tables, nayuta-yanagisawa is the subsystem owner and should be asked to review those changes. If this functionality involves the dynamic creation or dropping of partitions during the execution of DML transactions, I think that it is problematic. Until | ||||||||||||||||||||||||||||||||||||
| Comment by Aleksey Midenkov [ 2022-03-29 ] | ||||||||||||||||||||||||||||||||||||
In this bug we solve stale data in TABLE object. On server restart of course any data is reloaded. | ||||||||||||||||||||||||||||||||||||
| Comment by Aleksey Midenkov [ 2022-03-31 ] | ||||||||||||||||||||||||||||||||||||
You right. Moreover lifetimes of TABLE_SHARE and dict_table_t are independent by design. So we have to acquire TABLE_SHARE each time we need it in InnoDB. | ||||||||||||||||||||||||||||||||||||
| Comment by Aleksey Midenkov [ 2022-04-01 ] | ||||||||||||||||||||||||||||||||||||
|
Then the simplest solution is to process partitions each time from start for LIMIT in vers_set_hist_part(). | ||||||||||||||||||||||||||||||||||||
| Comment by Aleksey Midenkov [ 2022-04-01 ] | ||||||||||||||||||||||||||||||||||||
|
Please review bb-10.3-midenok | ||||||||||||||||||||||||||||||||||||
| Comment by Nikita Malyavin [ 2022-04-19 ] | ||||||||||||||||||||||||||||||||||||
|
ok to push |