again on index usage

From: Daniel Kalchev <daniel(at)digsys(dot)bg>
To: pgsql-hackers(at)postgresql(dot)org
Subject: again on index usage
Date: 2002-01-07 18:41:07
Message-ID: 200201071841.UAA26328@dcave.digsys.bg
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

I have an table with ca 1.7 million records, with the following structure:

Table "iplog_gate200112"
Attribute | Type | Modifier
-----------+-----------+----------
ipaddr | inet |
input | bigint |
output | bigint |
router | text |
ipdate | timestamp |
Indices: iplog_gate200112_ipaddr_idx,
iplog_gate200112_ipdate_idx

the following query

explain
SELECT sum(input) FROM iplog_gate200112
WHERE
'2001-12-01 00:00:00+02' <= ipdate AND ipdate < '2001-12-02 00:00:00+02' AND
'2001-12-01 00:00:00+02' <= ipdate AND ipdate < '2002-01-01 00:00:00+02' AND
network_subeq(ipaddr, '193.68.240.0/20') AND 'uni-gw' ~ router;

results in

NOTICE: QUERY PLAN:

Aggregate (cost=51845.51..51845.51 rows=1 width=8)
-> Seq Scan on iplog_gate200112 (cost=0.00..51845.04 rows=190 width=8)

Why would it not want to use index scan?

Statistics for the table are as follows (from pg_statistic s, pg_attribute a,
pg_class c
where starelid = c.oid and attrelid = c.oid and staattnum = attnum
and relname = 'iplog_gate200112')

attname | attdispersion | starelid | staattnum | staop | stanullfrac |
stacommonfrac | stacommonval | staloval |
stahival
---------+---------------+-----------+-----------+-------+-------------+-------
--------+------------------------+------------------------+--------------------
----
ipaddr | 8.85397e-05 | 190565949 | 1 | 1203 | 0 |
0.000441917 | 192.92.129.1 | 192.92.129.0 | 212.72.197.154
input | 0.0039343 | 190565949 | 2 | 412 | 0 |
0.0183278 | 0 | 0 | 5929816798
output | 0.724808 | 190565949 | 3 | 412 | 0 |
0.835018 | 0 | 0 | 2639435033
router | 0.222113 | 190565949 | 4 | 664 | 0 |
0.416541 | sofia5 | bourgas1 | varna3
ipdate | 0.014311 | 190565949 | 5 | 1322 | 0 |
0.0580676 | 2001-12-04 00:00:00+02 | 2001-12-01 00:00:00+02 | 2001-12-31
00:00:00+02
(5 rows)

The query

explain
SELECT sum(input) FROM iplog_gate200112
WHERE
ipdate < '2001-12-01 00:00:00+02' AND
network_subeq(ipaddr, '193.68.240.0/20') AND 'uni-gw' ~ router;

produces

Aggregate (cost=4.91..4.91 rows=1 width=8)
-> Index Scan using iplog_gate200112_ipdate_idx on iplog_gate200112
(cost=0.00..4.91 rows=1 width=8)

Note there are no records with ipdate < '2001-12-01 00:00:00+02' in the table.

Could anyone sched some light? This is on 7.1.3.

Daniel

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2002-01-07 18:56:45 Re: [HACKERS] pgcryto strangeness...
Previous Message Tom Lane 2002-01-07 18:38:38 Re: Why MemoryContextSwitch in ExecRelCheck ?