Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8d8bf12

Browse files
committed
Clean up the INET-vs-CIDR situation. Get rid of the internal is_cidr flag
and rely exclusively on the SQL type system to tell the difference betweenthe types. Prevent creation of invalid CIDR values via casting from INETor set_masklen() --- both of these operations now silently zero any bitsto the right of the netmask. Remove duplicate CIDR comparison operators,letting the type rely on the INET operators instead.
1 parent5997386 commit8d8bf12

File tree

12 files changed

+269
-142
lines changed

12 files changed

+269
-142
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.302 2006/01/11 20:12:38 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.303 2006/01/26 02:35:48 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -6797,9 +6797,7 @@ SELECT pg_sleep(1.5);
67976797
types. The <function>host</function>,
67986798
<function>text</function>, and <function>abbrev</function>
67996799
functions are primarily intended to offer alternative display
6800-
formats. You can cast a text value to <type>inet</> using normal casting
6801-
syntax: <literal>inet(<replaceable>expression</>)</literal> or
6802-
<literal><replaceable>colname</>::inet</literal>.
6800+
formats.
68036801
</para>
68046802

68056803
<table id="cidr-inet-functions-table">
@@ -6843,6 +6841,13 @@ SELECT pg_sleep(1.5);
68436841
<entry><literal>set_masklen('192.168.1.5/24', 16)</literal></entry>
68446842
<entry><literal>192.168.1.5/16</literal></entry>
68456843
</row>
6844+
<row>
6845+
<entry><literal><function>set_masklen</function>(<type>cidr</type>, <type>int</type>)</literal></entry>
6846+
<entry><type>cidr</type></entry>
6847+
<entry>set netmask length for <type>cidr</type> value</entry>
6848+
<entry><literal>set_masklen('192.168.1.0/24'::cidr, 16)</literal></entry>
6849+
<entry><literal>192.168.0.0/16</literal></entry>
6850+
</row>
68466851
<row>
68476852
<entry><literal><function>netmask</function>(<type>inet</type>)</literal></entry>
68486853
<entry><type>inet</type></entry>
@@ -6875,6 +6880,13 @@ SELECT pg_sleep(1.5);
68756880
<entry><literal><function>abbrev</function>(<type>inet</type>)</literal></entry>
68766881
<entry><type>text</type></entry>
68776882
<entry>abbreviated display format as text</entry>
6883+
<entry><literal>abbrev(inet '10.1.0.0/16')</literal></entry>
6884+
<entry><literal>10.1.0.0/16</literal></entry>
6885+
</row>
6886+
<row>
6887+
<entry><literal><function>abbrev</function>(<type>cidr</type>)</literal></entry>
6888+
<entry><type>text</type></entry>
6889+
<entry>abbreviated display format as text</entry>
68786890
<entry><literal>abbrev(cidr '10.1.0.0/16')</literal></entry>
68796891
<entry><literal>10.1/16</literal></entry>
68806892
</row>
@@ -6890,6 +6902,22 @@ SELECT pg_sleep(1.5);
68906902
</tgroup>
68916903
</table>
68926904

6905+
<para>
6906+
Any <type>cidr</> value can be cast to <type>inet</> implicitly
6907+
or explicitly; therefore, the functions shown above as operating on
6908+
<type>inet</> also work on <type>cidr</> values. (Where there are
6909+
separate functions for <type>inet</> and <type>cidr</>, it is because
6910+
the behavior should be different for the two cases.)
6911+
Also, it is permitted to cast an <type>inet</> value to <type>cidr</>.
6912+
When this is done, any bits to the right of the netmask are silently zeroed
6913+
to create a valid <type>cidr</> value.
6914+
In addition,
6915+
you can cast a text value to <type>inet</> or <type>cidr</>
6916+
using normal casting syntax: for example,
6917+
<literal>inet(<replaceable>expression</>)</literal> or
6918+
<literal><replaceable>colname</>::cidr</literal>.
6919+
</para>
6920+
68936921
<para>
68946922
<xref linkend="macaddr-functions-table"> shows the functions
68956923
available for use with the <type>macaddr</type> type. The function

‎src/backend/optimizer/path/indxpath.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.197 2006/01/25 20:29:23 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.198 2006/01/26 02:35:49 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -2024,8 +2024,6 @@ match_special_index_operator(Expr *clause, Oid opclass,
20242024

20252025
caseOID_INET_SUB_OP:
20262026
caseOID_INET_SUBEQ_OP:
2027-
caseOID_CIDR_SUB_OP:
2028-
caseOID_CIDR_SUBEQ_OP:
20292027
isIndexable= true;
20302028
break;
20312029
}
@@ -2087,12 +2085,8 @@ match_special_index_operator(Expr *clause, Oid opclass,
20872085

20882086
caseOID_INET_SUB_OP:
20892087
caseOID_INET_SUBEQ_OP:
2090-
isIndexable= (opclass==INET_BTREE_OPS_OID);
2091-
break;
2092-
2093-
caseOID_CIDR_SUB_OP:
2094-
caseOID_CIDR_SUBEQ_OP:
2095-
isIndexable= (opclass==CIDR_BTREE_OPS_OID);
2088+
isIndexable= (opclass==INET_BTREE_OPS_OID||
2089+
opclass==CIDR_BTREE_OPS_OID);
20962090
break;
20972091
}
20982092

@@ -2317,8 +2311,6 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opclass)
23172311

23182312
caseOID_INET_SUB_OP:
23192313
caseOID_INET_SUBEQ_OP:
2320-
caseOID_CIDR_SUB_OP:
2321-
caseOID_CIDR_SUBEQ_OP:
23222314
result=network_prefix_quals(leftop,expr_op,opclass,
23232315
patt->constvalue);
23242316
break;
@@ -2681,14 +2673,6 @@ network_prefix_quals(Node *leftop, Oid expr_op, Oid opclass, Datum rightop)
26812673
datatype=INETOID;
26822674
is_eq= true;
26832675
break;
2684-
caseOID_CIDR_SUB_OP:
2685-
datatype=CIDROID;
2686-
is_eq= false;
2687-
break;
2688-
caseOID_CIDR_SUBEQ_OP:
2689-
datatype=CIDROID;
2690-
is_eq= true;
2691-
break;
26922676
default:
26932677
elog(ERROR,"unexpected operator: %u",expr_op);
26942678
returnNIL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp