aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/network.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-06-13 21:57:28 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-06-13 21:57:28 +0000
commit950d047ec5913de0ff6f3badf636667926df0387 (patch)
tree3d97eae31381690a3af2d7321112e74649875cde /src/backend/utils/adt/network.c
parent0e338bba42df2ec25d4507613c14ded7269a5db8 (diff)
downloadpostgresql-950d047ec5913de0ff6f3badf636667926df0387.tar.gz
postgresql-950d047ec5913de0ff6f3badf636667926df0387.zip
Give inet/cidr datatypes their own hash function that ignores the inet vs
cidr type bit, the same as network_eq does. This is needed for hash joins and hash aggregation to work correctly on these types. Per bug report from Michael Fuhr, 2004-04-13. Also, improve hash function for int8 as suggested by Greg Stark.
Diffstat (limited to 'src/backend/utils/adt/network.c')
-rw-r--r--src/backend/utils/adt/network.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index 32ebc66fd02..715880e307b 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -1,18 +1,18 @@
/*
* PostgreSQL type definitions for the INET and CIDR types.
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.51 2004/06/13 19:56:50 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.52 2004/06/13 21:57:25 tgl Exp $
*
* Jon Postel RIP 16 Oct 1998
*/
#include "postgres.h"
-#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include "access/hash.h"
#include "catalog/pg_type.h"
#include "libpq/ip.h"
#include "libpq/libpq-be.h"
@@ -42,7 +42,7 @@ static int ip_addrsize(inet *inetptr);
(((inet_struct *)VARDATA(inetptr))->type)
#define ip_addr(inetptr) \
- (((inet_struct *)VARDATA(inetptr))->ip_addr)
+ (((inet_struct *)VARDATA(inetptr))->ipaddr)
#define ip_maxbits(inetptr) \
(ip_family(inetptr) == PGSQL_AF_INET ? 32 : 128)
@@ -60,7 +60,7 @@ ip_addrsize(inet *inetptr)
case PGSQL_AF_INET6:
return 16;
default:
- return -1;
+ return 0;
}
}
@@ -425,6 +425,27 @@ network_ne(PG_FUNCTION_ARGS)
}
/*
+ * Support function for hash indexes on inet/cidr.
+ *
+ * Since network_cmp considers only ip_family, ip_bits, and ip_addr,
+ * only these fields may be used in the hash; in particular don't use type.
+ */
+Datum
+hashinet(PG_FUNCTION_ARGS)
+{
+ inet *addr = PG_GETARG_INET_P(0);
+ int addrsize = ip_addrsize(addr);
+ unsigned char key[sizeof(inet_struct)];
+
+ Assert(addrsize + 2 <= sizeof(key));
+ key[0] = ip_family(addr);
+ key[1] = ip_bits(addr);
+ memcpy(key + 2, ip_addr(addr), addrsize);
+
+ return hash_any(key, addrsize + 2);
+}
+
+/*
* Boolean network-inclusion tests.
*/
Datum