[MCOL-979] Crash with LEAD function in ColumnStore with 'char' field type Created: 2017-10-19  Updated: 2017-10-26  Resolved: 2017-10-26

Status: Closed
Project: MariaDB ColumnStore
Component/s: None
Affects Version/s: 1.0.11
Fix Version/s: 1.0.12, 1.1.1

Type: Bug Priority: Major
Reporter: Vicențiu Ciorbaru Assignee: Daniel Lee (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Sprint: 2017-21

 Description   

Steps to reproduce:

Install base columnstore package mariadb-columnstore-1.0.11-1-x86_64-stretch
postConfigure uses defaults, single server install.

use test;
create table ct1 (a int, b char) engine=columnstore;
 
insert into ct1 values (1, 'a'), (2, 'b'), (3, NULL);
select lead(a) over (order by a) from ct1;  -- Correct result
select lead(b, 1, 'T') over (order by a) from ct1;  -- Correct result
select lead(b) over (order by a) from ct1;  -- Crash happens here
select lead(b, 1, NULL) over (order by a) from ct1;  -- This also crashes

 
MariaDB [test]> select lead(b, 1, NULL) over (order by a) from ct1;
ERROR 1815 (HY000): Internal error: InetStreamSocket::readToMagic: Remote is closed
MariaDB [test]> select lead(b, 3, NULL) over (order by a) from ct1;
ERROR 1815 (HY000): Internal error: InetStreamSocket::readToMagic: Remote is closed



 Comments   
Comment by David Thompson (Inactive) [ 2017-10-24 ]

verify if this is broken in 1.1 as may behave differently.

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

In the develop (which at this time equates to 1.1), the query does not crash, but it does throw an error:

MariaDB [dhall]> select lead(b) over (order by a) from ct1;
ERROR 1815 (HY000): Internal error: basic_string::_S_construct NULL not valid

I thought this was affected by the presence of NULL in column b, but it turns out to throw regardless of the existence of a NULL value.

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

The error thrown in 1.1 is a further bug, preventing the execution of the crashing code. It was introduced to theoretically prevent a use of an uninitialized variable, but there is no use case yet for it. When LEAD(<char type>) is used, the default for un-found values is NULL, but assigning NULL to a string is not supported by std:string, at least not in the way it was used. So, the crash is still in 1.1, but masked. Removing the line that set the default (revert) is the best line of action here.

The crash is caused by assigning an integer type to a void pointer and then reassigning the void pointer as a std::string. Not good.

The function

template<typename T>
void WindowFunctionType::setValue()

checks for NULL and calls getNullValueByType(). Unfortunately setValue() expects a std::string for strings shorter than 9 bytes, but getNullValueByType() returns a 1,2,4, or 8 byte fixed buffer set to the NULL value for strings shorter than 9 bytes.

getNullValueByType() is called from no where else, so modifying it to always return a string for all character types is safe and appears to work.

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

Pull requests
The changes for 1.0 and 1.1 are not the same
engine: 1.0 - #304, 1.1 - #305
regression: #47

Comment by Andrew Hutchings (Inactive) [ 2017-10-26 ]

Merged into 1.0 and 1.1. Also merged new regression test.

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

Build verified: Github source for 1.0.12

/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 28d26c89018faa3ec02fd49559b2fb53e6847e97
Merge: a8414b9 5ab7538
Author: Andrew Hutchings <andrew@linuxjedi.co.uk>
Date: Thu Oct 26 20:22:27 2017 +0300

Merge pull request #304 from mariadb-corporation/MCOL-979-1.0

MCOL-979 getNullValueByType() should return string for all char types

Build verified: Github source for 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 2c358a99cabbac0411dca78c3b082ab843e3a781
Merge: 2d8439c 31456c0
Author: david hill <david.hill@mariadb.com>
Date: Thu Oct 26 14:11:36 2017 -0500

Merge branch 'develop-1.1' of https://github.com/mariadb-corporation/mariadb-columnstore-engine into develop-1.1

Both crashing queries fixed in 1.0.12, but not in 1.1.1.

In 1.1.1

The following query worked:
select lead(b) over (order by a) from ct1;

But this query returned a syntax error.

MariaDB [mytest]> select lead(b, 1, NULL) over (order by a) from ct1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' NULL) over (order by a) from ct1' at line 1

We need to

1) Fix the syntax error
or
2) Treat this fix as a partial fix. Create a following ticket for the outstanding issue.

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

Reopen per my last comment

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

For version 1.1, the third parameter (default value) is no longer supported. It was removed because of a merge with MariaDB 10.2, which doesn't support this parameter. Hopefully it will be supported by MariaDB in the near future, perhaps as soon as MariaDB 10.3.

See MCOL-646

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

Closed per last comments from Mr. Hall and myself.

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