Public Sequencer: Add SV End Point to List All ValidatorPermissions where the sponser is the calling SV. #5702
Conversation
Signed-off-by: pasindutennage-da <pasindu.tennage@digitalasset.com> Signed-off-by: Pasindu Tennage <pasindu.tennage@digitalasset.com>
Signed-off-by: pasindutennage-da <pasindu.tennage@digitalasset.com> Signed-off-by: Pasindu Tennage <pasindu.tennage@digitalasset.com>
Signed-off-by: pasindutennage-da <pasindu.tennage@digitalasset.com> Signed-off-by: Pasindu Tennage <pasindu.tennage@digitalasset.com>
Signed-off-by: pasindutennage-da <pasindu.tennage@digitalasset.com> Signed-off-by: Pasindu Tennage <pasindu.tennage@digitalasset.com>
[ci] Signed-off-by: pasindutennage-da <pasindu.tennage@digitalasset.com> Signed-off-by: Pasindu Tennage <pasindu.tennage@digitalasset.com>
| @@ -0,0 +1,5 @@ | |||
| -- Add index for sv_party to the dso_acs_store. | |||
|
|
|||
There was a problem hiding this comment.
Prior to index
EXPLAIN ANALYZE
SELECT * FROM dso_acs_store
WHERE template_id_qualified_name LIKE '%ValidatorPermission%'
AND sv_party = 'PAR::sv1::12345';
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
Seq Scan on dso_acs_store (cost=0.00..10.90 rows=1 width=1225) (actual time=0.020..0.020 rows=0 loops=1)
Filter: ((template_id_qualified_name ~~ '%ValidatorPermission%'::text) AND (sv_party = 'PAR::sv1::12345'::text))
Rows Removed by Filter: 14
Planning Time: 1.217 ms
Execution Time: 0.030 ms
(5 rows)
After Index
splice_apps=# EXPLAIN ANALYZE
SELECT * FROM dso_acs_store
WHERE template_id_qualified_name LIKE '%ValidatorPermission%'
AND sv_party = 'PAR::sv1::12345';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using dso_acs_store_sv_party_idx on dso_acs_store (cost=0.14..12.54 rows=1 width=2756) (actual time=0.006..0.007 rows=0 loops=1)
Index Cond: (sv_party = 'PAR::sv1::12345'::text)
Filter: (template_id_qualified_name ~~ '%ValidatorPermission%'::text)
Planning Time: 1.628 ms
Execution Time: 0.038 ms
(5 rows)
There was a problem hiding this comment.
that's not the query we're actually running, that one also includes store id, migration and package name and does not use the LIKE filter. Query plans are quite subtle. You really need to make sure you test the one that you use.
There was a problem hiding this comment.
EXPLAIN ANALYZE
SELECT * FROM dso_acs_store
WHERE store_id = 2
AND migration_id = 0
AND package_name = 'splice-amulet'
AND template_id_qualified_name = 'Splice.ValidatorPermission:ValidatorPermission'
AND sv_party = 'digital-asset-2-f1623917::122s';
Index Scan using dso_acs_store_sv_party_idx on dso_acs_store (cost=0.14..8.16 rows=1 width=2743) (actual time=0.075..0.096 rows=3 loops=1)
Index Cond: ((store_id = 2) AND (migration_id = 0) AND (package_name = 'splice-amulet'::text) AND (template_id_qualified_name = 'Splice.ValidatorPermission:ValidatorPermission'::text) AND (sv_party = 'digital-asset-2-f1623917::12200a6dde6a5b4ab4a2f6e8c1e98b736c404f9775b810fed9f620a6e07134d6c11a'::text))
Planning Time: 2.629 ms
Execution Time: 0.125 ms
(4 rows)
There was a problem hiding this comment.
that's the query without pagination, what if you paginate?
There was a problem hiding this comment.
No curser
EXPLAIN ANALYZE
SELECT * FROM dso_acs_store
WHERE store_id = 2
AND migration_id = 0
AND package_name = 'splice-amulet'
AND template_id_qualified_name = 'Splice.ValidatorPermission:ValidatorPermission'
AND sv_party = 'digital-asset-2-f1623917::122s'
ORDER BY event_number DESC
LIMIT 101;
Limit (cost=6.99..7.00 rows=1 width=2755) (actual time=0.039..0.039 rows=0 loops=1)
-> Sort (cost=6.99..7.00 rows=1 width=2755) (actual time=0.038..0.039 rows=0 loops=1)
Sort Key: event_number DESC
Sort Method: quicksort Memory: 25kB
-> Index Scan using dso_acs_store_sv_party_idx on dso_acs_store (cost=0.14..6.98 rows=1 width=2755) (actual time=0.020..0.020 rows=0 loops=1)
Index Cond: ((store_id = 2) AND (migration_id = 0) AND (package_name = 'splice-amulet'::text) AND (template_id_qualified_name = 'Splice.ValidatorPermission:ValidatorPermission'::text) AND (sv_party = 'digital-asset-2-f1623917::122s'::text))
With cursor
EXPLAIN ANALYZE
SELECT * FROM dso_acs_store
WHERE store_id = 2
AND migration_id = 0
AND package_name = 'splice-amulet'
AND template_id_qualified_name = 'Splice.ValidatorPermission:ValidatorPermission'
AND sv_party = 'digital-asset-2-f1623917::122s'
AND event_number < 850
ORDER BY event_number DESC
LIMIT 101;
Limit (cost=7.00..7.00 rows=1 width=2755) (actual time=0.028..0.028 rows=0 loops=1)
-> Sort (cost=7.00..7.00 rows=1 width=2755) (actual time=0.027..0.027 rows=0 loops=1)
Sort Key: event_number DESC
Sort Method: quicksort Memory: 25kB
-> Index Scan using dso_acs_store_sv_party_idx on dso_acs_store (cost=0.14..6.99 rows=1 width=2755) (actual time=0.012..0.012 rows=0 loops=1)
Index Cond: ((store_id = 2) AND (migration_id = 0) AND (package_name = 'splice-amulet'::text) AND (template_id_qualified_name = 'Splice.ValidatorPermission:ValidatorPermission'::text) AND (sv_party = 'digital-asset-2-f1623917::122s'::text))
Filter: (event_number < 850)
Conclusion
Both approaches use indexed scanning.
There was a problem hiding this comment.
Both approaches use indexed scanning.
Sadly SQL query plans are more complex than that. They do use an index. But if you look at it more closely the index cond does not include the event_number and this is just a filter. This essentially means you still have to do a seq scan through everything matching your index cond.
There was a problem hiding this comment.
@moritzkiefer-da Thank you. Apologies for missing that. I updated the index and please see the new plans below, which use only index.
No cursor
EXPLAIN ANALYZE
SELECT * FROM dso_acs_store
WHERE store_id = 2
AND migration_id = 0
AND package_name = 'splice-amulet'
AND template_id_qualified_name = 'Splice.ValidatorPermission:ValidatorPermission'
AND sv_party = 'digital-asset-2-f1623917::122s'
ORDER BY event_number DESC
LIMIT 101;
Limit (cost=0.27..6.68 rows=1 width=2533) (actual time=0.038..0.038 rows=0 loops=1)
-> Index Scan using dso_acs_store_sv_party_idx on dso_acs_store (cost=0.27..6.68 rows=1 width=2533) (actual time=0.037..0.037 rows=0 loops=1)
Index Cond: ((store_id = 2) AND (migration_id = 0) AND (package_name = 'splice-amulet'::text) AND (template_id_qualified_name = 'Splice.ValidatorPermission:ValidatorPermission'::text) AND (sv_party = 'digital-asset-2-f1623917::122s'::text))
Planning Time: 1.609 ms
Execution Time: 0.062 ms
(5 rows)
With cursor
EXPLAIN ANALYZE
SELECT * FROM dso_acs_store
WHERE store_id = 2
AND migration_id = 0
AND package_name = 'splice-amulet'
AND template_id_qualified_name = 'Splice.ValidatorPermission:ValidatorPermission'
AND sv_party = 'digital-asset-2-f1623917::122s'
AND event_number < 850
ORDER BY event_number DESC
LIMIT 101;
Limit (cost=0.27..6.68 rows=1 width=2533) (actual time=0.010..0.011 rows=0 loops=1)
-> Index Scan using dso_acs_store_sv_party_idx on dso_acs_store (cost=0.27..6.68 rows=1 width=2533) (actual time=0.010..0.010 rows=0 loops=1)
Index Cond: ((store_id = 2) AND (migration_id = 0) AND (package_name = 'splice-amulet'::text) AND (template_id_qualified_name = 'Splice.ValidatorPermission:ValidatorPermission'::text) AND (sv_party = 'digital-asset-2-f1623917::122s'::text) AND (event_number < 850))
Planning Time: 0.248 ms
Execution Time: 0.023 ms
(5 rows)
| @@ -0,0 +1,5 @@ | |||
| -- Add index for sv_party to the dso_acs_store. | |||
|
|
|||
There was a problem hiding this comment.
that's not the query we're actually running, that one also includes store id, migration and package name and does not use the LIKE filter. Query plans are quite subtle. You really need to make sure you test the one that you use.
[ci] Signed-off-by: pasindutennage-da <pasindu.tennage@digitalasset.com> Signed-off-by: Pasindu Tennage <pasindu.tennage@digitalasset.com>
[ci] Signed-off-by: pasindutennage-da <pasindu.tennage@digitalasset.com> Signed-off-by: Pasindu Tennage <pasindu.tennage@digitalasset.com>
[ci] Signed-off-by: pasindutennage-da <pasindu.tennage@digitalasset.com> Signed-off-by: Pasindu Tennage <pasindu.tennage@digitalasset.com>
[ci] Signed-off-by: pasindutennage-da <pasindu.tennage@digitalasset.com> Signed-off-by: Pasindu Tennage <pasindu.tennage@digitalasset.com>
53886e5
into
pasindutennage-da/public-sequencer-feature-branch
Fix #5665