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

fix: scan hint checks order asc #4365

Merged
merged 7 commits into from
Jul 15, 2024

Conversation

evenyag
Copy link
Contributor

@evenyag evenyag commented Jul 15, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

What's changed and what's your intention?

The scan hint optimizer should ensure the sort expr is asc instead of desc.

This PR also fixes some unstable sqlness tests.

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.

Summary by CodeRabbit

  • New Features

    • Added SQL queries for creating, inserting, analyzing, and dropping tables, enhancing database testing capabilities.
  • Enhancements

    • Updated SQL query handling to include explain analyze and last_value functions for more detailed query analysis.
    • Improved sorting logic in ScanHintVisitor to enforce constraints on column references for last_value() functions.
  • Tests

    • Implemented new test cases for database operations to ensure the robustness of the new SQL queries and sorting logic.

Copy link
Contributor

coderabbitai bot commented Jul 15, 2024

Walkthrough

The recent changes primarily focus on SQL query optimizations and adjustments to SQL analysis processes. A new SQL query with an explain analyze statement was added, replacing a previously commented-out section. Additionally, the logic related to sorting expressions in the ScanHintVisitor was refined to ensure last_value() functions correctly represent the maximum value of a column by allowing only specific order by clauses.

Changes

File Path Change Summary
tests/cases/standalone/optimizer/last_value.result Added SQL queries for table creation, data insertion, query analysis, and table deletion.
tests/cases/standalone/optimizer/last_value.sql Replaced a commented-out section with a new SQL query using explain analyze and last_value functions.
src/query/src/optimizer/scan_hint.rs Updated sorting logic in ScanHintVisitor to allow only order by xxx where xxx is a bare column reference.

Poem

In lines of SQL, the changes flow,
Optimizing ways to help data grow.
A whisper of last_value, order by neat,
Tables created, analyzed, a task complete.
Code refined, queries run,
SQL victories, one by one.
🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Jul 15, 2024
@evenyag evenyag marked this pull request as ready for review July 15, 2024 03:39
@evenyag evenyag requested review from v0y4g3r, waynexia and a team as code owners July 15, 2024 03:39
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4b8b04f and af7b54f.

Files selected for processing (13)
  • src/mito2/src/read/scan_region.rs (2 hunks)
  • src/mito2/src/read/seq_scan.rs (1 hunks)
  • src/mito2/src/read/unordered_scan.rs (1 hunks)
  • src/query/src/optimizer/scan_hint.rs (2 hunks)
  • src/store-api/src/storage/requests.rs (1 hunks)
  • tests/cases/standalone/common/show/show_databases_tables.result (1 hunks)
  • tests/cases/standalone/common/show/show_databases_tables.sql (1 hunks)
  • tests/cases/standalone/common/system/information_schema.result (1 hunks)
  • tests/cases/standalone/common/system/information_schema.sql (1 hunks)
  • tests/cases/standalone/common/view/create.result (1 hunks)
  • tests/cases/standalone/common/view/create.sql (1 hunks)
  • tests/cases/standalone/optimizer/last_value.result (1 hunks)
  • tests/cases/standalone/optimizer/last_value.sql (1 hunks)
Files skipped from review due to trivial changes (4)
  • tests/cases/standalone/common/show/show_databases_tables.sql
  • tests/cases/standalone/common/system/information_schema.sql
  • tests/cases/standalone/common/view/create.result
  • tests/cases/standalone/common/view/create.sql
Additional comments not posted (11)
tests/cases/standalone/optimizer/last_value.sql (1)

19-26: Ensure the last_value function is used correctly.

The last_value function is used with an order by clause to ensure the correct value is selected. Verify that the ts column is indexed and that the optimizer correctly handles this query.

Verification successful

The last_value function is used correctly, and the ts column is indexed.

  • The ts column is indexed in the relevant create table statements.
  • The last_value function is used with the order by ts clause correctly.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the `last_value` function usage and indexing of `ts` column.

