Details
-
Task
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
-
None
-
Columnstore_commit_hash = 1122b64
Columnstore_version = 23.10.0
Description
SELECT non-aggregated column with GROUP BY query result differs from InnoDB.
Repro:
CREATE TABLE products (
product_id INT,
product_name VARCHAR(100),
category VARCHAR(50),
unit_price DECIMAL(10, 2),
stock_quantity INT
) ENGINE=InnoDB/Columnstore;
INSERT INTO products VALUES
(1, 'Laptop', 'Electronics', 1200.00, 50),
(2, 'Smartphone', 'Electronics', 800.00, 100),
(3, 'Coffee Maker', 'Appliances', 50.00, 30),
(4, 'Backpack', 'Fashion', 40.00, 80),
(5, 'Desk Chair', 'Furniture', 150.00, 20);
MariaDB-InnoDB> SELECT product_name, SUM(stock_quantity) AS total_stock FROM products GROUP BY category ORDER BY stock_quantity;
-------------------------+
| product_name | total_stock |
-------------------------+
| Desk Chair | 20 |
| Coffee Maker | 30 |
| Laptop | 150 |
| Backpack | 80 |
-------------------------+
4 rows in set (0.001 sec)
MariaDB-Columnstore> SELECT product_name, SUM(stock_quantity) AS total_stock FROM products GROUP BY category ORDER BY stock_quantity;
-------------------------+
| product_name | total_stock |
-------------------------+
| Backpack | 80 |
| Coffee Maker | 30 |
| Desk Chair | 20 |
| Smartphone | 150 |
-------------------------+
4 rows in set (0.020 sec)
FYI, MySQL doesn't allow such queries.
mysql8.0-InnoDB> SELECT product_name, SUM(stock_quantity) AS total_stock FROM products GROUP BY category ORDER BY stock_quantity;
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.products.product_name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by