Last active
December 31, 2015 13:49
-
-
Save abarth500/7995598 to your computer and use it in GitHub Desktop.
[データベースシステム論] インデクスの効果測定用テーブルの作成と測定
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--zipcodeと同じスキーマのテーブルzipcode2を作成 | |
CREATE TABLE zipcode2 | |
( | |
zip integer, | |
kana1 varchar(32), | |
kana2 varchar(32), | |
kana3 varchar(128), | |
addr1 varchar(32), | |
addr2 varchar(32), | |
addr3 varchar(128) | |
); | |
--データの流し込み | |
INSERT INTO zipcode2 | |
SELECT * FROM zipcode; | |
--zipxode2.zipにbtreeインデクス作成 | |
CREATE INDEX idx_zipcode2_zip | |
ON zipcode2 | |
USING btree (zip); | |
--zipxode2.addr3にhashインデクス作成 | |
CREATE INDEX idx_zipcode2_addr3 | |
ON zipcode2 | |
USING hash (addr3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------------------------------効果測定1 | |
--btreeインデクス(等価検索) | |
---インデクスなし | |
EXPLAIN | |
SELECT * FROM zipcode WHERE zip = 4328011; | |
---インデクスあり | |
EXPLAIN | |
SELECT * FROM zipcode2 WHERE zip = 4328011; | |
------------------------------------------------------------効果測定2 | |
--btreeインデクス(範囲検索) | |
---インデクスなし | |
EXPLAIN | |
SELECT * FROM zipcode WHERE zip >= 4328011 AND zip <= 4328066 ; | |
---インデクスあり | |
EXPLAIN | |
SELECT * FROM zipcode2 WHERE zip >= 4328011 AND zip <= 4328066 ; | |
------------------------------------------------------------効果測定3 | |
--hashインデクス(完全一致) | |
---インデクスなし | |
EXPLAIN | |
SELECT * FROM zipcode WHERE addr3 = '城北'; | |
---インデクスあり | |
EXPLAIN | |
SELECT * FROM zipcode2 WHERE addr3 = '城北'; | |
------------------------------------------------------------効果測定4 | |
--hashインデクス(部分一致) | |
---インデクスなし | |
EXPLAIN | |
SELECT * FROM zipcode WHERE addr3 LIKE '%城%'; | |
---インデクスあり | |
EXPLAIN | |
SELECT * FROM zipcode2 WHERE addr3 LIKE '%城%'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment