-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
-- This script runs a simple benchmark of a CHECK constraint using either | ||
-- the jsonschema or the pg_jsonschema extension. To test jsonschema for | ||
-- 200_000 iterations: | ||
-- | ||
-- psql -f eg/bench.sql --set extension=jsonschema --iterations 200_000 | ||
-- | ||
-- And with pg_jsonschema: | ||
-- | ||
-- psql -f eg/bench.sql --set extension=pg_jsonschema --iterations 200_000 | ||
-- | ||
-- Borrowed from | ||
-- https://github.com/supabase/pg_jsonschema?tab=readme-ov-file#benchmark | ||
|
||
\set QUIET on | ||
\unset ECHO | ||
\pset pager off | ||
|
||
\if :{?extension} | ||
\else | ||
\set extension jsonschema | ||
\endif | ||
|
||
\if :{?iterations} | ||
\else | ||
\set iterations 200_000 | ||
\endif | ||
|
||
BEGIN; | ||
|
||
SELECT '{ | ||
"type": "object", | ||
"properties": { | ||
"a": {"type": "number"}, | ||
"b": {"type": "string"} | ||
} | ||
}' AS schema \gset | ||
|
||
CREATE EXTENSION :extension; | ||
|
||
CREATE TABLE bench_json( | ||
meta JSON CHECK (json_matches_schema(:'schema'::json, meta)) | ||
); | ||
|
||
CREATE TABLE bench_jsonb( | ||
meta JSON CHECK (json_matches_schema(:'schema'::json, meta)) | ||
); | ||
|
||
\timing on | ||
|
||
\echo | ||
\echo ###################################################################### | ||
\echo # Test :extension JSON validation for :iterations iterations | ||
\echo ###################################################################### | ||
|
||
INSERT INTO bench_json(meta) | ||
SELECT json_build_object( 'a', i, 'b', i::text ) | ||
FROM generate_series(1, :iterations) t(i); | ||
|
||
\echo | ||
\echo | ||
\echo ###################################################################### | ||
\echo # Test :extension JSONB validation for :iterations iterations | ||
\echo ###################################################################### | ||
|
||
INSERT INTO bench_jsonb(meta) | ||
SELECT json_build_object( 'a', i, 'b', i::text ) | ||
FROM generate_series(1, :iterations) t(i); | ||
|
||
\echo | ||
\echo | ||
\timing off | ||
ROLLBACK; |