[MCOL-898] NULL operand ignored in vtable mode when querying view Created: 2017-08-29  Updated: 2020-08-25  Resolved: 2017-10-25

Status: Closed
Project: MariaDB ColumnStore
Component/s: PrimProc
Affects Version/s: 1.0.10
Fix Version/s: 1.0.12, 1.1.1

Type: Bug Priority: Major
Reporter: patrice Assignee: Daniel Lee (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Sprint: 2017-19, 2017-20, 2017-21

 Description   

With the example below, columnstore return a number instead of NULL in the addition when there is a if in the view and using vtable=0 gives NULL.

use test;
create table test_bug(a float default null, b float default null) engine=Columnstore;
insert into test.test_bug values (rand(),rand()),(rand(),rand()),(rand(),rand()),(rand(),rand());
create or replace view test_bug_view (a,b,c) as select a,b,(abs(a*2.6+b*38.7))*1.16+if(a>0.5,a,1.0 -(a*0.1)) as c from test.test_bug;
set infinidb_vtable_mode=1;
select c+NULL as t,c from test.test_bug_view;
set infinidb_vtable_mode=0;
select c+NULL as t,c from test.test_bug_view;



 Comments   
Comment by Geoff Montee (Inactive) [ 2017-08-29 ]

It looks like this can be simplified into the following:

CREATE TABLE test_bug (
	a float default null
) ENGINE=ColumnStore;
INSERT INTO test_bug VALUES (0.0), (1.0);
CREATE OR REPLACE VIEW test_bug_view AS
SELECT IF(a>0,a,1) AS a FROM test_bug;
-- This gives the wrong result
SET infinidb_vtable_mode=1;
SELECT a+NULL FROM test_bug_view;
-- This gives the correct result
SET infinidb_vtable_mode=0;
SELECT a+NULL FROM test_bug_view;

Results:

MariaDB [test]> SET infinidb_vtable_mode=1;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> SELECT a+NULL FROM test_bug_view;
+--------+
| a+NULL |
+--------+
|      1 |
|      1 |
+--------+
2 rows in set (0.00 sec)
 
MariaDB [test]> SET infinidb_vtable_mode=0;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> SELECT a+NULL FROM test_bug_view;
+--------+
| a+NULL |
+--------+
|   NULL |
|   NULL |
+--------+
2 rows in set (0.01 sec)

Comment by David Hall (Inactive) [ 2017-10-05 ]

Substitution to remove the view still results in incorrect data. Therefore, the use of a view is not a contributing factor:

MariaDB [dhall]> SELECT if(`test_bug`.`a` > 0,`test_bug`.`a`,1)+NULL FROM test_bug;
----------------------------------------------

if(`test_bug`.`a` > 0,`test_bug`.`a`,1)+NULL

----------------------------------------------

1
1

----------------------------------------------
2 rows in set (0.03 sec)
MariaDB [dhall]> SET infinidb_vtable_mode=0;
Query OK, 0 rows affected (0.00 sec)

MariaDB [dhall]> SELECT if(`test_bug`.`a` > 0,`test_bug`.`a`,1)+NULL FROM test_bug;
----------------------------------------------

if(`test_bug`.`a` > 0,`test_bug`.`a`,1)+NULL

----------------------------------------------

NULL
NULL

----------------------------------------------
2 rows in set (0.01 sec)

Comment by David Hall (Inactive) [ 2017-10-06 ]

Swapping the order (NULL+a) gives the correct answer and can be used as a workaround.

The problem is caused by the right hand side of the '+' being evaluated first which sets a global NULL flag. The if logic on the left hand side uses that NULL flag in ways that cause the issue. By switching the order, the NULL is evaluated after the if so it doesn't interfere with the if and the if doesn't mess with the flag and so the proper answer is given.

Comment by David Hall (Inactive) [ 2017-10-06 ]

func_if uses a private utility boolVal(). We were passing in the global value of isNull, which had been set, which short circuited the boolVal logic. We then set isNull to false because we didn't want the action of boolVal to influence the final answer. Unfortunately, this had the effect of wiping out the right hand side setting.

I changed boolVal to use a private isNull, and let the other functions use isNull unchanged.

Comment by Daniel Lee (Inactive) [ 2017-10-24 ]

Build verified: Github source for 1.1.1-1

/root/columnstore/mariadb-columnstore-server
commit f6cd94ea167789970db7b5b501569a6549495d10
Merge: 3d846d3 91b2553
Author: David.Hall <david.hall@mariadb.com>
Date: Tue Oct 24 09:15:58 2017 -0500

Merge pull request #72 from mariadb-corporation/MCOL-982

MCOL-982 Merge MariaDB 10.2.9

/root/columnstore/mariadb-columnstore-server/mariadb-columnstore-engine
commit 751f9fbd2f26026983915a0677d6d600be273073
Author: david hill <david.hill@mariadb.com>
Date: Tue Oct 24 14:05:48 2017 -0500

removed duplicaue entries

Verified test case in the bug description, as well as in the comments.

Comment by Daniel Lee (Inactive) [ 2017-10-25 ]

Build verified: Github source for 1.0.12-1

/root/columnstore/mariadb-columnstore-server
commit a42eb6d1e74e44c9e8fd9bb8290e6ce7dbf909f5
Merge: 2965fc8 6a14ced
Author: David.Hall <david.hall@mariadb.com>
Date: Tue Oct 3 10:12:33 2017 -0500

Merge pull request #69 from mariadb-corporation/MCOL-940

MCOL-940

/root/columnstore/mariadb-columnstore-server/mariadb-columnstore-engine
commit 22f5c04f854d8571fa81ac33a26edc256d3acd48
Merge: 2f19dc2 c132f1b
Author: David.Hall <david.hall@mariadb.com>
Date: Tue Oct 24 17:39:45 2017 -0500

Merge pull request #300 from mariadb-corporation/MCOL-973-1.0

MCOL-973 remove reference to TEXT in the 1.0 code

Verified with the same tests.

Comment by Daniel Lee (Inactive) [ 2017-10-25 ]

Both 1.0.12 and 1.1.1 have been verified

Generated at Thu Feb 08 02:24:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.