[MCOL-603] sum of col=value fails with Internal error: std::bad_typeid Created: 2017-03-02  Updated: 2023-02-06  Resolved: 2022-11-28

Status: Closed
Project: MariaDB ColumnStore
Component/s: PrimProc
Affects Version/s: 1.0.7
Fix Version/s: 22.08.8

Type: Bug Priority: Major
Reporter: David Thompson (Inactive) Assignee: David Hall (Inactive)
Resolution: Fixed Votes: 1
Labels: community

Issue Links:
Relates
relates to MCOL-5275 Implement comparison functions for SE... Open
Epic Link: ColumnStore Compatibility Improvements
Sprint: 2017-20, 2021-17, 2022-22
Assigned for Review: Andrey Piskunov Andrey Piskunov (Inactive)
Assigned for Testing: Daniel Lee Daniel Lee (Inactive)

 Description   

I have a probleme with this patch https://jira.mariadb.org/browse/MCOL-301

The test is ok :
----------------------------------------------------

  1. mysql 14:23:48 > create table t1 (a int) engine=columnstore;
    Query OK, 0 rows affected (0.08 sec)
  1. mysql 14:24:18 > insert into t1 values (1),(1),(2),(2),(3),(3);
    Query OK, 6 rows affected (0.08 sec)
    Records: 6 Duplicates: 0 Warnings: 0
  1. mysql 14:24:24 > select sum(1) from t1;
    --------
    sum(1)

    --------

    1

    --------
    1 row in set (0.03 sec)

  1. mysql 14:24:37 > select sum((a=1)*(1=1)) from t1;
    ------------------
    sum((a=1)*(1=1))

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

    2

    ------------------
    1 row in set (0.01 sec)
    -----------------------------------------------------------------

But I am obliged to add *(1*1) . Too bad

  1. mysql 14:25:02 > select sum(a=1) from t1;
    ERROR 1815 (HY000): Internal error: std::bad_typeid


 Comments   
Comment by David Thompson (Inactive) [ 2017-03-02 ]

group thread: https://groups.google.com/forum/#!topic/mariadb-columnstore/4XJ9VqwLcrQ

Comment by Andrew Hutchings (Inactive) [ 2017-03-03 ]

The good news is it isn't caused by the fix for MCOL-301. The execution of that query doesn't touch that code (that could also be bad news because I think it should).

A quick assessment and I've found the problem is happening in ExeMgr during the execution instead of the storage engine plugin during the parsing of the query as in MCOL-301.

It is tripping up on this line:

errmsg << "doAggProject: unsupported column: " << typeid(*(srcp.get())).name();

We get here because we appear to have an AggregateColumn with no functionParms which probably shouldn't happen (the code doesn't handle that).

So there are two bugs here:

1. The error message should handle when srcp.get() is NULL
2. An AggregateColumn gets passed down without parameters.

Comment by David Hall (Inactive) [ 2022-10-21 ]

buildAggregateColumn() calls buildFunctionColumn(), which upon seeing the EQ_FUNC, short circuits out and returns NULL. Nothing notices, so an empty parm list is created and subsequent code isn't able to handle that. By setting fatalParseError here, we get an error rather than an Assert.

select sum((a=1)) from t3;
ERROR 1178 (42000): The storage engine for the table doesn't support MCS-2027: Non supported item in aggregate function sum((a=1)).

Somehow, buildArithmeticFunction – which is called by buildAgggregateColumn in the ((a=1)*1) case – handles the NULL return by calling buildParsseTree after detecting the NULL. I think this may be possible in the failing case as well. In fact, it could conceivably work for all cases of EQ_FUNC and similar. I will investigate.

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

The following functions aren't supported in the SELECT clause in columnstore
Item::COND_ITEM
Item_func::EQ_FUNC
Item_func::NE_FUNC
Item_func::LT_FUNC
Item_func::LE_FUNC
Item_func::GE_FUNC
Item_func::GT_FUNC
Item_func::LIKE_FUNC
Item_func::BETWEEN
Item_func::IN_FUNC
Item_func::ISNULL_FUNC
Item_func::ISNOTNULL_FUNC
Item_func::NOT_FUNC
Item_func::EQUAL_FUNC
Until these are implemented, no bueno.

Fixed to emit error message rather than crash.

Comment by Daniel Lee (Inactive) [ 2022-11-01 ]

Build tested: 22.11.01 (#5838)

Repeated the test case in the description and got a "Lost connect to ExeMgr" error:

MariaDB [mytest]> select sum(a=1) from t1;
ERROR 1815 (HY000): Internal error: Lost connection to ExeMgr. Please contact your administrator

In err.log

Nov  1 19:56:41 mcs1 Calpont[1776]: 41.517329 |0|0|0| E 00 CAL0000:/mdb/verylongdirnameforverystrangecpackbehavior/storage/columnstore/columnstore/writeengine/server/we_dmlcommandproc.cpp@2461: assertion 'auxColDBRootExtentInfo.size() == 1' failed         %%10%%
Nov  1 19:56:41 mcs1 writeengine[1776]: 41.517611 |0|0|0| E 19 CAL0001: we_readthread caught exception  MCS-2035: An internal error occurred.  Check the error log file & contact support.  

Comment by Daniel Lee (Inactive) [ 2022-11-28 ]

Build verified: latest in develop branch

engine: 93a2e7eb8bfafe905997bbdcc77e58688ed87f79
server: c9572eafa46fd5722881d2d1fa03a8ade22ac96e
buildNo: 6122

It now returned the expected error.

Please note that "select sum(1) from t1;" returned 6, as innodb did, not 1, as described in the description.

MariaDB [mytest]> create table t1 (a int) engine=columnstore;
Query OK, 0 rows affected (0.097 sec)
 
MariaDB [mytest]>  insert into t1 values (1),(1),(2),(2),(3),(3);
Query OK, 6 rows affected (0.096 sec)
Records: 6  Duplicates: 0  Warnings: 0
 
MariaDB [mytest]> select sum(1) from t1;
+--------+
| sum(1) |
+--------+
|      6 |
+--------+
1 row in set (0.026 sec)
 
MariaDB [mytest]> select sum((a=1)*(1=1)) from t1;
+------------------+
| sum((a=1)*(1=1)) |
+------------------+
|                2 |
+------------------+
1 row in set (0.006 sec)
 
MariaDB [mytest]>  select sum(a=1) from t1;
ERROR 1178 (42000): The storage engine for the table doesn't support MCS-2027: Non supported item in aggregate function sum(a=1).
MariaDB [mytest]> drop table t1;
Query OK, 0 rows affected (0.091 sec)
 
MariaDB [mytest]> create table t1 (a int) engine=innodb;
Query OK, 0 rows affected (0.004 sec)
 
MariaDB [mytest]> insert into t1 values (1),(1),(2),(2),(3),(3);
Query OK, 6 rows affected (0.001 sec)
Records: 6  Duplicates: 0  Warnings: 0
 
MariaDB [mytest]> select sum(1) from t1;
+--------+
| sum(1) |
+--------+
|      6 |
+--------+
1 row in set (0.000 sec)

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