473,408 Members | 2,399 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

why is this index not being used?


Hey all,

I'm using PostgreSQL 7.3.4.

I have a query that isn't using a particular index, and I'm wondering why.

The query is:
select i.ItemID, d.Extension from ITEM i, SHARING s, DOCUMENT d where
i.ItemID = d.ItemID AND s.ItemID = i.DomainID AND s.UserIDOfSharee = 12

Item's primary key is ItemID.
Document's primary key is ItemID.
Sharing's primary key is (ItemID, UserIDOfSharee).
Item has index item_ix_item_3_idx on (DomainID, ItemID).
Sharing has index sharing_ix_sharing_1_idx on (UserIDOfSharee, ItemID).

Explain says:
Hash Join (cost=25526.26..31797.78 rows=6105 width=23)
Hash Cond: ("outer".itemid = "inner".itemid)
-> Seq Scan on document d (cost=0.00..5629.14 rows=113214 width=11)
-> Hash (cost=25502.60..25502.60 rows=9465 width=12)
-> Merge Join (cost=310.16..25502.60 rows=9465 width=12)
Merge Cond: ("outer".domainid = "inner".itemid)
-> Index Scan using item_ix_item_3_idx on item i
(cost=0.00..24634.71 rows=175519 width=8)
-> Sort (cost=310.16..310.47 rows=123 width=4)
Sort Key: s.itemid
-> Index Scan using sharing_ix_sharing_1_idx on
sharing s (cost=0.00..305.88 rows=123 width=4)
Index Cond: (useridofsharee = 12)
Why is there a Seq Scan on Document? How can I get it to use Document's
primary key?
Thanks!
Mike


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #1
2 1451
BTW -- We vacuum nightly, and running vacuum analyze doesn't make a
difference.

Hey all,

I'm using PostgreSQL 7.3.4.

I have a query that isn't using a particular index, and I'm wondering
why.

The query is:
select i.ItemID, d.Extension from ITEM i, SHARING s, DOCUMENT d where
i.ItemID = d.ItemID AND s.ItemID = i.DomainID AND s.UserIDOfSharee = 12

Item's primary key is ItemID.
Document's primary key is ItemID.
Sharing's primary key is (ItemID, UserIDOfSharee).
Item has index item_ix_item_3_idx on (DomainID, ItemID).
Sharing has index sharing_ix_sharing_1_idx on (UserIDOfSharee, ItemID).

Explain says:
Hash Join (cost=25526.26..31797.78 rows=6105 width=23)
Hash Cond: ("outer".itemid = "inner".itemid)
-> Seq Scan on document d (cost=0.00..5629.14 rows=113214 width=11)
-> Hash (cost=25502.60..25502.60 rows=9465 width=12)
-> Merge Join (cost=310.16..25502.60 rows=9465 width=12)
Merge Cond: ("outer".domainid = "inner".itemid)
-> Index Scan using item_ix_item_3_idx on item i
(cost=0.00..24634.71 rows=175519 width=8)
-> Sort (cost=310.16..310.47 rows=123 width=4)
Sort Key: s.itemid
-> Index Scan using sharing_ix_sharing_1_idx on
sharing s (cost=0.00..305.88 rows=123 width=4)
Index Cond: (useridofsharee = 12)
Why is there a Seq Scan on Document? How can I get it to use
Document's primary key?
Thanks!
Mike


---------------------------(end of
broadcast)--------------------------- TIP 1: subscribe and unsubscribe
commands go to ma*******@postgresql.org



---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #2
You can always try and force it by doing

"set enable_seqscan=0"

I'd try explain analyze on the query with it on (=1) and off (=0) and
see why the planner likes seqscan better.

Gavin

mi**@linkify.com wrote:
BTW -- We vacuum nightly, and running vacuum analyze doesn't make a
difference.

Hey all,

I'm using PostgreSQL 7.3.4.

I have a query that isn't using a particular index, and I'm wondering
why.

The query is:
select i.ItemID, d.Extension from ITEM i, SHARING s, DOCUMENT d where
i.ItemID = d.ItemID AND s.ItemID = i.DomainID AND s.UserIDOfSharee = 12

Item's primary key is ItemID.
Document's primary key is ItemID.
Sharing's primary key is (ItemID, UserIDOfSharee).
Item has index item_ix_item_3_idx on (DomainID, ItemID).
Sharing has index sharing_ix_sharing_1_idx on (UserIDOfSharee, ItemID).

Explain says:
Hash Join (cost=25526.26..31797.78 rows=6105 width=23)
Hash Cond: ("outer".itemid = "inner".itemid)
-> Seq Scan on document d (cost=0.00..5629.14 rows=113214 width=11)
-> Hash (cost=25502.60..25502.60 rows=9465 width=12)
-> Merge Join (cost=310.16..25502.60 rows=9465 width=12)
Merge Cond: ("outer".domainid = "inner".itemid)
-> Index Scan using item_ix_item_3_idx on item i
(cost=0.00..24634.71 rows=175519 width=8)
-> Sort (cost=310.16..310.47 rows=123 width=4)
Sort Key: s.itemid
-> Index Scan using sharing_ix_sharing_1_idx on
sharing s (cost=0.00..305.88 rows=123 width=4)
Index Cond: (useridofsharee = 12)
Why is there a Seq Scan on Document? How can I get it to use
Document's primary key?
Thanks!
Mike


---------------------------(end of
broadcast)--------------------------- TIP 1: subscribe and unsubscribe
commands go to ma*******@postgresql.org



---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Heiko | last post by:
Hello, is there any way (v$-view) to get informaion about how often an index hast been used since of starting the Database? Thanks for help Heiko
3
by: Phil Latio | last post by:
I am following a book on PHP and MySQL and have come across the below SQL statement. CREATE TABLE users ( user_id MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT, username VARCHAR(20) NOT NULL,...
8
by: Andr? Queiroz | last post by:
Hi, I have a table with 10M records and col A has a index created on it. The data on that table has the same value for col A on all 10M records. After that I insert diferent values for that column...
4
by: maricel | last post by:
Could someone confirm which tablespace is being used when running ALTER & CREATE INDEX. Is it the tempspace or the tablespace where the table resides? Many thanks, maricel
3
by: usenet | last post by:
Hi. If I have an index (or primary key) on 3 columns, will a subset of these columns automatically be indexed also? For example: CREATE INDEX idx ON tbl(cola, colb, colc); Will: SELECT...
4
by: Deniz Bahar | last post by:
Hello all, Often times programs in C have arrays used as buffers and shared among different sections of code. The need arises to have position indicators to point to different parts of an array...
122
by: C.L. | last post by:
I was looking for a function or method that would return the index to the first matching element in a list. Coming from a C++ STL background, I thought it might be called "find". My first stop was...
33
by: John Salerno | last post by:
Is it possible to write a list comprehension for this so as to produce a list of two-item tuples? base_scores = range(8, 19) score_costs = print zip(base_scores, score_costs) I can't think...
6
by: Henry J. | last post by:
I have a composite index on two columns in a table. However, the index is not used in a query that restricts the 2nd column to a constant. If both columns are linked with columns in other join...
10
by: Ian | last post by:
Henry J. wrote: MDC *guarantees* clustering, whereas a table with a clustering index will eventually require maintenance (a.k.a. reorg) to maintain the cluster ratio. That's not to say that...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.