diff --git a/note.md b/note.md index 13f37ca0..2b052563 100644 --- a/note.md +++ b/note.md @@ -287,4 +287,19 @@ mysql> EXPLAIN SELECT c.id, c.name, c.political_party, c.sex, v.count | 1 | PRIMARY | | NULL | ref | | | 4 | ishocon2.c.id | 128 | 100.00 | NULL | | 2 | DERIVED | votes | NULL | index | idx_votes_candidate_id | idx_votes_candidate_id | 4 | NULL | 12863 | 100.00 | NULL | +----+-------------+------------+------------+-------+------------------------+------------------------+---------+---------------+-------+----------+---------------------------------+ +``` + +- add foreign key to votes to candidates 28840 + +``` +❯ make bench +docker exec -i ishocon2-bench-1 sh -c "./benchmark --ip app:443 --workload 6" +2024/01/02 04:26:26 Start GET /initialize +2024/01/02 04:26:26 期日前投票を開始します +2024/01/02 04:26:27 期日前投票が終了しました +2024/01/02 04:26:27 投票を開始します Workload: 6 +2024/01/02 04:27:13 投票が終了しました +2024/01/02 04:27:13 投票者が結果を確認しています +2024/01/02 04:27:28 投票者の感心がなくなりました +2024/01/02 04:27:28 {"score": 28840, "success": 26120, "failure": 0} ``` \ No newline at end of file diff --git a/webapp/ruby/app.rb b/webapp/ruby/app.rb index 94c0e05a..e422c96f 100644 --- a/webapp/ruby/app.rb +++ b/webapp/ruby/app.rb @@ -96,6 +96,7 @@ def db_initialize db.query('DELETE FROM votes') db.query('ALTER TABLE votes ADD INDEX idx_votes_candidate_id (candidate_id)') db.query('ALTER TABLE votes ADD COLUMN count int(4) NOT NULL') + db.query('ALTER TABLE votes ADD CONSTRAINT fk_votes_to_candidate FOREIGN KEY (candidate_id) REFERENCES candidates (id)') end end