mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-18 04:12:19 +00:00
fix usage of index with array columns and ARRAY JOIN
This commit is contained in:
parent
8ba6a5393f
commit
ffa56bde24
@ -423,6 +423,9 @@ KeyCondition::KeyCondition(
|
|||||||
*/
|
*/
|
||||||
Block block_with_constants = getBlockWithConstants(query_info.query, query_info.syntax_analyzer_result, context);
|
Block block_with_constants = getBlockWithConstants(query_info.query, query_info.syntax_analyzer_result, context);
|
||||||
|
|
||||||
|
for (const auto & [name, _] : query_info.syntax_analyzer_result->array_join_result_to_source)
|
||||||
|
array_joined_columns.insert(name);
|
||||||
|
|
||||||
const ASTSelectQuery & select = query_info.query->as<ASTSelectQuery &>();
|
const ASTSelectQuery & select = query_info.query->as<ASTSelectQuery &>();
|
||||||
if (select.where() || select.prewhere())
|
if (select.where() || select.prewhere())
|
||||||
{
|
{
|
||||||
@ -610,6 +613,10 @@ bool KeyCondition::canConstantBeWrappedByMonotonicFunctions(
|
|||||||
DataTypePtr & out_type)
|
DataTypePtr & out_type)
|
||||||
{
|
{
|
||||||
String expr_name = node->getColumnNameWithoutAlias();
|
String expr_name = node->getColumnNameWithoutAlias();
|
||||||
|
|
||||||
|
if (array_joined_columns.count(expr_name))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (key_subexpr_names.count(expr_name) == 0)
|
if (key_subexpr_names.count(expr_name) == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -714,6 +721,9 @@ bool KeyCondition::canConstantBeWrappedByFunctions(
|
|||||||
{
|
{
|
||||||
String expr_name = ast->getColumnNameWithoutAlias();
|
String expr_name = ast->getColumnNameWithoutAlias();
|
||||||
|
|
||||||
|
if (array_joined_columns.count(expr_name))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (key_subexpr_names.count(expr_name) == 0)
|
if (key_subexpr_names.count(expr_name) == 0)
|
||||||
{
|
{
|
||||||
/// Let's check another one case.
|
/// Let's check another one case.
|
||||||
@ -1075,6 +1085,9 @@ bool KeyCondition::isKeyPossiblyWrappedByMonotonicFunctionsImpl(
|
|||||||
// Key columns should use canonical names for index analysis
|
// Key columns should use canonical names for index analysis
|
||||||
String name = node->getColumnNameWithoutAlias();
|
String name = node->getColumnNameWithoutAlias();
|
||||||
|
|
||||||
|
if (array_joined_columns.count(name))
|
||||||
|
return false;
|
||||||
|
|
||||||
auto it = key_columns.find(name);
|
auto it = key_columns.find(name);
|
||||||
if (key_columns.end() != it)
|
if (key_columns.end() != it)
|
||||||
{
|
{
|
||||||
|
@ -459,6 +459,8 @@ private:
|
|||||||
const ExpressionActionsPtr key_expr;
|
const ExpressionActionsPtr key_expr;
|
||||||
/// All intermediate columns are used to calculate key_expr.
|
/// All intermediate columns are used to calculate key_expr.
|
||||||
const NameSet key_subexpr_names;
|
const NameSet key_subexpr_names;
|
||||||
|
|
||||||
|
NameSet array_joined_columns;
|
||||||
PreparedSets prepared_sets;
|
PreparedSets prepared_sets;
|
||||||
|
|
||||||
// If true, always allow key_expr to be wrapped by function
|
// If true, always allow key_expr to be wrapped by function
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
a c
|
10
tests/queries/0_stateless/01922_array_join_with_index.sql
Normal file
10
tests/queries/0_stateless/01922_array_join_with_index.sql
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
DROP TABLE IF EXISTS t_array_index;
|
||||||
|
|
||||||
|
CREATE TABLE t_array_index (n Nested(key String, value String))
|
||||||
|
ENGINE = MergeTree ORDER BY n.key;
|
||||||
|
|
||||||
|
INSERT INTO t_array_index VALUES (['a', 'b'], ['c', 'd']);
|
||||||
|
|
||||||
|
SELECT * FROM t_array_index ARRAY JOIN n WHERE n.key = 'a';
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS t_array_index;
|
Loading…
Reference in New Issue
Block a user