Added indexes to Foreign keys
ClosedPublic

Authored by jskladan on Apr 14 2015, 12:34 PM.

Details

Summary

PostgreSQL does not automatically create Indexes for Foreign keys.
This was found out while solving T452. Without indexes, queries like:

SELECT * FROM result WHERE 115515 = result.job_id;

take about 250 ms. With index on the Foreign key, it is 0.048 ms.

Test Plan

None

Diff Detail

Repository
rRSDB resultsdb
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
jskladan retitled this revision from to Added indexes to Foreign keys.Apr 14 2015, 12:34 PM
jskladan updated this object.
jskladan edited the test plan for this revision. (Show Details)
jskladan added reviewers: tflink, kparal, mkrizek.
tflink accepted this revision.Apr 14 2015, 2:28 PM
This revision is now accepted and ready to land.Apr 14 2015, 2:28 PM
jskladan updated this revision to Diff 919.Apr 14 2015, 3:24 PM
  • Use better query to order jobs by start_time
  • Allow LIKE to use index on result_data.key/value search

@tflink, you are way too fast and I am way too slow - I have been digging around for more slow queries, and I found out, that the key-value index on result_data is not used for LIKE queries.

I'm not saying we need to remake the index now, but if we're going to have downtime for creating the other indexes anyway, this might be well worth it.

Let me know whether this is OK with you, or if I should keep it at the Accepted state and do this in a separate Diff.

In D338#6147, @jskladan wrote:

@tflink, you are way too fast and I am way too slow - I have been digging around for more slow queries, and I found out, that the key-value index on result_data is not used for LIKE queries.

I'm not saying we need to remake the index now, but if we're going to have downtime for creating the other indexes anyway, this might be well worth it.

Let me know whether this is OK with you, or if I should keep it at the Accepted state and do this in a separate Diff.

Makes sense to me - fewer downtimes scheduled the better.

I'm starting to wonder if the mysql stuff should be removed, though. While I'm not against having it in there if it doesn't cost us much, it kinda implies that we support mysql in addition to postgres and I don't see that as a priority. Postgres is in our deployments, sqlite can be used for dev but I don't see enough value in adding mysql to justify spending time on any mysql-specific issues that may come up.

In D338#6150, @tflink wrote:

I'm starting to wonder if the mysql stuff should be removed, though.

Yeah, it probably should. I had some dev setup with mysql in the past, but with the rise and shine of Taskotron-Ansible, I don't see myself using it anyway.
Will, do, and push.

Closed by commit rRSDBd3793bc9c571: Added indexes to Foreign keys (authored by Josef Skladanka <jskladan@redhat.com>). · Explain WhyApr 15 2015, 8:37 AM
This revision was automatically updated to reflect the committed changes.