# Test: Check if `ts` column is indexed. Expect: Index on `ts` column.
rg --type sql -A 5 $'create table t (\n    ts timestamp time index,'

Length of output: 341


Script:

#!/bin/bash
# Description: Verify the `last_value` function usage and indexing of `ts` column.

# Test: Check if `ts` column is indexed. Expect: Index on `ts` column.
rg --type sql -A 5 'create table t' | grep -i 'ts timestamp'

# Test: Verify the usage of `last_value` function in the SQL query.
rg --type sql 'last_value'

Length of output: 4946

src/store-api/src/storage/requests.rs (1)

17-17: LGTM! The Display trait addition is appropriate.

The addition of the Display trait to the TimeSeriesRowSelector enum is a useful enhancement for formatted output.

tests/cases/standalone/optimizer/last_value.result (1)

1-51: Verify the expected results for the explain analyze query.

The expected results for the explain analyze query with last_value functions should be verified to ensure accuracy. Ensure that the query plan and results match the expected behavior.

tests/cases/standalone/common/show/show_databases_tables.result (1)

107-108: Ensure regex replacements are accurate.

The regex replacements for datetime and whitespace matching should be verified to ensure they correctly match the expected patterns.

src/mito2/src/read/unordered_scan.rs (1)

217-217: Method name change looks good.

The method name format_parts has been changed to format_for_explain to better reflect its purpose.

src/query/src/optimizer/scan_hint.rs (1)

215-217: Order by expression validation looks good.

The conditions ensure that the order by expression is in ascending order and is a bare column reference, which is necessary for the last_value function.

src/mito2/src/read/seq_scan.rs (1)

451-451: Method name change looks good.

The method name format_parts has been changed to format_for_explain to better reflect its purpose.

src/mito2/src/read/scan_region.rs (1)

Line range hint 820-842:
Method name change looks good.

The method name format_parts has been changed to format_for_explain to better reflect its purpose.

tests/cases/standalone/common/system/information_schema.result (3)

7-7: Regex pattern for datetime matching looks good.

The pattern (\s[\-0-9T:\.]{15,}) is appropriate for matching datetime strings.


8-8: Regex pattern for whitespace matching looks good.

The pattern [\u0020\-]+ is appropriate for matching whitespace characters.


14-48: Table data additions look good.

The table data in the information_schema.tables table is consistent and correct. The datetime values are standardized to DATETIME.

@evenyag evenyag mentioned this pull request Jul 15, 2024
13 tasks
Copy link

codecov bot commented Jul 15, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 84.86%. Comparing base (15ac811) to head (fcf67c8).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4365      +/-   ##
==========================================
- Coverage   85.15%   84.86%   -0.29%     
==========================================
  Files        1063     1064       +1     
  Lines      189987   190003      +16     
==========================================
- Hits       161782   161255     -527     
- Misses      28205    28748     +543     

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between af7b54f and 22aa5d0.

Files selected for processing (2)
  • tests/cases/standalone/optimizer/last_value.result (1 hunks)
  • tests/cases/standalone/optimizer/last_value.sql (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/cases/standalone/optimizer/last_value.result
Additional comments not posted (2)
tests/cases/standalone/optimizer/last_value.sql (2)

19-20: Ensure redacted content is handled correctly.

The comments indicate redacted replacements for metrics and partitioning. Ensure that these replacements are handled correctly in the actual implementation.


21-27: Verify the explain analyze statement and select query.

The explain analyze statement is correctly used to analyze the query performance. The select query utilizes last_value functions with an order by ts clause and groups by host. Ensure that the last_value functions and the order by ts clause are correctly implemented to achieve the desired ascending sort order.

Co-authored-by: Ruihang Xia <waynestxia@gmail.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 22aa5d0 and fcf67c8.

Files selected for processing (1)
  • src/query/src/optimizer/scan_hint.rs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/query/src/optimizer/scan_hint.rs

@WenyXu WenyXu added this pull request to the merge queue Jul 15, 2024
Merged via the queue into GreptimeTeam:main with commit 20d9c0a Jul 15, 2024
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants