8.3 から分岐した PostgreSQL の MPP バージョンを使用しています。
where 句を使用して select ステートメントを最適化し、プライベート ソース IP アドレスとパブリック宛先 IP アドレスを持つ行のみを選択しようとしています。source_ip と destination_ip というタイプの inet の 2 つの列があります。IPがパブリックかプライベートかを判断するために正規表現の一致を行っているため、次の操作は最も効率的な方法ではないように感じます。
where (text(source_ip) like '10.%'
or text(source_ip) like '192.168.%'
or text(source_ip) ~ E'^172\.((1[6-9])|(2[0-9])|(3[0-1]))\..+')
and text(destination_ip) not like '10.%'
and text(destination_ip) not like '192.168.%'
and text(destination_ip) !~ E'^172\.((1[6-9])|(2[0-9])|(3[0-1]))\..+';
上記のwhere句をより効率的にするにはどうすればよいですか? 正規表現を使用せず、組み込みの postgresql 関数を使用して inet 型をより高速に操作する方法はありますか?