From: ludo@gnu.org (Ludovic Courtès)
To: Danny Milosavljevic <dannym@scratchpost.org>, clement@lassieur.org
Cc: guix-devel@gnu.org
Subject: [Cuirass] Missing database indexes?
Date: Sat, 10 Nov 2018 18:33:23 +0100 [thread overview]
Message-ID: <87va54yh0c.fsf@gnu.org> (raw)
Hello!
I was investigating the slowness of our /api/latestbuilds requests on
berlin.
I found that if we have just the two indexes currently defined in
‘schema.sql’, basically everything involves a table scan:
--8<---------------cut here---------------start------------->8---
sqlite> EXPLAIN QUERY PLAN select * from builds where system = "x";
0|0|0|SCAN TABLE builds
--8<---------------cut here---------------end--------------->8---
I tentatively defined new indexes that seem to help:
--8<---------------cut here---------------start------------->8---
sqlite> CREATE INDEX Builds_index_evaluation ON Builds(evaluation);
sqlite> CREATE INDEX Builds_index_status ON Builds(status);
sqlite> CREATE INDEX Builds_index_system ON Builds(system, evaluation);
sqlite> EXPLAIN QUERY PLAN select * from builds where evaluation = 12;
0|0|0|SEARCH TABLE builds USING INDEX Builds_index_evaluation (evaluation=?)
sqlite> EXPLAIN QUERY PLAN select * from builds where evaluation = 12 and system ="x";
0|0|0|SEARCH TABLE builds USING INDEX Builds_index_system (system=? AND evaluation=?)
sqlite> EXPLAIN QUERY PLAN select * from builds where evaluation = 12 and status = 0;
0|0|0|SEARCH TABLE builds USING INDEX Builds_index_status (status=?)
--8<---------------cut here---------------end--------------->8---
Now, ‘db-get-builds’ in Cuirass uses a more complex query. In
particular, it orders things, very roughly along these lines:
--8<---------------cut here---------------start------------->8---
sqlite> EXPLAIN QUERY PLAN select * from builds where evaluation = 12 and status > 0 order by stoptime ;
0|0|0|SEARCH TABLE builds USING INDEX Builds_index_evaluation (evaluation=?)
0|0|0|USE TEMP B-TREE FOR ORDER BY
--8<---------------cut here---------------end--------------->8---
I’m pretty much a database newbie so please forgive the naive question,
but is there something we can do to avoid this extra B-tree step, which
seems costly in space and time? <http://www.sqlite.com/matrix/eqp.html>
suggests it’s just a matter of adding yet another index but I couldn’t
get that.
Anything else we should do?
Thanks in advance! :-)
Ludo’.
next reply other threads:[~2018-11-10 17:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-10 17:33 Ludovic Courtès [this message]
2018-11-10 20:11 ` [Cuirass] Missing database indexes? Björn Höfling
2018-11-11 17:06 ` Ludovic Courtès
2018-11-12 18:50 ` Björn Höfling
2018-11-12 19:42 ` Amirouche Boubekki
2018-11-12 23:27 ` Danny Milosavljevic
2018-11-14 11:14 ` Ludovic Courtès
2018-11-16 22:31 ` Björn Höfling
2018-11-13 8:10 ` Clément Lassieur
2018-11-16 22:42 ` Björn Höfling
2018-11-12 23:31 ` Danny Milosavljevic
2018-11-13 0:04 ` Danny Milosavljevic
2018-11-14 11:11 ` Ludovic Courtès
2018-11-19 10:44 ` Danny Milosavljevic
2018-12-19 22:45 ` Amirouche Boubekki
2018-11-19 9:47 ` swedebugia
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87va54yh0c.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=clement@lassieur.org \
--cc=dannym@scratchpost.org \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.