fix: pg_graphql performance (#3204)
This commit is contained in:
@ -16,6 +16,60 @@ CREATE FUNCTION graphql."_internal_resolve"(
|
|||||||
LANGUAGE c /* Rust */
|
LANGUAGE c /* Rust */
|
||||||
AS 'MODULE_PATHNAME', 'resolve_wrapper';
|
AS 'MODULE_PATHNAME', 'resolve_wrapper';
|
||||||
|
|
||||||
|
-- src/lib.rs:19
|
||||||
|
-- Is updated every time the schema changes
|
||||||
|
create sequence if not exists graphql.seq_schema_version as int cycle;
|
||||||
|
|
||||||
|
create or replace function graphql.increment_schema_version()
|
||||||
|
returns event_trigger
|
||||||
|
security definer
|
||||||
|
language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
perform nextval('graphql.seq_schema_version');
|
||||||
|
end;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
create or replace function graphql.get_schema_version()
|
||||||
|
returns int
|
||||||
|
security definer
|
||||||
|
language sql
|
||||||
|
as $$
|
||||||
|
select last_value from graphql.seq_schema_version;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
-- On DDL event, increment the schema version number
|
||||||
|
create event trigger graphql_watch_ddl
|
||||||
|
on ddl_command_end
|
||||||
|
execute procedure graphql.increment_schema_version();
|
||||||
|
|
||||||
|
create event trigger graphql_watch_drop
|
||||||
|
on sql_drop
|
||||||
|
execute procedure graphql.increment_schema_version();
|
||||||
|
|
||||||
|
|
||||||
|
-- src/lib.rs:20
|
||||||
|
create function graphql.comment_directive(comment_ text)
|
||||||
|
returns jsonb
|
||||||
|
language sql
|
||||||
|
immutable
|
||||||
|
as $$
|
||||||
|
/*
|
||||||
|
comment on column public.account.name is '@graphql.name: myField'
|
||||||
|
*/
|
||||||
|
select
|
||||||
|
coalesce(
|
||||||
|
(
|
||||||
|
regexp_match(
|
||||||
|
comment_,
|
||||||
|
'@graphql\((.+?)\)'
|
||||||
|
)
|
||||||
|
)[1]::jsonb,
|
||||||
|
jsonb_build_object()
|
||||||
|
)
|
||||||
|
$$;
|
||||||
|
|
||||||
|
|
||||||
-- src/lib.rs:22
|
-- src/lib.rs:22
|
||||||
-- requires:
|
-- requires:
|
||||||
-- resolve
|
-- resolve
|
||||||
@ -50,28 +104,6 @@ end;
|
|||||||
$$;
|
$$;
|
||||||
|
|
||||||
|
|
||||||
-- src/lib.rs:20
|
|
||||||
create function graphql.comment_directive(comment_ text)
|
|
||||||
returns jsonb
|
|
||||||
language sql
|
|
||||||
immutable
|
|
||||||
as $$
|
|
||||||
/*
|
|
||||||
comment on column public.account.name is '@graphql.name: myField'
|
|
||||||
*/
|
|
||||||
select
|
|
||||||
coalesce(
|
|
||||||
(
|
|
||||||
regexp_match(
|
|
||||||
comment_,
|
|
||||||
'@graphql\((.+?)\)'
|
|
||||||
)
|
|
||||||
)[1]::jsonb,
|
|
||||||
jsonb_build_object()
|
|
||||||
)
|
|
||||||
$$;
|
|
||||||
|
|
||||||
|
|
||||||
-- src/lib.rs:21
|
-- src/lib.rs:21
|
||||||
create or replace function graphql.exception(message text)
|
create or replace function graphql.exception(message text)
|
||||||
returns text
|
returns text
|
||||||
@ -82,35 +114,3 @@ begin
|
|||||||
end;
|
end;
|
||||||
$$;
|
$$;
|
||||||
|
|
||||||
|
|
||||||
-- src/lib.rs:19
|
|
||||||
-- Is updated every time the schema changes
|
|
||||||
create sequence if not exists graphql.seq_schema_version as int cycle;
|
|
||||||
|
|
||||||
create or replace function graphql.increment_schema_version()
|
|
||||||
returns event_trigger
|
|
||||||
security definer
|
|
||||||
language plpgsql
|
|
||||||
as $$
|
|
||||||
begin
|
|
||||||
perform nextval('graphql.seq_schema_version');
|
|
||||||
end;
|
|
||||||
$$;
|
|
||||||
|
|
||||||
create or replace function graphql.get_schema_version()
|
|
||||||
returns int
|
|
||||||
security definer
|
|
||||||
language sql
|
|
||||||
as $$
|
|
||||||
select last_value from graphql.seq_schema_version;
|
|
||||||
$$;
|
|
||||||
|
|
||||||
-- On DDL event, increment the schema version number
|
|
||||||
create event trigger graphql_watch_ddl
|
|
||||||
on ddl_command_end
|
|
||||||
execute procedure graphql.increment_schema_version();
|
|
||||||
|
|
||||||
create event trigger graphql_watch_drop
|
|
||||||
on sql_drop
|
|
||||||
execute procedure graphql.increment_schema_version();
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@ -48,10 +48,11 @@ EOF
|
|||||||
echo_header $BLUE " DATABASE SETUP"
|
echo_header $BLUE " DATABASE SETUP"
|
||||||
|
|
||||||
PG_MAIN_VERSION=15
|
PG_MAIN_VERSION=15
|
||||||
PG_GRAPHQL_VERSION=1.3.0
|
PG_GRAPHQL_VERSION=1.4.2
|
||||||
CARGO_PGRX_VERSION=0.9.8
|
CARGO_PGRX_VERSION=0.10.2
|
||||||
|
|
||||||
current_directory=$(pwd)
|
current_directory=$(pwd)
|
||||||
|
script_directory="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||||
|
|
||||||
# Install PostgresSQL
|
# Install PostgresSQL
|
||||||
echo_header $GREEN "Step [1/4]: Installing PostgreSQL..."
|
echo_header $GREEN "Step [1/4]: Installing PostgreSQL..."
|
||||||
@ -85,9 +86,17 @@ unzip pg_graphql-$PG_GRAPHQL_VERSION.zip
|
|||||||
[[ ":$PATH:" != *":/opt/homebrew/opt/postgresql@$PG_MAIN_VERSION/bin:"* ]] && PATH="/opt/homebrew/opt/postgresql@$PG_MAIN_VERSION/bin:${PATH}"
|
[[ ":$PATH:" != *":/opt/homebrew/opt/postgresql@$PG_MAIN_VERSION/bin:"* ]] && PATH="/opt/homebrew/opt/postgresql@$PG_MAIN_VERSION/bin:${PATH}"
|
||||||
|
|
||||||
cd "pg_graphql-$PG_GRAPHQL_VERSION"
|
cd "pg_graphql-$PG_GRAPHQL_VERSION"
|
||||||
|
|
||||||
|
# Apply patches to pg_graphql files
|
||||||
|
echo "Applying patches to pg_graphql files..."
|
||||||
|
for patch_file in "$script_directory/../../patches/pg_graphql/"*.patch; do
|
||||||
|
echo "Applying patch: $patch_file"
|
||||||
|
patch -p1 < "$patch_file"
|
||||||
|
done
|
||||||
|
|
||||||
cargo pgrx install --release --pg-config /opt/homebrew/opt/postgresql@$PG_MAIN_VERSION/bin/pg_config
|
cargo pgrx install --release --pg-config /opt/homebrew/opt/postgresql@$PG_MAIN_VERSION/bin/pg_config
|
||||||
|
|
||||||
# # Clean up the temporary directory
|
# Clean up the temporary directory
|
||||||
echo "Cleaning up..."
|
echo "Cleaning up..."
|
||||||
cd "$current_directory"
|
cd "$current_directory"
|
||||||
rm -rf "$temp_dir"
|
rm -rf "$temp_dir"
|
||||||
|
|||||||
@ -48,10 +48,11 @@ EOF
|
|||||||
echo_header $BLUE " DATABASE SETUP"
|
echo_header $BLUE " DATABASE SETUP"
|
||||||
|
|
||||||
PG_MAIN_VERSION=15
|
PG_MAIN_VERSION=15
|
||||||
PG_GRAPHQL_VERSION=1.3.0
|
PG_GRAPHQL_VERSION=1.4.2
|
||||||
CARGO_PGRX_VERSION=0.9.8
|
CARGO_PGRX_VERSION=0.10.2
|
||||||
|
|
||||||
current_directory=$(pwd)
|
current_directory=$(pwd)
|
||||||
|
script_directory="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||||
|
|
||||||
# Install PostgresSQL
|
# Install PostgresSQL
|
||||||
echo_header $GREEN "Step [1/4]: Installing PostgreSQL..."
|
echo_header $GREEN "Step [1/4]: Installing PostgreSQL..."
|
||||||
@ -85,9 +86,17 @@ unzip pg_graphql-$PG_GRAPHQL_VERSION.zip
|
|||||||
[[ ":$PATH:" != *":/usr/local/opt/postgresql@$PG_MAIN_VERSION/bin:"* ]] && PATH="/usr/local/opt/postgresql@$PG_MAIN_VERSION/bin:${PATH}"
|
[[ ":$PATH:" != *":/usr/local/opt/postgresql@$PG_MAIN_VERSION/bin:"* ]] && PATH="/usr/local/opt/postgresql@$PG_MAIN_VERSION/bin:${PATH}"
|
||||||
|
|
||||||
cd "pg_graphql-$PG_GRAPHQL_VERSION"
|
cd "pg_graphql-$PG_GRAPHQL_VERSION"
|
||||||
|
|
||||||
|
# Apply patches to pg_graphql files
|
||||||
|
echo "Applying patches to pg_graphql files..."
|
||||||
|
for patch_file in "$script_directory/../../patches/pg_graphql/"*.patch; do
|
||||||
|
echo "Applying patch: $patch_file"
|
||||||
|
patch -p1 < "$patch_file"
|
||||||
|
done
|
||||||
|
|
||||||
cargo pgrx install --release --pg-config /usr/local/opt/postgresql@$PG_MAIN_VERSION/bin/pg_config
|
cargo pgrx install --release --pg-config /usr/local/opt/postgresql@$PG_MAIN_VERSION/bin/pg_config
|
||||||
|
|
||||||
# # Clean up the temporary directory
|
# Clean up the temporary directory
|
||||||
echo "Cleaning up..."
|
echo "Cleaning up..."
|
||||||
cd "$current_directory"
|
cd "$current_directory"
|
||||||
rm -rf "$temp_dir"
|
rm -rf "$temp_dir"
|
||||||
|
|||||||
@ -0,0 +1,28 @@
|
|||||||
|
diff --git a/sql/load_sql_context.sql b/sql/load_sql_context.sql
|
||||||
|
index 565e4e3..40cd99e 100644
|
||||||
|
--- a/sql/load_sql_context.sql
|
||||||
|
+++ b/sql/load_sql_context.sql
|
||||||
|
@@ -95,6 +95,8 @@ select
|
||||||
|
pg_type pt
|
||||||
|
left join pg_class tabs
|
||||||
|
on pt.typrelid = tabs.oid
|
||||||
|
+ join search_path_oids spo
|
||||||
|
+ on pt.typnamespace = spo.schema_oid or pt.typnamespace = 'pg_catalog'::regnamespace::oid
|
||||||
|
),
|
||||||
|
jsonb_build_object()
|
||||||
|
),
|
||||||
|
@@ -111,6 +113,8 @@ select
|
||||||
|
pg_type pt
|
||||||
|
join pg_class tabs
|
||||||
|
on pt.typrelid = tabs.oid
|
||||||
|
+ join search_path_oids spo
|
||||||
|
+ on pt.typnamespace = spo.schema_oid or pt.typnamespace = 'pg_catalog'::regnamespace::oid
|
||||||
|
where
|
||||||
|
pt.typcategory = 'C'
|
||||||
|
and tabs.relkind = 'c'
|
||||||
|
@@ -420,4 +424,4 @@ select
|
||||||
|
jsonb_build_array()
|
||||||
|
)
|
||||||
|
|
||||||
|
- )
|
||||||
|
+ );
|
||||||
Reference in New Issue
Block a user