Skip to content

Commit

Permalink
enhance: remove redundant indices from submission_defs table
Browse files Browse the repository at this point in the history
improves submission throughput by 20% without any impact on select queries

Benchmark:
250_questions form with 20K existing submissions
JMeter parameters:
300 thread
60 test duration
1500 per 10 sec target throughput
release 40 threads in batch

Result:
95/sec throughput with 4% error without this change
115/sec throughput without any error with this change
  • Loading branch information
sadiqkhoja committed Mar 21, 2023
1 parent 05ebccd commit 596a114
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/model/migrations/20230321-01-optimize-indices-sub-defs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2023 ODK Central Developers
// See the NOTICE file at the top-level directory of this distribution and at
// https://github.com/getodk/central-backend/blob/master/NOTICE.
// This file is part of ODK Central. It is subject to the license terms in
// the LICENSE file found in the top-level directory of this distribution and at
// https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central,
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.

const up = async (db) => {
await db.raw('DROP INDEX public.submission_defs_createdat_index;');
await db.raw('DROP INDEX public.submission_defs_current_index;');
await db.raw('DROP INDEX public.submission_defs_id_submissionid_index;');
await db.raw('DROP INDEX public.submission_defs_submissionid_index;');
};

const down = async (db) => {
await db.raw('CREATE INDEX submission_defs_createdat_index ON public.submission_defs USING btree ("createdAt");');
await db.raw('CREATE INDEX submission_defs_current_index ON public.submission_defs USING btree (current);');
await db.raw('CREATE INDEX submission_defs_id_submissionid_index ON public.submission_defs USING btree (id, "submissionId");');
await db.raw('CREATE INDEX submission_defs_submissionid_index ON public.submission_defs USING btree ("submissionId");');
};

module.exports = { up, down };

0 comments on commit 596a114

Please sign in to comment.