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

Performance: Declare exposed functions as parallel safe #51

Merged
merged 1 commit into from Apr 4, 2024

Conversation

yuri0sh
Copy link
Contributor

@yuri0sh yuri0sh commented Apr 4, 2024

What kind of change does this PR introduce?

Performance improvement

What is the current behavior?

Postgres treats all functions as unsafe by default

What is the new behavior?

Rust appropriate

https://www.postgresql.org/docs/current/parallel-safety.html#PARALLEL-LABELING

@yuri0sh
Copy link
Contributor Author

yuri0sh commented Apr 4, 2024

Setup:

create table bench_test_pg_jsonschema(
    meta jsonb
);
insert into bench_test_pg_jsonschema(meta)
select
    json_build_object(
        'a', i,
        'b', i::text
    )
from
    generate_series(1, 200000) t(i);

Query:

select count(*) from bench_test_pg_jsonschema 
where jsonb_matches_schema(
  '{"type": "object", "properties": {"a": {"type": "number", "exclusiveMinimum": 100000}, "b": {"type": "string"}}}', 
  meta
);

Default:
10630.823 ms (00:10.631)
Parallel safe:
5445.342 ms (00:05.445) - utilizes Parallel Seq Scan

MacBook Pro M1 Pro 2021, macOS 14.4, Postgres 16.2

@olirice
Copy link
Collaborator

olirice commented Apr 4, 2024

nice, thank you

@olirice olirice merged commit 6dfbfe3 into supabase:master Apr 4, 2024
1 check passed
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.

None yet

2 participants