network address query - Mailing list pgsql-performance

From Litao Wu
Subject network address query
Date
Msg-id 20040701161247.98527.qmail@web13122.mail.yahoo.com
Whole thread Raw
In response to Re: reindex and copy - deadlock?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-performance
Hi,

I have query:
explain
SELECT *
FROM ip_tracking T, ip_map C
WHERE
  T.source_ip::inet >>= C.net;
                                        QUERY PLAN
-------------------------------------------------------------------------------------------
 Nested Loop  (cost=0.00..3894833367750.16
rows=51709297065144 width=111)
   Join Filter: ("outer".source_ip >>=
("inner".net)::inet)
   ->  Seq Scan on ip_tracking t
(cost=0.00..825050.68 rows=31093368 width=34)
   ->  Seq Scan on ip_map c  (cost=0.00..83686.66
rows=3326066 width=77)
(4 rows)

ip_tracking (
  pk_col int,
  source_ip inet,
  .. the rest...
)
There is one index
  ip_tracking_ip_idx btree (source_ip)

ip_map (
net cidr,
... the rest...)
Indexes: map_net_idx hash (net)

If I change ">>=" to "=", the query plan is:

 QUERY PLAN

--------------------------------------------------------------------------------------------------------------------------
 Nested Loop  (cost=0.00..10798882243.63 rows=31093368
width=111)
   ->  Seq Scan on ip_map c  (cost=0.00..83686.66
rows=3326066 width=77)
   ->  Index Scan using ip_tracking_ip_idx on
ip_tracking t  (cost=0.00..3236.72 rows=800 width=34)
         Index Cond: (t.source_ip =
("outer".net)::inet)
(4 rows)

This is my first time to deal network address type.

Is it possible to make a query use index with
operator of ">>=" like the above?

Thanks,





__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail

pgsql-performance by date:

Previous
From: Joseph Shraibman
Date:
Subject: planner and worst case scenario
Next
From: James Antill
Date:
Subject: Query gets slow when where clause increases