move our dbsp-based views to materialized views

We will implement normal SQLite-style view-as-an-alias for
compatibility, and will call our incremental views materialized views.
This commit is contained in:
Glauber Costa
2025-08-12 14:06:19 -05:00
parent a6247e891f
commit 770f86e490
6 changed files with 65 additions and 23 deletions

View File

@@ -391,6 +391,29 @@ impl ToTokens for Stmt {
s.append(TK_AS, None)?;
select.to_tokens_with_context(s, context)
}
Self::CreateMaterializedView {
if_not_exists,
view_name,
columns,
select,
} => {
s.append(TK_CREATE, None)?;
s.append(TK_MATERIALIZED, None)?;
s.append(TK_VIEW, None)?;
if *if_not_exists {
s.append(TK_IF, None)?;
s.append(TK_NOT, None)?;
s.append(TK_EXISTS, None)?;
}
view_name.to_tokens_with_context(s, context)?;
if let Some(columns) = columns {
s.append(TK_LP, None)?;
comma(columns, s, context)?;
s.append(TK_RP, None)?;
}
s.append(TK_AS, None)?;
select.to_tokens_with_context(s, context)
}
Self::CreateVirtualTable(create_virtual_table) => {
let CreateVirtualTable {
if_not_exists,

View File

@@ -130,6 +130,17 @@ pub enum Stmt {
/// query
select: Box<Select>,
},
/// `CREATE MATERIALIZED VIEW`
CreateMaterializedView {
/// `IF NOT EXISTS`
if_not_exists: bool,
/// view name
view_name: QualifiedName,
/// columns
columns: Option<Vec<IndexedColumn>>,
/// query
select: Box<Select>,
},
/// `CREATE VIRTUAL TABLE`
CreateVirtualTable(Box<CreateVirtualTable>),
/// `DELETE`

View File

@@ -478,6 +478,11 @@ cmd ::= createkw temp(T) VIEW ifnotexists(E) fullname(Y) eidlist_opt(C)
self.ctx.stmt = Some(Stmt::CreateView{ temporary: T, if_not_exists: E, view_name: Y, columns: C,
select: Box::new(S) });
}
cmd ::= createkw MATERIALIZED VIEW ifnotexists(E) fullname(Y) eidlist_opt(C)
AS select(S). {
self.ctx.stmt = Some(Stmt::CreateMaterializedView{ if_not_exists: E, view_name: Y, columns: C,
select: Box::new(S) });
}
cmd ::= DROP VIEW ifexists(E) fullname(X). {
self.ctx.stmt = Some(Stmt::DropView{ if_exists: E, view_name: X });
}