Closed edridudi closed 2 years ago
The current query code (view for select distinct) is not really optimal, we'd want to perhaps improve the tx_metalabels
endpoint by moving into a cache table instead - the result set being as small as it currently is. The keys returned are not really changing often, so it might be alright for this table to get refreshed every 10/15 minutes
@dostrelith678 @Scitz0 - thoughts?
Agree, that the current view is not great as it is. I suggest turning the current view into a materialized view (or a cache table) that is updated on a schedule. If a materialized view is used, we should refresh it using CONCURRENTLY
option to allow select on it while updating.
The problem with tx_metadata table is that it currently contains ~35M rows on mainnet. The lack of an index on key column doesn't really matter as an index only scan over the entire table isn't much quicker than no index.
Actually, let me investigate loost index scan first before creating a cache table. ref: https://wiki.postgresql.org/wiki/Loose_indexscan
Yip, this is the way to go, current view takes ~15s on a fast dedicated server. While loose index scan approach takes ~10ms.
WITH RECURSIVE t AS (
(SELECT key FROM tx_metadata ORDER BY key LIMIT 1)
UNION ALL
SELECT (SELECT key FROM tx_metadata WHERE key > t.key ORDER BY key LIMIT 1)
FROM t
WHERE t.key IS NOT NULL
)
SELECT key FROM t WHERE key IS NOT NULL;
Nice, wasn't aware of skip scan bit, seems straightforward indeed
Should be fixed by linked issue, now just need to create a release soon (alongwith open PRs) - and version bump to have it available on instances
Describe the bug Tx Metalabels Requests are timing out (infrequently)
To Reproduce GET https://api.koios.rest/api/v0/tx_metalabels?limit=10
Expected behavior No Timeout
Screenshots