-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for scanning views (#44)
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)`
- Loading branch information
Showing
8 changed files
with
166 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,3 +67,4 @@ SELECT count(*) FROM public.t, other.t; | |
DROP TABLE other.t; | ||
DROP SCHEMA other; | ||
RESET search_path; | ||
drop table t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
create table view_table(a varchar); | ||
insert into view_table values ('test'), ('hello'); | ||
create view vw as select * from view_table; | ||
select * from vw; | ||
a | ||
------- | ||
test | ||
hello | ||
(2 rows) | ||
|
||
select * from vw offset 1; | ||
a | ||
------- | ||
hello | ||
(1 row) | ||
|
||
select * from vw limit 1; | ||
a | ||
------ | ||
test | ||
(1 row) | ||
|
||
drop view vw; | ||
create schema s; | ||
create table s.t as select 21; | ||
create table "s.t" as select 42; | ||
create view vw1 as select * from s.t; | ||
create view vw2 as select * from "s.t"; | ||
select * from vw1, vw2; | ||
?column? | ?column? | ||
----------+---------- | ||
21 | 21 | ||
(1 row) | ||
|
||
drop view vw1; | ||
drop view vw2; | ||
drop table "s.t"; | ||
drop table s.t; | ||
drop schema s; | ||
drop table view_table; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
create table view_table(a varchar); | ||
insert into view_table values ('test'), ('hello'); | ||
|
||
create view vw as select * from view_table; | ||
|
||
select * from vw; | ||
select * from vw offset 1; | ||
select * from vw limit 1; | ||
|
||
drop view vw; | ||
|
||
create schema s; | ||
create table s.t as select 21; | ||
create table "s.t" as select 42; | ||
|
||
create view vw1 as select * from s.t; | ||
create view vw2 as select * from "s.t"; | ||
|
||
select * from vw1, vw2; | ||
|
||
drop view vw1; | ||
drop view vw2; | ||
drop table "s.t"; | ||
drop table s.t; | ||
drop schema s; | ||
drop table view_table; |