transaction type: ./test-sql1.sql scaling factor: 1 query mode: simple number of clients: 4 number of threads: 4 duration: 30 s number of transactions actually processed: 39007 latency average = 3.077 ms tps = 1299.848793 (including connections establishing) tps = 1299.933199 (excluding connections establishing)
transaction type: ./test-sql2.sql scaling factor: 1 query mode: simple number of clients: 4 number of threads: 4 duration: 30 s number of transactions actually processed: 173751 latency average = 0.691 ms tps = 5791.490212 (including connections establishing) tps = 5791.971583 (excluding connections establishing)
transaction type: ./test-sql3.sql scaling factor: 1 query mode: simple number of clients: 4 number of threads: 4 duration: 30 s number of transactions actually processed: 198253 latency average = 0.605 ms tps = 6608.167036 (including connections establishing) tps = 6608.692985 (excluding connections establishing)
方案4. Gist索引-int8range
我们选用Gist索引, 类型选用int8range
建表:
1 2 3 4 5 6 7
createtable ip2location_db1_test4 ( ip_range int8range notnull, country_code character(2) notnull, country_name charactervarying(64) notnull ); createindex ip2location_db1_test4_range on ip2location_db1_test4 using gist (ip_range);
基准测试
构建文件: ./test-sql4.sql
1 2 3 4
\set ip random(0, 2147483647) select * from ip2location_db1_test4 where ip_range @> :ip;
transaction type: ./test-sql4.sql scaling factor: 1 query mode: simple number of clients: 4 number of threads: 4 duration: 30 s number of transactions actually processed: 1070154 latency average = 0.112 ms tps = 35671.455573 (including connections establishing) tps = 35674.666859 (excluding connections establishing)
方案5. Gist索引-int4range
我们对方案4进行改进, 将int8range修改为int4range
建表:
1 2 3 4 5 6 7
createtable ip2location_db1_test5 ( ip_range int4range notnull, country_code character(2) notnull, country_name charactervarying(64) notnull ); createindex ip2location_db1_test5_range on ip2location_db1_test5 using gist (ip_range);
基准测试
构建文件: ./test-sql5.sql
1 2 3 4
\set ip random(0, 2147483647) select * from ip2location_db1_test5 where ip_range @> (:ip - 2147483648)::int4;
ransaction type: ./test-sql5.sql scaling factor: 1 query mode: simple number of clients: 4 number of threads: 4 duration: 30 s number of transactions actually processed: 980291 latency average = 0.122 ms tps = 32675.974742 (including connections establishing) tps = 32678.161957 (excluding connections establishing)
transaction type: ./test-sql6.sql scaling factor: 1 query mode: simple number of clients: 4 number of threads: 4 duration: 30 s number of transactions actually processed: 1218063 latency average = 0.099 ms tps = 40600.765922 (including connections establishing) tps = 40604.364144 (excluding connections establishing)
数据与索引空间
最后, 我们展示各种方案下数据和索引所占空间
查询语句
1 2 3 4 5 6 7 8
SELECT table_name "表名", pg_size_pretty(pg_relation_size(table_name::text)) "数据占用空间", pg_size_pretty(pg_indexes_size(table_name::text)) "索引占用空间", pg_size_pretty(pg_total_relation_size(table_name::text)) "数据和索引占用空间" FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE' and table_name like'ip2location_db1_%';