pgbench
Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 4.56 2.36 2.36 7000 0.00 0.00 OpernameGetCandidates 4.09 4.47 2.11 7001 0.00 0.00 yyparse 3.99 6.53 2.06 1419187 0.00 0.00 AllocSetAlloc 2.75 7.95 1.42 168015 0.00 0.00 SearchCatCache 2.64 9.31 1.36 8004 0.00 0.00 XLogInsert
pgbenchのボトルネックはparserにある。
OpernameGetCandidatesは、'='などのoperatorを評価するための関数をシステムカタログから探す。SearchSysCacheListでpg_operatorから、operatorのテキスト表現('='など)が一致するリストを取得し、その中から左右のデータ型が一致するoperatorが選択される。このときnamespaceも考慮され、同じoperatorが見つかった場合、namespace search pathの優先順位が高い方が選択される。SearchSysCacheListで取得したデータを全部調べるため、実行コストが高い。
operatorの選択結果をキャッシュする仕組みを導入すれば、OpernameGetCandidatesの実行回数を減らすことができ、スループットが向上するはず。
patch適用結果:
Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 4.41 2.13 2.13 1418187 0.00 0.00 AllocSetAlloc 3.98 4.05 1.92 7001 0.00 0.00 yyparse 3.15 5.57 1.52 168015 0.00 0.00 SearchCatCache 2.96 7.00 1.43 197699 0.00 0.00 hash_search 2.70 8.31 1.31 8002 0.00 0.00 XLogInsert ..... 0.00 48.25 0.00 2 0.00 0.02 OpernameGetCandidates