Lists: | pgsql-sql |
---|
From: | Georgos Siganos <siganos(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Question about a CIDR based query |
Date: | 2004-06-24 20:43:08 |
Message-ID: | ebba5a930406241343173046c7@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
Hello,
Consider that I have the following table:
Create Table tmp(
route_id int NOT NULL,
route cidr NOT NULL,
Data varchar(100) NOT NULL)
The table contains ~40,000 routes and I have an index on route.
The query I am interested in is:
select * from tmp where route >>= some_cidr
The index on route is not used and I get a sequential scan. The index is
used only for the <<= operator.
Any idea how I can make the query run faster?
Thanks,
George
From: | Josh Berkus <josh(at)agliodbs(dot)com> |
---|---|
To: | Georgos Siganos <siganos(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Question about a CIDR based query |
Date: | 2004-06-25 16:00:08 |
Message-ID: | 200406250900.08312.josh@agliodbs.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
Georgos,
> select * from tmp where route >>= some_cidr
Can you post an EXPLAIN ANALYZE for this? And when's the last time you ran
ANALYZE on the table?
> The index on route is not used and I get a sequential scan. The index is
> used only for the <<= operator.
Most likely Postgres thinks that the >>= query is returning 60% of your table,
which makes indexes useless.
--
Josh Berkus
Aglio Database Solutions
San Francisco
From: | siganos(at)gmail(dot)com (George Siganos) |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Question about a CIDR based query |
Date: | 2004-06-26 23:06:15 |
Message-ID: | ebba5a93.0406261506.7a0f7558@posting.google.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
I did a vacuum analyze before I run the following explain
June_03=# explain select * from tmp where route >>='62.1.1.0/24';
QUERY PLAN
----------------------------------------------------------------
Seq Scan on tmp (cost=0.00..606.60 rows=14544 width=33)
Filter: (route >>= '62.1.1.0/24'::cidr)
(2 rows)
The select returns just one route,
Thanks
josh(at)agliodbs(dot)com (Josh Berkus) wrote in message news:<200406250900(dot)08312(dot)josh(at)agliodbs(dot)com>...
> Georgos,
>
> > select * from tmp where route >>= some_cidr
>
> Can you post an EXPLAIN ANALYZE for this? And when's the last time you ran
> ANALYZE on the table?
>
> > The index on route is not used and I get a sequential scan. The index is
> > used only for the <<= operator.
>
> Most likely Postgres thinks that the >>= query is returning 60% of your table,
> which makes indexes useless.
>
> --
> Josh Berkus
> Aglio Database Solutions
> San Francisco
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
From: | Josh Berkus <josh(at)agliodbs(dot)com> |
---|---|
To: | siganos(at)gmail(dot)com (George Siganos), pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Question about a CIDR based query |
Date: | 2004-06-29 23:52:24 |
Message-ID: | 200406291652.24900.josh@agliodbs.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
George,
Um, no, I need an EXPLAIN ANALYZE, not just an EXPLAIN. Thanks.
> June_03=# explain select * from tmp where route >>='62.1.1.0/24';
> QUERY PLAN
> ----------------------------------------------------------------
> Seq Scan on tmp (cost=0.00..606.60 rows=14544 width=33)
> Filter: (route >>= '62.1.1.0/24'::cidr)
--
-Josh Berkus
Aglio Database Solutions
San Francisco
From: | Josh Berkus <josh(at)agliodbs(dot)com> |
---|---|
To: | siganos(at)gmail(dot)com (George Siganos), pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Question about a CIDR based query |
Date: | 2004-06-30 03:49:06 |
Message-ID: | 200406292049.06283.josh@agliodbs.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
George,
> Um, no, I need an EXPLAIN ANALYZE, not just an EXPLAIN. Thanks.
>
> > June_03=# explain select * from tmp where route >>='62.1.1.0/24';
> > QUERY PLAN
> > ----------------------------------------------------------------
> > Seq Scan on tmp (cost=0.00..606.60 rows=14544 width=33)
> > Filter: (route >>= '62.1.1.0/24'::cidr)
Oh, and also a SELECT VERSION(); would be nice.
--
Josh Berkus
Aglio Database Solutions
San Francisco
From: | siganos(at)gmail(dot)com (George Siganos) |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Question about a CIDR based query |
Date: | 2004-07-02 17:39:14 |
Message-ID: | ebba5a93.0407020939.3734121b@posting.google.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
Hi Josh,
Ok, first the explain analyze ....
June_03=# explain analyze select * from tmp where route
>>='62.1.1.0/24';
QUERY PLAN
-----------------------------------------------------------------------------------------------------------
Seq Scan on tmp (cost=0.00..606.60 rows=14544 width=33) (actual
time=3.862..15.366 rows=1 loops=1)
Filter: (route >>= '62.1.1.0/24'::cidr)
Total runtime: 15.493 ms
(3 rows)
And the version of postgres
June_03=# select version();
version
--------------------------------------------------------------------------------------------------------------------
PostgreSQL 7.4.1 on i686-pc-linux-gnu, compiled by GCC gcc (GCC)
3.3.2 20031022 (Gentoo Linux 3.3.2-r2, propolice)
(1 row)
Thanks,
Georgos
josh(at)agliodbs(dot)com (Josh Berkus) wrote in message news:<200406292049(dot)06283(dot)josh(at)agliodbs(dot)com>...
> George,
>
> > Um, no, I need an EXPLAIN ANALYZE, not just an EXPLAIN. Thanks.
> >
> > > June_03=# explain select * from tmp where route >>='62.1.1.0/24';
> > > QUERY PLAN
> > > ----------------------------------------------------------------
> > > Seq Scan on tmp (cost=0.00..606.60 rows=14544 width=33)
> > > Filter: (route >>= '62.1.1.0/24'::cidr)
>
> Oh, and also a SELECT VERSION(); would be nice.