Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid reusing columns among different named tuples #70103

Merged
merged 4 commits into from
Oct 21, 2024

Conversation

amosbird
Copy link
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Avoid reusing columns among different named tuples when evaluating tuple functions. This fixes #70022

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

CI Settings (Only check the boxes if you know what you are doing):

  • Allow: All Required Checks
  • Allow: Stateless tests
  • Allow: Stateful tests
  • Allow: Integration Tests
  • Allow: Performance tests
  • Allow: All Builds
  • Allow: batch 1, 2 for multi-batch jobs
  • Allow: batch 3, 4, 5, 6 for multi-batch jobs

  • Exclude: Style check
  • Exclude: Fast test
  • Exclude: All with ASAN
  • Exclude: All with TSAN, MSAN, UBSAN, Coverage
  • Exclude: All with aarch64, release, debug

  • Run only fuzzers related jobs (libFuzzer fuzzers, AST fuzzers, etc.)
  • Exclude: AST fuzzers

  • Do not test
  • Woolen Wolfdog
  • Upload binaries for special builds
  • Disable merge-commit
  • Disable CI cache

@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-bugfix Pull request with bugfix, not backported by default label Sep 29, 2024
@robot-clickhouse
Copy link
Member

robot-clickhouse commented Sep 29, 2024

This is an automated comment for commit e843bb9 with description of existing statuses. It's updated for the latest CI running

✅ Click here to open a full report in a separate page

Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
Bugfix validationChecks that either a new test (functional or integration) or there some changed tests that fail with the binary built on master branch✅ success
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@novikd novikd self-assigned this Sep 30, 2024
@novikd novikd added the analyzer Issues and pull-requests related to new analyzer label Sep 30, 2024
@fm4v fm4v added pr-backport Changes, backported to release branch. Do not use manually - automated use only! v24.7-must-backport v24.8-must-backport v24.9-must-backport labels Sep 30, 2024
Comment on lines 188 to 190
if (const DataTypeTuple * type_tuple = typeid_cast<const DataTypeTuple *>(function_node.getResultType().get()))
{
if (type_tuple->haveExplicitNames())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will likely not work in the distributed case because the query on the follower node won't have AS col_a and AS col_b for the tuple function argument. I think a proper fix would also include creating a cast operation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think that such code should check enable_named_columns_in_function_tuple setting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will likely not work in the distributed case because the query on the follower node won't have AS col_a and AS col_b for the tuple function argument. I think a proper fix would also include creating a cast operation.

It works because we do addConvertingActions in ReadFromRemote step. I've added a test case to verify this.

Also, I think that such code should check enable_named_columns_in_function_tuple setting.

Sure.

@amosbird amosbird force-pushed the fix-70022 branch 2 times, most recently from 571ba76 to d5359cd Compare October 10, 2024 01:09
{
if (i != 0)
s << ", ";
s << names[i];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing escaping.

@alexey-milovidov alexey-milovidov self-assigned this Oct 17, 2024
@Algunenano
Copy link
Member

A case that's not covered by this fix:

DROP TABLE IF EXISTS src;
DROP TABLE IF EXISTS target;
SET flatten_nested = 0;

CREATE TABLE src
(
    id UInt64,
    minmax Nested(
        min Float64,
        max Float64,
    )
)
ENGINE = MergeTree
ORDER BY (id);

CREATE TABLE target AS src;


INSERT INTO src VALUES (0, [(-10, 10)]);


INSERT INTO target
SELECT
    id,
    groupArray(tuple(bucket_min, bucket_max))
FROM
(
    SELECT
        id,
        minmax.1 AS bucket_min,
        minmax.2 AS bucket_max
    FROM
    (
        select
            id, arrayJoin(minmax) as minmax
        FROM src
    )
)
GROUP BY id;

SELECT * FROM target;
$ clickhouse local --queries-file repro.sql --enable_named_columns_in_function_tuple=0
0       [(-10,10)]
$ clickhouse local --queries-file repro.sql --enable_named_columns_in_function_tuple=1
0       [(0,0)]

I'm going to disable with setting by default (and backport) in the meantime.

@amosbird
Copy link
Collaborator Author

A case that's not covered by this fix:

create table x (t Tuple(a int, b int)) engine MergeTree order by ();
insert into x select (1 as a2, 2 as b2);
select * from x format JSONEachRow;

{"t":{"a":0,"b":0}}

We never support inserting Tuple(a2 int, b2 int) into Tuple(a int, b int), but it's fine to insert Tuple(int, int) into Tuple(a int, b int). I'm not sure what's the expected behavior. Maybe we should keep this feature disabled by default?

@alexey-milovidov alexey-milovidov added this pull request to the merge queue Oct 21, 2024
Merged via the queue into ClickHouse:master with commit 688c971 Oct 21, 2024
211 checks passed
@alexey-milovidov alexey-milovidov deleted the fix-70022 branch October 21, 2024 03:23
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 21, 2024
robot-ch-test-poll3 added a commit that referenced this pull request Oct 21, 2024
…0cf1c8f242c3fe583d6add0a86718

Cherry pick #70103 to 24.9: Avoid reusing columns among different named tuples
robot-clickhouse-ci-1 added a commit that referenced this pull request Oct 21, 2024
Backport #70103 to 24.9: Avoid reusing columns among different named tuples
robot-clickhouse added a commit that referenced this pull request Oct 21, 2024
…0cf1c8f242c3fe583d6add0a86718

Cherry pick #70103 to 24.7: Avoid reusing columns among different named tuples
robot-clickhouse added a commit that referenced this pull request Oct 21, 2024
…0cf1c8f242c3fe583d6add0a86718

Cherry pick #70103 to 24.8: Avoid reusing columns among different named tuples
@rschu1ze
Copy link
Member

Just for reference: Setting enable_named_columns_in_function_tuple was disabled here: #70833

@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 21, 2024
@alexey-milovidov
Copy link
Member

@amosbird, please enable it back in a subsequent pull request.

@amosbird
Copy link
Collaborator Author

please enable it back in a subsequent pull request.

@alexey-milovidov Sure. I'll mention this backward incompatibility in the following PR #70103 (comment)

robot-ch-test-poll3 added a commit that referenced this pull request Oct 22, 2024
Backport #70103 to 24.8: Avoid reusing columns among different named tuples
robot-ch-test-poll4 added a commit that referenced this pull request Oct 22, 2024
Backport #70103 to 24.7: Avoid reusing columns among different named tuples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer Issues and pull-requests related to new analyzer pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-backports-created-cloud pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo v24.7-must-backport v24.8-must-backport v24.9-must-backport
Projects
None yet
Development

Successfully merging this pull request may close these issues.

24.7 broke some queries using tuple() and NULLs
9 participants