[MCOL-1472] where does not properly evaluate case when case when on varchar columns Created: 2018-06-14 Updated: 2018-08-07 Resolved: 2018-08-07 |
|
| Status: | Closed |
| Project: | MariaDB ColumnStore |
| Component/s: | MariaDB Server |
| Affects Version/s: | 1.1.4 |
| Fix Version/s: | 1.1.6 |
| Type: | Bug | Priority: | Minor |
| Reporter: | antoine | Assignee: | Daniel Lee (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
debian9 |
||
| Issue Links: |
|
||||||||||||||||
| Sprint: | 2018-14, 2018-15, 2018-16 | ||||||||||||||||
| Description |
|
the following type of expression evaluates correctly as a column of a select query, but not in a where clause: case when (case when ... then ... else ... end) then ... else ... end the problem appears on varchar columns here is an example: create table t(a varchar(20) not null) engine=ColumnStore default character set=utf8; the following query correctly returns 1 row (the expression is evaluated as a column of a select): the following query (the "problem query") returns no row but it should return one. the problem expression is evaluated in the where clause: I did the following tests:
|
| Comments |
| Comment by Andrew Hutchings (Inactive) [ 2018-06-14 ] | ||||
|
Confirmed. This definitely isn't a UTF8 problem, more likely to do with the CASE handling changes in ColumnStore and MariaDB. | ||||
| Comment by David Hall (Inactive) [ 2018-07-19 ] | ||||
|
As best as I can determine, this only happens if an IS NULL or IS NOT NULL occurs in an inside nested CASE. When the CASE is in a SELECT, the code calls BuildFunction() directly, which starts with the outside case, which recursively builds the inside case and the stacks play nicely. When the CASE is in the WHERE clause, it uses traverse_cond(), which walks a tree and starts on the inside and works the leaves, then up the tree. When this happens, the interior CASE is left on rcWorkStack when it gets to the outside CASE. At this point the outside case doesn't trust the tree, so it tries to rebuild its arguments. This shouldn't be a problem, except that IS NULL doesn't have it's argument as a leaf in the tree. When we get to processing the IS NULL, it looks on the rcWorkStack and uses what's there, which is the whole inside case statement from before. Oops. The kludge is to set a flag just before processing the item of the outside CASE. If the flag is set, IS NULL doesn't use the element in the stack, and all is well. Other functions and predicates are wise enough to actually have their arguments in the tree, so when prcessed the second time, the stack gets used properly. | ||||
| Comment by Daniel Lee (Inactive) [ 2018-08-07 ] | ||||
|
Build verified: 1.1.6-1 source /root/columnstore/mariadb-columnstore-server Merge pull request #123 from drrtuy/ /root/columnstore/mariadb-columnstore-server/mariadb-columnstore-engine Merge pull request #523 from mariadb-corporation/ MariaDB [mytest]> insert into t(a) values ('a'),('b'); MariaDB [mytest]> SELECT
------
------ MariaDB [mytest]> SELECT *
---
--- |