From e990e0239137390ec4d67831278981b1294c3186 Mon Sep 17 00:00:00 2001 From: georgehao Date: Mon, 28 Aug 2023 17:07:29 +0800 Subject: [PATCH] feat(database): add index (#881) Co-authored-by: georgehao Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> --- common/version/version.go | 2 +- database/migrate/migrate_test.go | 2 +- .../00010_add_index_chunk_prover_task.sql | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 database/migrate/migrations/00010_add_index_chunk_prover_task.sql diff --git a/common/version/version.go b/common/version/version.go index e13ee5f24b..85a509d873 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -7,7 +7,7 @@ import ( "strings" ) -var tag = "v4.2.3" +var tag = "v4.2.4" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { diff --git a/database/migrate/migrate_test.go b/database/migrate/migrate_test.go index 93c86e36fc..31dc69e9ce 100644 --- a/database/migrate/migrate_test.go +++ b/database/migrate/migrate_test.go @@ -63,7 +63,7 @@ func testResetDB(t *testing.T) { cur, err := Current(pgDB.DB) assert.NoError(t, err) // total number of tables. - assert.Equal(t, 9, int(cur)) + assert.Equal(t, 10, int(cur)) } func testMigrate(t *testing.T) { diff --git a/database/migrate/migrations/00010_add_index_chunk_prover_task.sql b/database/migrate/migrations/00010_add_index_chunk_prover_task.sql new file mode 100644 index 0000000000..73c47329a1 --- /dev/null +++ b/database/migrate/migrations/00010_add_index_chunk_prover_task.sql @@ -0,0 +1,19 @@ +-- +goose Up +-- +goose StatementBegin + +create index if not exists idx_chunk_hash on chunk(hash, deleted_at) where deleted_at IS NULL; + +create index if not exists idx_proving_status_end_block_number_index on chunk(index, end_block_number, proving_status, deleted_at) where deleted_at IS NULL; + +create index if not exists idx_publickey_proving_status on prover_task(prover_public_key, proving_status, deleted_at, id) where deleted_at is null; + +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin + +drop index if exists idx_chunk_hash; +drop index if exists idx_proving_status_end_block_number_index; +drop index if exists idx_publickey_proving_status; + +-- +goose StatementEnd