Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
202548d6
Commit
202548d6
authored
Jun 09, 2001
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Teach convert_to_scalar about datatypes timetz, inet, cidr, macaddr.
parent
e8637ec9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
3 deletions
+76
-3
src/backend/utils/adt/network.c
src/backend/utils/adt/network.c
+51
-1
src/backend/utils/adt/selfuncs.c
src/backend/utils/adt/selfuncs.c
+23
-1
src/include/utils/builtins.h
src/include/utils/builtins.h
+2
-1
No files found.
src/backend/utils/adt/network.c
View file @
202548d6
...
...
@@ -3,7 +3,7 @@
* is for IP V4 CIDR notation, but prepared for V6: just
* add the necessary bits where the comments indicate.
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.
29 2001/03/22 03:59:52 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.
30 2001/06/09 22:16:18 tgl
Exp $
*
* Jon Postel RIP 16 Oct 1998
*/
...
...
@@ -16,6 +16,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include "catalog/pg_type.h"
#include "utils/builtins.h"
#include "utils/inet.h"
...
...
@@ -564,6 +565,55 @@ network_netmask(PG_FUNCTION_ARGS)
PG_RETURN_INET_P
(
dst
);
}
/*
* Convert a value of a network datatype to an approximate scalar value.
* This is used for estimating selectivities of inequality operators
* involving network types.
*
* Currently, inet/cidr values are simply converted to the IPv4 address;
* this will need more thought when IPv6 is supported too. MAC addresses
* are converted to their numeric equivalent as well (OK since we have a
* double to play in).
*/
double
convert_network_to_scalar
(
Datum
value
,
Oid
typid
)
{
switch
(
typid
)
{
case
INETOID
:
case
CIDROID
:
{
inet
*
ip
=
DatumGetInetP
(
value
);
if
(
ip_family
(
ip
)
==
AF_INET
)
return
(
double
)
ip_v4addr
(
ip
);
else
/* Go for an IPV6 address here, before faulting out: */
elog
(
ERROR
,
"unknown address family (%d)"
,
ip_family
(
ip
));
break
;
}
case
MACADDROID
:
{
macaddr
*
mac
=
DatumGetMacaddrP
(
value
);
double
res
;
res
=
(
mac
->
a
<<
16
)
|
(
mac
->
b
<<
8
)
|
(
mac
->
c
);
res
*=
256
*
256
*
256
;
res
+=
(
mac
->
d
<<
16
)
|
(
mac
->
e
<<
8
)
|
(
mac
->
f
);
return
res
;
}
}
/*
* Can't get here unless someone tries to use scalarltsel/scalargtsel
* on an operator with one network and one non-network operand.
*/
elog
(
ERROR
,
"convert_network_to_scalar: unsupported type %u"
,
typid
);
return
0
;
}
/*
* Bitwise comparison for V4 addresses. Add V6 implementation!
*/
...
...
src/backend/utils/adt/selfuncs.c
View file @
202548d6
...
...
@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.9
2 2001/06/05 05:26:04
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.9
3 2001/06/09 22:16:18
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -1326,6 +1326,9 @@ icnlikejoinsel(PG_FUNCTION_ARGS)
* scale needed by scalarltsel()/scalargtsel().
* Returns "true" if successful.
*
* XXX this routine is a hack: ideally we should look up the conversion
* subroutines in pg_type.
*
* All numeric datatypes are simply converted to their equivalent
* "double" values. XXX what about NUMERIC values that are outside
* the range of "double"?
...
...
@@ -1398,10 +1401,22 @@ convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue,
case
RELTIMEOID
:
case
TINTERVALOID
:
case
TIMEOID
:
case
TIMETZOID
:
*
scaledvalue
=
convert_timevalue_to_scalar
(
value
,
valuetypid
);
*
scaledlobound
=
convert_timevalue_to_scalar
(
lobound
,
boundstypid
);
*
scaledhibound
=
convert_timevalue_to_scalar
(
hibound
,
boundstypid
);
return
true
;
/*
* Built-in network types
*/
case
INETOID
:
case
CIDROID
:
case
MACADDROID
:
*
scaledvalue
=
convert_network_to_scalar
(
value
,
valuetypid
);
*
scaledlobound
=
convert_network_to_scalar
(
lobound
,
boundstypid
);
*
scaledhibound
=
convert_network_to_scalar
(
hibound
,
boundstypid
);
return
true
;
}
/* Don't know how to convert */
return
false
;
...
...
@@ -1694,6 +1709,13 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
}
case
TIMEOID
:
return
DatumGetTimeADT
(
value
);
case
TIMETZOID
:
{
TimeTzADT
*
timetz
=
DatumGetTimeTzADTP
(
value
);
/* use GMT-equivalent time */
return
(
double
)
(
timetz
->
time
+
timetz
->
zone
);
}
}
/*
...
...
src/include/utils/builtins.h
View file @
202548d6
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: builtins.h,v 1.1
49 2001/06/07 00:09:31 momjian
Exp $
* $Id: builtins.h,v 1.1
50 2001/06/09 22:16:17 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -514,6 +514,7 @@ extern Datum network_broadcast(PG_FUNCTION_ARGS);
extern
Datum
network_host
(
PG_FUNCTION_ARGS
);
extern
Datum
network_show
(
PG_FUNCTION_ARGS
);
extern
Datum
network_abbrev
(
PG_FUNCTION_ARGS
);
extern
double
convert_network_to_scalar
(
Datum
value
,
Oid
typid
);
/* mac.c */
extern
Datum
macaddr_in
(
PG_FUNCTION_ARGS
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment