Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save anarchivist/78be4e70f154ef1fbe8d5f0c3018aa5f to your computer and use it in GitHub Desktop.

Select an option

Save anarchivist/78be4e70f154ef1fbe8d5f0c3018aa5f to your computer and use it in GitHub Desktop.
PostgreSQL 9.4 prepared statement behavior
marmotta=# -- prepare statement
marmotta=# prepare boom as SELECT id FROM triples WHERE subject = $1 AND predicate = $2 AND object = $3 AND context =
$4 AND deleted = false;
PREPARE
marmotta=# -- run 1
marmotta=# explain execute boom('718127302357929984', '564051914678095872', '564051914636152835', '564051914489352192');
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using idx_triples_spo on triples (cost=0.57..3.60 rows=1 width=8)
Index Cond: ((subject = 718127302357929984::bigint) AND (predicate = 564051914678095872::bigint) AND (object = 5640
51914636152835::bigint))
Filter: (context = 564051914489352192::bigint)
(3 rows)
marmotta=# -- run 2
explain execute boom('718127302357929984', '564051914678095872', '564051914636152835', '564051914489352192');
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using idx_triples_spo on triples (cost=0.57..3.60 rows=1 width=8)
Index Cond: ((subject = 718127302357929984::bigint) AND (predicate = 564051914678095872::bigint) AND (object = 5640
51914636152835::bigint))
Filter: (context = 564051914489352192::bigint)
(3 rows)
marmotta=# -- run 3
explain execute boom('718127302357929984', '564051914678095872', '564051914636152835', '564051914489352192');
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using idx_triples_spo on triples (cost=0.57..3.60 rows=1 width=8)
Index Cond: ((subject = 718127302357929984::bigint) AND (predicate = 564051914678095872::bigint) AND (object = 5640
51914636152835::bigint))
Filter: (context = 564051914489352192::bigint)
(3 rows)
marmotta=# -- run 4
explain execute boom('718127302357929984', '564051914678095872', '564051914636152835', '564051914489352192');
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using idx_triples_spo on triples (cost=0.57..3.60 rows=1 width=8)
Index Cond: ((subject = 718127302357929984::bigint) AND (predicate = 564051914678095872::bigint) AND (object = 564051914636152835::bigint))
Filter: (context = 564051914489352192::bigint)
(3 rows)
marmotta=# -- run 5
explain execute boom('718127302357929984', '564051914678095872', '564051914636152835', '564051914489352192');
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using idx_triples_spo on triples (cost=0.57..3.60 rows=1 width=8)
Index Cond: ((subject = 718127302357929984::bigint) AND (predicate = 564051914678095872::bigint) AND (object = 564051914636152835::bigint))
Filter: (context = 564051914489352192::bigint)
(3 rows)
marmotta=# -- run 6
explain execute boom('718127302357929984', '564051914678095872', '564051914636152835', '564051914489352192');
QUERY PLAN
-------------------------------------------------------------------------------
Index Scan using idx_triples_cop on triples (cost=0.57..3.60 rows=1 width=8)
Index Cond: ((context = $4) AND (object = $3) AND (predicate = $2))
Filter: (subject = $1)
(3 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment