1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-10 01:22:48 +03:00
Files
mariadb-columnstore-engine/mysql-test/columnstore
Alexander Barkov fa9f18553a MCOL-4728 Query with unusual use of aggregate functions on ColumnStore table crashes MariaDB Server
After an AggreateColumn corresponding to SUM(1+1) is created,
it is pushed to the list:

    gwi.count_asterisk_list.push_back(ac)

Later, in getSelectPlan(), the expression SUM(1+1) was erroneously
treated as a constant:

  if (!hasNonSupportItem && !nonConstFunc(ifp) && !(parseInfo & AF_BIT) && tmpVec.size() == 0)
  {
     srcp.reset(buildReturnedColumn(item, gwi, gwi.fatalParseError));

This code freed the original AggregateColumn and replaced to a ConstantColumn.

But gwi.count_asterisk_list still pointer to the freed AggregateColumn().

The expression SUM(1+1) was treated as a constant because tmpVec
was empty due to a bug in this code:

                    // special handling for count(*). This should not be treated as constant.
                    if (isp->argument_count() == 1 &&
                            ( sfitempp[0]->type() == Item::CONST_ITEM &&
                                (sfitempp[0]->cmp_type() == INT_RESULT ||
                                 sfitempp[0]->cmp_type() == STRING_RESULT ||
                                 sfitempp[0]->cmp_type() == REAL_RESULT ||
                                 sfitempp[0]->cmp_type() == DECIMAL_RESULT)
                            )
                        )
                    {
                        field_vec.push_back((Item_field*)item); //dummy

Notice, it handles only aggregate functions with explicit literals
passed as an argument, while it does not handle constant expressions
such as 1+1.

Fix:

- Adding new classes ConstantColumnNull, ConstantColumnString,
  ConstantColumnNum, ConstantColumnUInt, ConstantColumnSInt,
  ConstantColumnReal, ValStrStdString, to reuse the code easier.

- Moving a part of the code from the case branch handling CONST_ITEM
  in buildReturnedColumn() into a new function
  newConstantColumnNotNullUsingValNativeNoTz(). This
  makes the code easier to read and to reuse in the future.

- Adding a new function newConstantColumnMaybeNullFromValStrNoTz().
  Removing dulplicate code from !!!four!!! places, using the new
  function instead.

- Adding a function isSupportedAggregateWithOneConstArg() to
  properly catch all constant expressions. Using the new function parse_item()
  in the code commented as "special handling for count(*)".
  Now it pushes all constant expressions to field_vec, not only
  explicit literals.

- Moving a part of the code from buildAggregateColumn()
  to a helper function processAggregateColumnConstArg().
  Using processAggregateColumnConstArg() in the CONST_ITEM
  and NULL_ITEM branches.

- Adding a new branch in buildReturnedColumn() handling FUNC_ITEM.
  If a function has constant arguments, a ConstantColumn() is
  immediately created, without going to
  buildArithmeticColumn()/buildFunctionColumn().

- Reusing isSupportedAggregateWithOneConstArg()
  and processAggregateColumnConstArg() in buildAggregateColumn().
  A new branch catches aggregate function has only one constant argument
  and immediately creates a single ConstantColumn without
  traversing to the argument sub-components.
2021-09-21 14:00:56 +04:00
..

Objective
---------
The 'columnstore' test suite includes tests suites aimed at testing MariaDB Columnstore
Database Engine (MCS).

https://mariadb.com/kb/en/mariadb-columnstore/

Test Repo
---------
https://github.com/mariadb-corporation/columnstore-tests/tree/master/mysql-test/suite/columnstore

Test structure
--------------
The current directory structure is shown below:

columnstore/
├── basic
│   ├── r
│   └── t
├── csinternal
│   ├── autopilot
│   │   ├── r
│   │   └── t
│   ├── devregression
│   │   ├── r
│   │   └── t
│   └── include
│       ├── dbt3
│       └── ssb
├── extended
├── include
└── std_data

't' dir contains the tests.
'r' dir contains the expected result files.
'include' dir contains common libraries used by the tests.
'std_data' dir containt test data files. 

Test suites:
1. basic
Mostly sanity, high value, shorter execution time tests

2. extended
More complex and involved tests - longer execution time, variations

3. csinternal
Limited to CS internal team - Uses seeded test data. The tests in this are divided into the following two sub-suites:
   autopilot - Autopilot cases migrated to MTR
   devregression - Part of Dev test suite migrated to MTR

Prerequisites
-------------
1.
MariaDB Server and Columnstore are already installed on the test box, let's call it INSTALL_DIR. Usually it is /usr/share/mysql.
mysql-test is already installed, let's call it MYSQLTEST_DIR. Usually it is /usr/share/mysql-test.
Columnstore-tests local repository, let's call it MCSTEST_DIR. Usually it is columnstore-tests/mysql-test/suite/columnstore

cd MYSQLTEST_DIR
ln -s MCSTEST_DIR MYSQLTEST_DIR/suite/columnstore

2. Only for csinternal tests
For csinternal test run requires the test data 'dbt3' and 'ssb' stored at https://drive.google.com/drive/folders/1dAV4ltxLrvC_7TrZ4zLu42gxx17wzH15?usp=sharing to be available at the following location on the test box:

/data/qa/source/
               dbt3
               ssb

Setup test environment by running the following:
./mtr --suite=columnstore/csinternal regression_env_setup  --extern socket=/var/lib/mysql/mysql.sock

Test Run
--------
Run test suite:
mtr --force --suite=columnstore/basic --extern socket=/var/lib/mysql/mysql.sock
mtr --force --suite=columnstore/extended --extern socket=/var/lib/mysql/mysql.sock
mtr --force --suite=columnstore/csinternal --extern socket=/var/lib/mysql/mysql.sock
mtr --force --suite=columnstore/csinternal/autopilot --extern socket=/var/lib/mysql/mysql.sock
mtr --force --suite=columnstore/csinternal/devregression --extern socket=/var/lib/mysql/mysql.sock

Run individual test:
example
mtr --suite=columnstore/basic mcs12_alter_table.test --extern socket=/var/lib/mysql/mysql.sock

Run by skipping list of tests:
example
mtr --force --skip-test-list=failed.def --suite=columnstore/basic --extern socket=/var/lib/mysql/mysql.sock
failed.def file lists test names in separated lines.