williamdclt
04/30/2024, 12:28 PMplan_cache_mode = force_custom_plan
myself in postgres? How does SpiceDB handle that now?vroldanbet
04/30/2024, 12:40 PMplan_cache_mode
in the DSN
https://github.com/authzed/spicedb/blob/main/internal/datastore/postgres/postgres.go#L615-L634williamdclt
04/30/2024, 12:58 PMsql
SELECT namespace, object_id, relation, userset_namespace, userset_object_id, userset_relation, caveat_name, caveat_context FROM relation_tuple WHERE pg_visible_in_snapshot(created_xid, $1) = $2 AND pg_visible_in_snapshot(deleted_xid, $3) = $4 AND namespace = $5 AND relation = $6 AND object_id IN ($7) AND ((userset_namespace = $8 AND userset_object_id IN ($9) AND userset_relation = $10)) LIMIT 9223372036854775807
See the "planning time" in these 2 EXPLAIN ANALYZE:williamdclt
04/30/2024, 12:58 PMsql
Limit (cost=0.69..8.72 rows=1 width=138) (actual time=0.033..0.034 rows=0 loops=1)
-> Index Scan using uq_relation_tuple_living_xid on relation_tuple (cost=0.69..8.72 rows=1 width=138) (actual time=0.033..0.033 rows=0 loops=1)
Index Cond: (((namespace)::text = 'care_recipient'::text) AND ((object_id)::text = '(268ea094-92e4-11eb-a25b-067ff236ecb9,af6f7d21-eb5d-42a0-8b9e-cc55dddfeee0,99c8c11d-f6d2-471d-845b-ed2dbc21e822,90ae53f5-ad48-4929-9a12-b4a6ed8a3d80,9f7a7d6d-9b6a-4b2e-8d33-dfbea8e4c59f)'::text) AND ((relation)::text = 'caregiver'::text) AND ((userset_namespace)::text = 'user_agency_role'::text) AND ((userset_object_id)::text = '(e3108ff2-4041-4287-972e-9fb5ca6d8cc7__cd79fa38-b6e8-4452-a14b-7f67141d0489,e3108ff2-4041-4287-972e-9fb5ca6d8cc7__cd79fa38-b6e8-4452-a14b-7f67141d0488,e3108ff2-4041-4287-972e-9fb5ca6d8cc7__cd79fa38-b6e8-4452-a14b-7f67141d0481)'::text) AND ((userset_relation)::text = '...'::text))
Filter: (pg_visible_in_snapshot(created_xid, '795:799:795,797'::pg_snapshot) AND (NOT pg_visible_in_snapshot(deleted_xid, '795:799:795,797'::pg_snapshot)))
Planning Time: 0.204 ms
Execution Time: 0.057 ms
(6 rows)
With `plan_cache_mode = auto`:
sql
Limit (cost=0.56..8.60 rows=1 width=138) (actual time=0.040..0.040 rows=0 loops=1)
-> Index Scan using ix_relation_tuple_by_subject on relation_tuple (cost=0.56..8.60 rows=1 width=138) (actual time=0.039..0.039 rows=0 loops=1)
Index Cond: (((userset_object_id)::text = $9) AND ((userset_namespace)::text = $8) AND ((userset_relation)::text = $10) AND ((namespace)::text = $5) AND ((relation)::text = $6))
Filter: (((object_id)::text = $7) AND (pg_visible_in_snapshot(created_xid, $1) = $2) AND (pg_visible_in_snapshot(deleted_xid, $3) = $4))
Planning Time: 0.055 ms
Execution Time: 0.079 ms
(6 rows)
williamdclt
04/30/2024, 12:58 PMvroldanbet
04/30/2024, 1:31 PMwilliamdclt
04/30/2024, 1:34 PMvroldanbet
04/30/2024, 1:42 PMwilliamdclt
04/30/2024, 2:09 PMSELECT MIN(id), MAX(id) from relation_tuple_transaction ...
), and basically kill my spicedbvroldanbet
04/30/2024, 2:21 PMJoey
04/30/2024, 3:10 PMvroldanbet
04/30/2024, 3:27 PMwilliamdclt
04/30/2024, 4:24 PMJoey
04/30/2024, 4:26 PMJoey
04/30/2024, 4:27 PMJoey
04/30/2024, 4:27 PMwilliamdclt
05/01/2024, 9:30 AM--datastore-conn-uri="postgresql://user:password@mydb:5432/spicedb"
), which doesn't accept the plan_cache_mode
setting as parameter AFAIK, only these params https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDSwilliamdclt
05/01/2024, 9:30 AMJoey
05/01/2024, 3:40 PMJoey
05/01/2024, 3:40 PMwilliamdclt
05/01/2024, 4:47 PMpsql
can't deal with it but pgx
(or whatever handles that) doeswilliamdclt
05/01/2024, 4:48 PMsql
SELECT namespace, object_id, relation, userset_namespace, userset_object_id, userset_relation, caveat_name, caveat_context FROM relation_tuple WHERE pg_visible_in_snapshot(created_xid, $1) = $2 AND pg_visible_in_snapshot(deleted_xid, $3) = $4 AND namespace = $5 AND relation = $6 AND object_id IN ($7) AND ((userset_namespace = $8 AND userset_object_id IN ($9) AND userset_relation = $10)) LIMIT ?
https://cdn.discordapp.com/attachments/1234843902091984917/1235271657724317759/image.png?ex=6633c3e1&is=66327261&hm=39e40c3b27faeca285bdd0da0723363bac17c084dd24df3393fdc19e24743269&williamdclt
05/01/2024, 4:48 PMJoey
05/01/2024, 4:57 PMJoey
05/01/2024, 4:57 PMJoey
05/01/2024, 4:58 PMJoey
05/01/2024, 5:03 PMauto
Joey
05/01/2024, 5:03 PMvroldanbet
05/02/2024, 8:06 AMmin(), max()
query, which makes sense because all that change a while back after the MVCC for postgres was redesigned.
If you set debug level, you should see the parameters used to execute the query, so you can replay it with an explain.vroldanbet
05/02/2024, 8:10 AMwilliamdclt
05/02/2024, 10:26 AM