From 596a1148c0186251041fd26a66bc1108f49eefe7 Mon Sep 17 00:00:00 2001 From: Sadiq Khoja Date: Tue, 21 Mar 2023 14:34:17 -0400 Subject: [PATCH] enhance: remove redundant indices from submission_defs table 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 --- .../20230321-01-optimize-indices-sub-defs.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/model/migrations/20230321-01-optimize-indices-sub-defs.js diff --git a/lib/model/migrations/20230321-01-optimize-indices-sub-defs.js b/lib/model/migrations/20230321-01-optimize-indices-sub-defs.js new file mode 100644 index 000000000..181d6cbf8 --- /dev/null +++ b/lib/model/migrations/20230321-01-optimize-indices-sub-defs.js @@ -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 }; +