我使用的是从8.3派生出来的PostgreSQL的MPP版本。
我正在尝试使用where子句优化select语句,以便只选择具有私有源IP地址和公共目标IP地址的行。我有两个类型为source_ip和destination_ip的列。我觉得下面的操作不是最有效的方法,因为我正在进行正则表达式匹配,以确定IP是公有IP还是私有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类型进行操作?
发布于 2013-03-19 02:57:42
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')
https://stackoverflow.com/questions/15484322
复制相似问题