Details
-
Bug
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Fixed
-
10.5.12, 10.4(EOL), 10.6
Description
How to reproduce:
SET @@session.spider_same_server_link = ON; |
|
|
GRANT ALL PRIVILEGES ON *.* TO 'spinne'@'127.0.0.1' IDENTIFIED BY 'Widow2021!'; |
|
DROP SERVER data1; |
|
CREATE SERVER IF NOT EXISTS data1 |
|
FOREIGN DATA WRAPPER mysql |
OPTIONS(
|
HOST '127.0.0.1', |
DATABASE 'test', |
USER 'spinne', |
PORT 3307,
|
PASSWORD 'Widow2021!' |
);
|
|
DROP DATABASE IF EXISTS auto_test_local; |
DROP DATABASE IF EXISTS auto_test_remote; |
|
CREATE DATABASE auto_test_local; |
USE auto_test_local; |
CREATE TABLE IF NOT EXISTS `sp` ( |
`c1` varchar(10) NOT NULL, |
`c2` varchar(17) NOT NULL, |
`c3` datetime NOT NULL DEFAULT '0001-01-01 00:00:00', |
PRIMARY KEY (`c1`,`c2`,`c3`) |
) ENGINE=SPIDER DEFAULT CHARSET=utf8 COMMENT='wrapper "mariadb", table "sp"' |
PARTITION BY LIST COLUMNS(`c2`) |
(PARTITION `pt1` DEFAULT COMMENT = 'srv "data1"' ENGINE = SPIDER); |
|
CREATE DATABASE auto_test_remote; |
USE auto_test_remote; |
CREATE TABLE IF NOT EXISTS `sp` ( |
`c1` varchar(10) NOT NULL, |
`c2` varchar(17) NOT NULL, |
`c3` datetime NOT NULL DEFAULT '0001-01-01 00:00:00', |
PRIMARY KEY (`c1`,`c2`,`c3`) |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8 |
PARTITION BY RANGE COLUMNS(`c3`) |
(PARTITION `pmax` VALUES LESS THAN (MAXVALUE) ENGINE = InnoDB); |
|
INSERT INTO auto_test_remote.sp VALUES |
('00166','1','2020-05-05 00:00:00'), |
('00166','2','2020-05-03 00:00:00'), |
('00166','3','2020-05-02 00:00:00'), |
('00166','4','2020-05-01 00:00:00'), |
('00166','5','2020-05-06 00:00:00'), |
('00174','6','2020-05-06 00:00:00'), |
('00174','7','2020-05-06 00:00:00'), |
('00174','8','2020-05-04 00:00:00'); |
|
SELECT MIN(c2),c1 FROM auto_test_local.sp WHERE c1='00166'; |
Result of c2 is not correct, resultset have 5 times the same value for c2.
MariaDB > SELECT MIN(c2),c1 FROM auto_test_local.sp WHERE c1='00166'; |
+---------+-------+ |
| MIN(c2) | c1 | |
+---------+-------+ |
| 1 | 00166 |
|
| 1 | 00166 |
|
| 1 | 00166 |
|
| 1 | 00166 |
|
| 1 | 00166 |
|
+---------+-------+ |
5 rows in set (0.042 sec) |
Attachments
Issue Links
- causes
-
MDEV-35422 mysqld got signal 11 after SELECT DISTINCT
-
- Closed
-
-
MDEV-35874 Unexpected error 1264 'Out of Range Value for Column' when inserting into ... select ... from a spider table
-
- Closed
-
- is blocked by
-
MDEV-33100 Backport MDEV-20468 to 10.4
-
- Closed
-
- is caused by
-
MDEV-20502 Queries against spider tables return wrong values for columns following constant declarations.
-
- Closed
-
- relates to
-
MDEV-29546 spider group by handler wrong result on order by aggregate
-
- Closed
-
The idea of adding distinct in case of implicit groupin (as in nayuta's patch) is incorrect, and here's a counterexample:
# 2 1 2
# 2 1 1
The real issue is the spider GBH skipping of const items (MIN(b) in the example) and sending something like select distinct a, c from t1 ....
The natural fix would be that GBH does not exclude const items in the queries sent to the data node (in this test case, it would mean the implicit grouping in the query sent by spider, causing correctly only one row to be returned). It would also require spider to discard the result from the const item select when storing results to the temp table fields, because the sql layer does not include these fields in the temp table construction, and not discarding will cause a shift to the right.
To summarise, spider GBH can fail when selecting auxiliary fields (see the previous comment), not skipping constant (will cause a shift to the right in the result of the tests of this issue, as well as those of
MDEV-29502/MDEV-20502), or skipping constant (the testcase in this comment). These issues are illustrated as follows:C: const; x, y, z: original select; a, b: auxiliary;
query->select: a C b x y C z
send res join->fields: x y C z
temp table->field: a b x y z
spider execute select: a b x y z
spider store results: a b x y z
To remove the fragility, it seems that a sensible solution is to make spider send a query as faithful to the original query as possible, i.e.
spider execute select: x y C z
spider store results: x y z
Note also
MDEV-33704where the change was that group by handlers are skipped when all tables are const.