Improve update.py database performance.

This patch adds indexes to awfy_breakdown and awfy_score and rewrites
the update search queries to be simpler and much faster.
This commit is contained in:
David Anderson 2013-10-18 08:06:09 +00:00
Родитель a95dc1f1c1
Коммит b224a4366d
3 изменённых файлов: 17 добавлений и 3 удалений

Просмотреть файл

@ -167,8 +167,8 @@ CREATE TABLE `awfy_breakdown` (
`test_id` int(10) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `run_id` (`run_id`),
KEY `suite_id` (`suite_id`),
KEY `mode_id` (`mode_id`),
KEY `test_id` (`test_id`),
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
@ -218,6 +218,7 @@ CREATE TABLE `awfy_score` (
PRIMARY KEY (`id`),
KEY `run_id` (`run_id`),
KEY `mode_id` (`mode_id`)
KEY `suite_id` (`suite_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------

Просмотреть файл

@ -68,3 +68,16 @@ if 'test' in awfy_breakdown_columns:
if 'suite_id' in awfy_breakdown_columns:
print('Dropping old column suite_id...')
c.execute("alter table `awfy_breakdown` drop `suite_id`")
def try_add_column(table, column):
try:
c.execute("alter table `{0}` add index {1} ({2})".format(table, column, column))
except:
pass
try_add_column('awfy_breakdown', 'run_id')
try_add_column('awfy_breakdown', 'mode_id')
try_add_column('awfy_breakdown', 'test_id')
try_add_column('awfy_score', 'run_id')
try_add_column('awfy_score', 'mode_id')
try_add_column('awfy_score', 'suite_id')

Просмотреть файл

@ -65,9 +65,9 @@ def fetch_test_scores(machine_id, suite_id, name, earliest_run_id):
def fetch_suite_scores(machine_id, suite_id, earliest_run_id):
query = "SELECT r.id, r.stamp, b.cset, s.score, s.mode_id \
FROM awfy_score s \
JOIN awfy_mode m \
JOIN awfy_mode m on m.id = s.mode_id \
JOIN fast_run r ON s.run_id = r.id \
JOIN awfy_build b ON (s.run_id = b.run_id AND s.mode_id = b.mode_id) \
JOIN awfy_build b ON s.run_id = b.run_id \
WHERE s.suite_id = %s \
AND r.id > %s \
AND r.status = 1 \