0

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 型をより高速に操作する方法はありますか?

4

1 に答える 1

2
where
    (
        inet '10/8' >> source_ip
        or inet '192.168/16' >> source_ip
        or sourceip >= inet '172.16/16' and sourceip < inet '172.32/16'
    )
    and not inet '10/8' >> destination_ip
    and not inet '192.168/16' >> destination_ip
    and not (destination_ip >= inet '172.16/16' and destination_ip < inet '172.32/16')
于 2013-03-18T18:57:42.497 に答える