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 support for scanning views #44

Merged
merged 6 commits into from
Jun 18, 2024
Merged

Add support for scanning views #44

merged 6 commits into from
Jun 18, 2024

Conversation

Tishj
Copy link
Collaborator

@Tishj Tishj commented Jun 12, 2024

First we took the parse->rtable that Postgres has provided to us after parsing the query, then we looked through this list in the replacement scan, we returned this RangeTblEntry and used it for the Oid throughout execution of the scan.

The only benefit that the RangeTblEntry gave us was that it contained an alias for where it appeared in the query, but we don't need that, DuckDB already provides us the alias.

Internal details:
Inside the replacement scan we find the Oid given the name (schema+table), from there we check if this is a VIEW or not.
If it is, we look up the views definition and return a SubqueryRef that will get bound later, essentially rewriting:
select * from vw into select * from (select * from tbl)

Tishj added 4 commits June 10, 2024 15:14
…m it, which then gets bound, causing us to do another replacement scan on the table referenced by the view
…The only thing we're missing is the alias that was attached to the RangeTblEntry but since we are parsing the same query as Postgres, the alias should be resolved by the system anyways
@Tishj Tishj requested a review from mkaruza June 12, 2024 13:18
@Tishj
Copy link
Collaborator Author

Tishj commented Jun 12, 2024

@mkaruza any requests for tests, things that might require extra attention, pitfalls I haven't foreseen?

src/quack_heap_scan.cpp Show resolved Hide resolved
@mkaruza
Copy link
Collaborator

mkaruza commented Jun 13, 2024

@Tishj i left comments that i would need further discussion. Other i will try this today/tomorrow and provide you feedback if anything else is missing.

@mkaruza mkaruza self-requested a review June 17, 2024 08:08
Copy link
Collaborator

@mkaruza mkaruza left a comment

Choose a reason for hiding this comment

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

lgtm

@Tishj Tishj merged commit 726db29 into main Jun 18, 2024
2 checks passed
@Tishj Tishj deleted the replace_views branch June 18, 2024 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants