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

Add SHOW WARNINGS support in MySQL interface #58929

Merged
merged 2 commits into from Jan 18, 2024

Conversation

slvrtrn
Copy link
Contributor

@slvrtrn slvrtrn commented Jan 17, 2024

SHOW WARNINGS is a rather popular query that is sent by a lot of different tools (DBeaver, DataGrip...) and, while it is almost always non-fatal if it fails, it produces unnecessary errors in the log.

This PR adds minimal support for it, so the statement does not fail. As discussed with @rschu1ze, we add it for compatibility reasons and with correct column definitions, though we always return an empty set.

See also: https://dev.mysql.com/doc/refman/8.0/en/show-warnings.html

Changelog category (leave one):

  • Improvement

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

MySQL interface gained compatibility with SHOW WARNINGS/SHOW COUNT(*) WARNINGS queries, though the returned result is always an empty set.

@slvrtrn slvrtrn requested a review from rschu1ze January 17, 2024 21:12
@slvrtrn slvrtrn added pr-improvement Pull request with some product improvements can be tested Allows running workflows for external contributors labels Jan 17, 2024
@robot-clickhouse-ci-1
Copy link
Contributor

robot-clickhouse-ci-1 commented Jan 17, 2024

This is an automated comment for commit 8658cd3 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
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker image for serversThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ 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. Integrational 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
Mergeable CheckChecks if all other necessary checks are successful✅ success
SQLTestThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
SQLancerFuzzing tests that detect logical bugs with SQLancer tool✅ success
SqllogicRun clickhouse on the sqllogic test set against sqlite and checks that all statements are passed✅ 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
Check nameDescriptionStatus
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR⏳ pending
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests❌ failure
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure
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❌ failure

@alexey-milovidov alexey-milovidov self-assigned this Jan 17, 2024
${MYSQL_CLIENT} --execute "show warnings;"
${MYSQL_CLIENT} --execute "SHOW WARNINGS LIMIT 100;"
${MYSQL_CLIENT} --execute "show warnings limit 100;"
${MYSQL_CLIENT} --execute "SHOW WARNINGS LIMIT 100 OFFSET 100;"
Copy link
Member

Choose a reason for hiding this comment

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

Looking at MySQL docs:

SHOW WARNINGS [LIMIT [offset,] row_count]

SHOW WARNINGS LIMIT 100, 50 (MySQL) is equivalent to SHOW WARNINGS LIMIT 100 OFFSET 50 (ClickHouse). Did you ever see syntax [offset,] row_count in logs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only saw plain SHOW WARNINGS so far.

${MYSQL_CLIENT} --execute "show warnings limit 100 offset 100;"
${MYSQL_CLIENT} --execute "SHOW COUNT(*) WARNINGS;"
${MYSQL_CLIENT} --execute "show count(*) warnings;"
${MYSQL_CLIENT} --execute "SELECT @@session.warning_count;"
Copy link
Member

Choose a reason for hiding this comment

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

@@session.warnings_count is a system variable in MySQL. My feeling is that re-implementing (even just faking) these in ClickHouse opens a can of worms.

If you did not see SELECT @@session.warning_count; in log files, I'd prefer to not provide compatibility with @@session.warning_count.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It already works even without this PR. I only added it to the test cause it's mentioned in the docs.

@@ -544,6 +548,18 @@ static bool isFederatedServerSetupSetCommand(const String & query)
return re2::RE2::FullMatch(query, expr);
}

/// Always return an empty set with appropriate column definitions for SHOW WARNINGS queries
Copy link
Member

Choose a reason for hiding this comment

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

Thoughts:

  • as the implementation is in MySQLHandler.cpp, I assume the statements work only through the MySQL port?
  • similarity, I was thinking whether the statements should be documented in docs/en/sql-reference/statements/show.md but maybe that's not necessary when exist only for the MySQL protocol
  • we are doing simple string comparisons (l. 91/92) to handle the statements. While matching is case-insensitive (good), statements with more than one whitespace (SHOW WARNINGS) are to the user's surprise not recognized but I guess this isn't terrible for our use case. Maybe you like to add a comment about that (l. 90 maybe?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

p.1 - yes, it works only via MySQL port.
p.2 - docs are probably not necessary, indeed.
p.3 is precisely why I am not very happy with the current implementation; it is fine for automatically generated statements (via tools), but it falls apart with any typos, like extra spaces. I'd say when we accumulate all the current fixes and related tests (including the rolled back #58835) AND if we have issues with queries matching (extra spaces, etc), we can think about a more sophisticated approach.

The extra spaces issue, in particular, is true for any query that was historically hardcoded into the MySQLHandler (I just added new ones in a similar fashion).

@rschu1ze rschu1ze merged commit cf115e6 into ClickHouse:master Jan 18, 2024
249 of 355 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can be tested Allows running workflows for external contributors pr-improvement Pull request with some product improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants