Fix incorrect rows_before_limit_at_least with subquery in

This commit is contained in:
Amos Bird 2024-05-09 14:43:37 +08:00
parent 8a07f4cdcc
commit a8aa5fa3f6
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
5 changed files with 78 additions and 35 deletions

View File

@ -19,6 +19,7 @@
#include <Processors/Transforms/AggregatingInOrderTransform.h>
#include <Processors/Transforms/AggregatingTransform.h>
#include <Processors/Transforms/CountingTransform.h>
#include <Processors/Transforms/CreatingSetsTransform.h>
#include <Processors/Transforms/ExpressionTransform.h>
#include <Processors/Transforms/LimitsCheckingTransform.h>
#include <Processors/Transforms/MaterializingTransform.h>
@ -240,6 +241,10 @@ static void initRowsBeforeLimit(IOutputFormat * output_format)
continue;
}
/// Skip CreatingSetsTransform
if (typeid_cast<CreatingSetsTransform *>(processor))
continue;
if (limit_processor == processor)
{
ssize_t i = 0;

View File

@ -1,26 +0,0 @@
{
"meta":
[
{
"name": "age",
"type": "Int16"
}
],
"data":
[
{
"age": 33
},
{
"age": 48
},
{
"age": 50
}
],
"rows": 3,
"rows_before_limit_at_least": 3
}

View File

@ -1,9 +0,0 @@
DROP TABLE IF EXISTS users;
CREATE TABLE users (uid Int16, name String, age Int16) ENGINE=MergeTree order by uid;
INSERT INTO users VALUES (1231, 'John', 33),(6666, 'John', 48), (8888, 'John', 50);
SELECT age FROM remote('127.0.0.{2,3}', currentDatabase(), users) group by age limit 20 format JSON SETTINGS output_format_write_statistics=0;
DROP TABLE users;

View File

@ -0,0 +1,52 @@
{
"meta":
[
{
"name": "age",
"type": "Int16"
}
],
"data":
[
{
"age": 33
},
{
"age": 48
},
{
"age": 50
}
],
"rows": 3,
"rows_before_limit_at_least": 3
}
{
"meta":
[
{
"name": "service_name",
"type": "String"
}
],
"data":
[
{
"service_name": "service1"
},
{
"service_name": "service2"
},
{
"service_name": "service3"
}
],
"rows": 3,
"rows_before_limit_at_least": 3
}

View File

@ -0,0 +1,21 @@
DROP TABLE IF EXISTS users;
CREATE TABLE users (uid Int16, name String, age Int16) ENGINE=MergeTree ORDER BY uid;
INSERT INTO users VALUES (1231, 'John', 33),(6666, 'John', 48), (8888, 'John', 50);
SELECT age FROM remote('127.0.0.{2,3}', currentDatabase(), users) GROUP BY age LIMIT 20 FORMAT JSON SETTINGS output_format_write_statistics=0;
DROP TABLE users;
DROP TABLE IF EXISTS test_rows_count_bug_local;
CREATE TABLE test_rows_count_bug_local (id UUID DEFAULT generateUUIDv4(), service_name String, path String) ENGINE=MergeTree ORDER BY tuple();
INSERT INTO test_rows_count_bug_local (service_name, path) VALUES ('service1', '/foo/1'), ('service1', '/foo/2'), ('service2', '/foo/3'), ('service2', '/foo/4'), ('service3', '/foo/5');
SELECT service_name FROM test_rows_count_bug_local
WHERE id global in (select id from remote('127.0.0.{2,3}', currentDatabase(), test_rows_count_bug_local))
GROUP BY service_name ORDER BY service_name limit 20 FORMAT JSON SETTINGS output_format_write_statistics=0;
DROP TABLE test_rows_count_bug_local;