翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
ユースケース 3 — SELECT ステートメントの関数呼び出し
where
句で関数を呼び出すVOLATILE
と、関数が であり、関数を呼び出すときに select
キーワードを使用しない場合に、クエリのパフォーマンスが低下する可能性があります。
Select * from tab_name where FieldName = FunctionName(parameters);
インデックススキャンは、関数の呼び出し中に select
ステートメントが使用されている場合に実行されます。
Select * from tab_name where FieldName = ( select FunctionName(parameters) );
pnr_number
フィールドには、rnr_expiry_date
テーブルにインデックスがあります。インデックスは、 where
句の値を比較するときに使用されます。
explain analyze select * from perf_user.rnr_expiry_date where pnr_number= 'EE9F41'; "Index Scan using rnr_expiry_date_idx3 on rnr_expiry_date (cost=0.29..8.31 rows=1 width=72) (actual time=0.020..0.021 rows=1 loops=1)" " Index Cond: ((pnr_number)::text = 'EE9F41'::text)" "Planning Time: 0.063 ms" "Execution Time: 0.038 ms"
シーケンシャルスキャンは、フィールドでインデックスが使用可能であっても、select
キーワードなしで関数が呼び出されたときに実行されます。
explain analyze select * from perf_user.rnr_expiry_date where pnr_number= perf_user.return_data(); "Seq Scan on rnr_expiry_date (cost=0.00..27084.00 rows=1 width=72) (actual time=0.112..135.917 rows=1 loops=1)" " Filter: ((pnr_number)::text = (perf_user.return_data())::text)" " Rows Removed by Filter: 99999" "Planning Time: 0.053 ms" "Execution Time: 136.803 ms"
インデックススキャンは、関数が select
キーワードで呼び出されたときに実行されます。
explain analyze select * from perf_user.rnr_expiry_date where pnr_number= (select perf_user.return_data() ); "Index Scan using rnr_expiry_date_idx3 on rnr_expiry_date (cost=0.55..8.57 rows=1 width=72) (actual time=0.058..0.061 rows=1 loops=1)" " Index Cond: ((pnr_number)::text = ($0)::text)" " InitPlan 1 (returns $0)" " -> Result (cost=0.00..0.26 rows=1 width=32) (actual time=0.021..0.022 rows=1 loops=1)" "Planning Time: 0.147 ms" "Execution Time: 0.111 ms"