Open dostrelith678 opened 2 years ago
I will try to restore the previous snapshot db-sync-snapshot-schema-13-block-7560650-x86_64.tgz to see if the issue remains the same.
I will try to restore the previous snapshot db-sync-snapshot-schema-13-block-7560650-x86_64.tgz to see if the issue remains the same.
This one seems to be okay.
\d+ tx_out
Table "public.tx_out"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
---------------------+-------------------+-----------+----------+------------------------------------+----------+-------------+--------------+-------------
id | bigint | | not null | nextval('tx_out_id_seq'::regclass) | plain | | |
tx_id | bigint | | not null | | plain | | |
index | txindex | | not null | | plain | | |
address | character varying | | not null | | extended | | |
address_raw | bytea | | not null | | extended | | |
address_has_script | boolean | | not null | | plain | | |
payment_cred | hash28type | | | | extended | | |
stake_address_id | bigint | | | | plain | | |
value | lovelace | | not null | | main | | |
data_hash | hash32type | | | | extended | | |
inline_datum_id | bigint | | | | plain | | |
reference_script_id | bigint | | | | plain | | |
Indexes:
"tx_out_pkey" PRIMARY KEY, btree (id)
"idx_tx_out_address" hash (address)
"idx_tx_out_payment_cred" btree (payment_cred)
"idx_tx_out_stake_address_id" btree (stake_address_id)
"idx_tx_out_tx_id" btree (tx_id)
"tx_out_inline_datum_id_idx" btree (inline_datum_id)
"unique_txout" UNIQUE CONSTRAINT, btree (tx_id, index)
Foreign-key constraints:
"tx_out_inline_datum_id_fkey" FOREIGN KEY (inline_datum_id) REFERENCES datum(id) ON UPDATE RESTRICT ON DELETE CASCADE
"tx_out_reference_script_id_fkey" FOREIGN KEY (reference_script_id) REFERENCES script(id) ON UPDATE RESTRICT ON DELETE CASCADE
"tx_out_stake_address_id_fkey" FOREIGN KEY (stake_address_id) REFERENCES stake_address(id) ON UPDATE RESTRICT ON DELETE CASCADE
"tx_out_tx_id_fkey" FOREIGN KEY (tx_id) REFERENCES tx(id) ON UPDATE RESTRICT ON DELETE CASCADE
Referenced by:
TABLE "ma_tx_out" CONSTRAINT "ma_tx_out_tx_out_id_fkey" FOREIGN KEY (tx_out_id) REFERENCES tx_out(id) ON UPDATE RESTRICT ON DELETE CASCADE
OS Your OS:
Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-122-generic x86_64)
Versions The
db-sync
version (egcardano-db-sync --version
):PostgreSQL version:
14.4
Build/Install Method The method you use to build or install
cardano-db-sync
: Pre-compiled Hydra binary (https://hydra.iohk.io/build/17139466/download/1/cardano-db-sync-13.0.2-linux.tar.gz)Run method The method you used to run
cardano-db-sync
(eg Nix/Docker/systemd/none): systemdAdditional context Add any other context about the problem here. After upgrading to db-sync v13 and restoring the mainnet snapshot, I noticed some of the queries we run at Koios are extremely slow.
Problem Report Please do not include screenshots or images, but instead cut and paste any relevant log messages or errors.
After analysing the affected queries, we noticed that Postgres is deciding to do a sequential scan instead of an index scan on the
tx_out
table. I looked at thetx_out
table information of the restored snapshot:Comparing this to a testnet instance of the same db-sync version:
There are 3 missing indices in this table:
"idx_tx_out_address" hash (address)
"idx_tx_out_payment_cred" btree (payment_cred)
"idx_tx_out_tx_id" btree (tx_id)
as well as theReferenced by ma_tx_out
section.I checked the
ma_tx_out
table as well. Mainnet:Testnet:
which also reveals a missing index on the mainnet db.
I have confirmed that at least one of these indices (and presumably all of them) are present in the migration files: https://github.com/input-output-hk/cardano-db-sync/blob/e0a84705f82643513d05fe5de2a954b4b8bf59c8/schema/migration-3-0003-20200702.sql#L15
I am not sure this is a bug with db-sync, but the snapshot I restored seems faulty. The snapshot I restored is currently still the latest one listed in: https://update-cardano-mainnet.iohk.io/cardano-db-sync/index.html#13/:
db-sync-snapshot-schema-13-block-7581148-x86_64.tgz