[MDEV-23799] CREATE .. SELECT wrong result on join versioned table Created: 2020-09-23 Updated: 2020-10-20 Resolved: 2020-10-20 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Versioned Tables |
| Affects Version/s: | 10.5.5, 10.3, 10.4, 10.5 |
| Fix Version/s: | 10.3.26, 10.4.16, 10.5.7 |
| Type: | Bug | Priority: | Major |
| Reporter: | Lucas Schons | Assignee: | Aleksey Midenkov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | temporal, temporary | ||
| Environment: |
OS: Arch Linux x86_64 |
||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
When creating a temporary table with the following statements, the behavior is as expected:
The statements above result in the expected temporary table:
But issuing the same statement for bi-temporal tables, wich are similar in respect to the data, result in an empty set:
I expect that the two queries yield the same result since they have nothing to do with the temporality of the tables. |
| Comments |
| Comment by Alice Sherepa [ 2020-09-24 ] | ||||||||||||||||||||||||||||||||||||||||
|
Thanks a lot! Repeatable on MariaDB 10.3-10.5.
| ||||||||||||||||||||||||||||||||||||||||
| Comment by Aleksey Midenkov [ 2020-10-15 ] | ||||||||||||||||||||||||||||||||||||||||
Reproduce
ResultNo rows selected. Expected
CauseFor join to work correctly versioning condition must be added to table on_expr. Without that JOIN_CACHE gets expression (1) trigcond(xtitle.row_end = TIMESTAMP'2038-01-19 06:14:07.999999') and instead of (2) trigcond(xtitle.elementId = x.`id` and xtitle.pkey = 'title') for join_null_complements(). It is NULL-row of xtitle for complementing the join and the above comparisons of course FALSE, but trigcond (Item_func_trig_cond) makes them TRUE via its trig_var property which is bound to some boolean properties of JOIN_TAB. Expression (2) evaluated to TRUE because its trig_var is bound to first_inner_tab->not_null_compl. The expression (1) does not evaluate correctly because row_end comparison's trig_var is bound to first_inner->found earlier. As a result JOIN_CACHE::check_match() skipped the row for join_null_complements(). When we add versioning condition to table's on_expr the optimizer in make_join_select() distributes conditions differently. tmp_cond inherits on_expr value and in Good case it is full expression xgender.elementId = x.`id` and xgender.pkey = 'gender' and while in Bad case it is only xgender.elementId = x.`id` and xgender.pkey = 'gender'. Later in Good row_end condition is optimized out and we get one trigcond in form of (2). | ||||||||||||||||||||||||||||||||||||||||
| Comment by Aleksey Midenkov [ 2020-10-15 ] | ||||||||||||||||||||||||||||||||||||||||
|
https://github.com/midenok/mariadb/commit/c000b7bbede7cc4ba770db6d1039b9bc0ead7be7 |