mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Backport #71089 to 24.10: Proj LWD Rebuild Respects Deleted Rows
This commit is contained in:
parent
3c594012d3
commit
1c37e50a57
@ -294,8 +294,22 @@ Block ProjectionDescription::calculate(const Block & block, ContextPtr context)
|
||||
mut_context->setSetting("aggregate_functions_null_for_empty", Field(0));
|
||||
mut_context->setSetting("transform_null_in", Field(0));
|
||||
|
||||
ASTPtr query_ast_copy = nullptr;
|
||||
/// Respect the _row_exists column.
|
||||
if (block.findByName("_row_exists"))
|
||||
{
|
||||
query_ast_copy = query_ast->clone();
|
||||
auto * select_row_exists = query_ast_copy->as<ASTSelectQuery>();
|
||||
if (!select_row_exists)
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot get ASTSelectQuery when adding _row_exists = 1. It's a bug");
|
||||
|
||||
select_row_exists->setExpression(
|
||||
ASTSelectQuery::Expression::WHERE,
|
||||
makeASTFunction("equals", std::make_shared<ASTIdentifier>("_row_exists"), std::make_shared<ASTLiteral>(1)));
|
||||
}
|
||||
|
||||
auto builder = InterpreterSelectQuery(
|
||||
query_ast,
|
||||
query_ast_copy ? query_ast_copy : query_ast,
|
||||
mut_context,
|
||||
Pipe(std::make_shared<SourceFromSingleChunk>(block)),
|
||||
SelectQueryOptions{
|
||||
|
@ -0,0 +1 @@
|
||||
34 1
|
@ -0,0 +1,20 @@
|
||||
DROP TABLE IF EXISTS users;
|
||||
|
||||
CREATE TABLE users (
|
||||
uid Int16,
|
||||
name String,
|
||||
age Int16,
|
||||
projection p1 (select age, count() group by age),
|
||||
) ENGINE = MergeTree order by uid
|
||||
SETTINGS lightweight_mutation_projection_mode = 'rebuild';
|
||||
|
||||
INSERT INTO users VALUES (1231, 'John', 33), (1232, 'Mary', 34);
|
||||
|
||||
DELETE FROM users WHERE uid = 1231;
|
||||
|
||||
SELECT
|
||||
age,
|
||||
count()
|
||||
FROM users
|
||||
GROUP BY age
|
||||
SETTINGS optimize_use_projections = 1, force_optimize_projection = 1;
|
Loading…
Reference in New Issue
Block a user