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: table resolving logic related to pg_catalog #4580

Merged

Conversation

J0HN50N133
Copy link
Contributor

refer to
#3560 (comment) and #4543

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

close #4543 and #3560 (comment).

What's changed and what's your intention?

!!! DO NOT LEAVE THIS BLOCK EMPTY !!!

This is a quiet huge change. Now query to catalog_manager have to bring a catalog_protocol arguments. So that, the catalog_manager can decide the table resolve logic according to the protocol.

Please explain IN DETAIL what the changes are in this PR and why they are needed:

  • Summarize your change (mandatory)
  • How does this PR work? Need a brief introduction for the changed logic (optional)
  • Describe clearly one logical change and avoid lazy messages (optional)
  • Describe any limitations of the current code (optional)

Checklist

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

Copy link
Contributor

coderabbitai bot commented Aug 17, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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 Aug 17, 2024
@J0HN50N133
Copy link
Contributor Author

@sunng87 could you check this pr. It a quiet big change and I'm not sure is it worth to do for such small feature? Or we could find a way that's affect less modules? Also, I wonder is it possible to specify protocol to pg in sqlness. The modification makes the sqlness test of pg_catalog unusable.

@sunng87
Copy link
Member

sunng87 commented Aug 17, 2024

Thank you so much for your effort.

We do have protocol information in QueryContext's channel field. Instead of adding new protocol type, I would suggest to reuse this channel enum. Another suggestion is to pass the whole QueryContextRef to catalog methods so we have more context information for future extensibility.

I'm not 100% sure if there is always a QueryContext when calling catalog methods, perhaps we can use Option<QueryContextRef> for catalog methods when it's missing.

@J0HN50N133
Copy link
Contributor Author

J0HN50N133 commented Aug 17, 2024

Thank you so much for your effort.

We do have protocol information in QueryContext's channel field. Instead of adding new protocol type, I would suggest to reuse this channel enum. Another suggestion is to pass the whole QueryContextRef to catalog methods so we have more context information for future extensibility.

I'm not 100% sure if there is always a QueryContext when calling catalog methods, perhaps we can use Option<QueryContextRef> for catalog methods when it's missing.

I'm pretty sure that there is no QueryContext in some call sites of Catalog's function. But it's a good idea to use Option<QueryContext>. I'll modify the implementation.

@J0HN50N133 J0HN50N133 force-pushed the pg_catalog_table_name_resolving branch from 93a9bb3 to 63da2ac Compare August 25, 2024 17:03
@J0HN50N133
Copy link
Contributor Author

J0HN50N133 commented Aug 25, 2024

@sunng87 I've updated the implementation to reuse the Channel type but encountered issues with sqlness tests. The pg_catalog schema is only accessible when using the PostgreSQL protocol, making it impossible to test its behavior through sqlness. While I could use integration tests, they seem unnecessary and cumbersome. To address this, I propose improving sqlness via sqlx, make it possible to specify protocol. Or we can control pg_catalog visibility with a private session variable named __PG_CATALOG_VISIBLE, which defaults to false. We would set it to true upon establishing a PostgreSQL connection and enable it in SQLness with SET __PG_CATALOG_VISIBLE = true. However, this introduces a new challenge: we don't always have access to QueryContext when querying the catalog manager, so we can't determine if pg_catalog should be visible. In summary, my solutions are: 1) Enhance sqlness to allow specifying the protocol via sqlx. 2) Use a session variable to control pg_catalog visibility, though accessing this variable isn't always feasible. I prefer the first one. WDYT?

@sunng87
Copy link
Member

sunng87 commented Aug 27, 2024

Sorry for being late. I have been travelling these days. The first approach sounds good to me. We also have some MySQL specific scenario to cover.

Another approach comes to my mind is to provide a http parameter to override the Channel to postgres or mysql. We can also add a sqlness directive to tell sqlness runner to use this parameter when sending SQL commands.

But I think it can be implemented in a separated patch.

@J0HN50N133
Copy link
Contributor Author

Can we just push forward this pr and keep the the pg specific behaviors untested for a while? I will try to improve sqlness in another patch.

@sunng87
Copy link
Member

sunng87 commented Aug 27, 2024

I think so. Current tests should guarantee that it will not break existed functionalities.

@J0HN50N133 J0HN50N133 marked this pull request as ready for review September 2, 2024 06:03
@J0HN50N133 J0HN50N133 requested review from evenyag and a team as code owners September 2, 2024 06:03
@J0HN50N133
Copy link
Contributor Author

@sunng87 This pr is now ready for reviewed.

Copy link
Member

@sunng87 sunng87 left a comment

Choose a reason for hiding this comment

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

Thank you for the effort. It looks good to me mostly except the one I left comment.

@sunng87 sunng87 requested a review from WenyXu September 3, 2024 21:21
@sunng87
Copy link
Member

sunng87 commented Sep 3, 2024

@J0HN50N133 seems we still have a test to fix.

@killme2008 @fengjiachun @WenyXu @evenyag PTAL when you got time.

Copy link

codecov bot commented Sep 4, 2024

Codecov Report

Attention: Patch coverage is 75.87940% with 48 lines in your changes missing coverage. Please review.

Project coverage is 84.56%. Comparing base (8d6cd8a) to head (cd817a4).
Report is 22 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4580      +/-   ##
==========================================
- Coverage   84.88%   84.56%   -0.33%     
==========================================
  Files        1105     1105              
  Lines      199116   199280     +164     
==========================================
- Hits       169023   168519     -504     
- Misses      30093    30761     +668     

@tisonkun tisonkun added this pull request to the merge queue Sep 9, 2024
Merged via the queue into GreptimeTeam:main with commit a8477e4 Sep 9, 2024
32 checks passed
CookiePieWw pushed a commit to CookiePieWw/greptimedb that referenced this pull request Sep 17, 2024
* fix: table resolving logic related to pg_catalog

refer to
GreptimeTeam#3560 (comment)
and GreptimeTeam#4543

* refactor: remove CatalogProtocol type

* fix: sqlness

* fix: forbid create database pg_catalog with mysql client

* refactor: use QueryContext as arguments rather than Channel

* refactor: pass None as default behaviour in information_schema

* test: fix test
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.

Make pg_catalog schema visible only when client connect from Postgres protocol
3 participants