The following query takes approx. 3-5+ minutes
to complete. I would like to get this down to around
2-3 seconds. Other RDBMS complete it in <1 second.

I am running 8.0.1 on XP P4 2.6 1GB for dev work. 

select i.internalid, c.code
from local.internal i
inner join country.ip c on
(i.ip between c.startip and c.endip)

Nested Loop  (cost=167.59..7135187.85 rows=31701997
width=10) (actual
time=63.000..776094.000 rows=5235 loops=1)
  Join Filter: ((inner.ip >= outer.startip) AND
(inner.ip <=
  ->  Seq Scan on ip c  (cost=0.00..2071.02 rows=54502
(actual time=0.000..313.000 rows=54502 loops=1)
  ->  Materialize  (cost=167.59..219.94 rows=5235
width=15) (actual
time=0.000..2.973 rows=5235 loops=54502)
        ->  Seq Scan on internal i (cost=0.00..162.35
width=15) (actual time=0.000..16.000 rows=5235
Total runtime: 776110.000 ms

-- data from
CREATE TABLE country.ip -- 54,502 rows
  startip inet NOT NULL,
  endip inet NOT NULL,
  code char(2) NOT NULL,
  CONSTRAINT ip_pkey PRIMARY KEY (startip, endip)
-- 1,,, US
-- 2,,, US

CREATE TABLE local.internal -- 5000+ rows
  internalid serial NOT NULL,
  ip inet NOT NULL,
  port int2 NOT NULL,
  CONSTRAINT internal_pkey PRIMARY KEY (internalid)
CREATE INDEX ip_idx ON local.internal (ip);
-- 1,, 80
-- 2,, 80
-- 3,, 443

have tried many settings with no improvement
max_connections = 50
shared_buffers = 30000
work_mem = 2048
sort_mem  = 2048

Have tried many different indexes with no help:
CREATE INDEX endip_idx  ON country.ip;
CREATE INDEX startip_idx  ON country.ip;
CREATE UNIQUE INDEX e_s_idx ON country.ip
  (endip, startip);

Any suggestions would be greatly appreciated.

Celebrate Yahoo!'s 10th Birthday! 
Yahoo! Netrospective: 100 Moments of the Web

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to