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

implement pg_catalog.pg_type table #2392

Merged
merged 12 commits into from
Jan 16, 2024
Merged
17 changes: 16 additions & 1 deletion crates/glaredb/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,22 @@ impl RunCommand for SltArgs {
}

fn build_runtime(thread_label: &'static str) -> Result<Runtime> {
let runtime = Builder::new_multi_thread()
let mut builder = Builder::new_multi_thread();

// Bump the stack from the default 2MB.
//
// We reach the limit when planning a query
// with nested views.
//
// Note that Sean observed the stack size only reaching ~300KB when
// running in release mode, and so we don't need to bump this
// everywhere. However there's definitely improvements to stack
// usage that we can make.
// see <https://github.com/GlareDB/glaredb/issues/2390>
#[cfg(not(release))]
builder.thread_stack_size(4 * 1024 * 1024);

let runtime = builder
universalmind303 marked this conversation as resolved.
Show resolved Hide resolved
.thread_name_fn(move || {
static THREAD_ID: AtomicU64 = AtomicU64::new(0);
let id = THREAD_ID.fetch_add(1, Ordering::Relaxed);
Expand Down
99 changes: 72 additions & 27 deletions crates/sqlbuiltins/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,32 +494,32 @@ pub static PG_ATTRIBUTE: Lazy<BuiltinView> = Lazy::new(|| BuiltinView {
name: "pg_attribute",
sql: "
SELECT
c.table_oid AS attrelid,
c.column_name AS attname,
null AS atttypeid,
null AS attstattarget,
null AS attlen,
null AS attnum,
null AS attndims,
null AS attcacheoff,
null AS atttypmod,
null AS attbyval,
null AS attalign,
null AS attstorage,
null AS attcompression,
null AS attnotnull,
null AS atthasdef,
null AS atthasmissing,
null AS attidentity,
null AS attgenerated,
null AS attisdropped,
null AS attislocal,
null AS attinhcount,
null AS attcollation,
null AS attacl,
null AS attoptions,
null AS attfdwoptions,
null AS attmissingval
null as attacl,
' ' as attalign,
false as attbyval,
0 as attcacheoff,
0 as attcollation,
' ' as attcompression,
null as attfdwoptions,
' ' as attgenerated,
false as atthasdef,
false as atthasmissing,
' ' as attidentity,
0 as attinhcount,
false as attisdropped,
false as attislocal,
0::smallint as attlen,
null as attmissingval,
'' as attname,
0 as attndims,
false as attnotnull,
0::smallint as attnum,
null as attoptions,
0 as attrelid,
0 as attstattarget,
' ' as attstorage,
0 as atttypid,
0 as atttypmod
FROM glare_catalog.columns c",
});

Expand Down Expand Up @@ -642,7 +642,51 @@ SELECT
FROM glare_catalog.views;
",
});

pub static PG_TYPE: Lazy<BuiltinView> = Lazy::new(|| BuiltinView {
schema: POSTGRES_SCHEMA,
name: "pg_type",
sql: "
SELECT

null as typacl,
0 as typndims,
0 as typcollation,
0 as oid,
0 as typnamespace,
0 as typowner,
0 as typlen,
false as typbyval,
'r' as typtype,
'r' as typcategory,
false as typispreferred,
false as typisdefined,
'r' as typdelim,
0 as typrelid,
0 as typsubscript,
0 as typelem,
0 as typarray,
0 as typinput,
0 as typoutput,
0 as typreceive,
0 as typsend,
0 as typmodin,
0 as typmodout,
0 as typanalyze,
'r' as typalign,
'r' as typstorage,
false as typnotnull,
0 as typbasetype,
0 as typtypmod,
'r' as typname,
null as typdefault,
null as typdefaultbin
FROM (VALUES (NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL)) WHERE false",
});
impl BuiltinView {
pub fn builtins() -> Vec<&'static BuiltinView> {
vec![
Expand All @@ -658,6 +702,7 @@ impl BuiltinView {
&PG_DATABASE,
&PG_TABLE,
&PG_VIEWS,
&PG_TYPE,
]
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/sqlexec/src/dispatch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ impl ViewPlanner for LocalSessionContext {
}))?
.build()?;
}

Ok(df_plan)
}
}
Expand Down
4 changes: 4 additions & 0 deletions testdata/sqllogictests/pg_catalog.slt
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ query TT
select schema_name, table_name from glare_catalog.tables where table_name = 'pg_description' and schema_name = 'pg_catalog_test';
----
pg_catalog_test pg_description


statement ok
select * from pg_catalog.pg_type;