473,471 Members | 4,650 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Index Using

hello,

I have in db table with 3 columns... table name is l_model_to_part
columns: i_model_id, i_part_id, i_year

I have index on every column separately and primary key is (i_model_id,
i_part_id, i_year)

when I use: EXPLAIN SELECT * FROM l_model_to_part WHERE i_part_id=234;
QUERY PLAN
----------------------------------------------------------------------------------
Index Scan using index_20 on l_model_to_part (cost=0.00..3.37 rows=10
width=12)
Index Cond: (i_part_id = 234)
when I use: EXPLAIN SELECT * FROM l_model_to_part WHERE i_model_id=234;
QUERY PLAN
---------------------------------------------------------------------
Seq Scan on l_model_to_part (cost=0.00..1400.59 rows=866 width=12)
Filter: (i_model_id = 234)

but, when I use: EXPLAIN SELECT * FROM l_model_to_part WHERE
i_model_id=234 AND i_model_id=456;
QUERY PLAN
-----------------------------------------------------------------------------------
Index Scan using index_50 on l_model_to_part (cost=0.00..41.84
rows=11 width=12)
Index Cond: ((i_model_id = 234) AND (i_model_id = 456))

my question is, why postgres doesn't use index_50 in second query???
when I create this structure in clear db, everything is all right...

thanx, hlavki
--

[ miso hlavac ][ hl****@medium13.sk ][ http://hlavki.sk ]
[ icq:94900232 ][ callto://hlavki ]

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

Nov 23 '05 #1
2 1084
Michal Hlavac wrote:
my question is, why postgres doesn't use index_50 in second query???
when I create this structure in clear db, everything is all right...


of course, index_50 is BTREE index with one column (i_model_id)...

thanx, hlk

--

[ miso hlavac ][ hl****@medium13.sk ][ http://hlavki.sk ]
[ icq:94900232 ][ callto://hlavki ]

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

Nov 23 '05 #2
On Mon, 19 Jul 2004, Michal Hlavac wrote:
hello,

I have in db table with 3 columns... table name is l_model_to_part
columns: i_model_id, i_part_id, i_year

I have index on every column separately and primary key is (i_model_id,
i_part_id, i_year)

when I use: EXPLAIN SELECT * FROM l_model_to_part WHERE i_part_id=234;
QUERY PLAN
----------------------------------------------------------------------------------
Index Scan using index_20 on l_model_to_part (cost=0.00..3.37 rows=10
width=12)
Index Cond: (i_part_id = 234)
when I use: EXPLAIN SELECT * FROM l_model_to_part WHERE i_model_id=234;
QUERY PLAN
---------------------------------------------------------------------
Seq Scan on l_model_to_part (cost=0.00..1400.59 rows=866 width=12)
Filter: (i_model_id = 234)

but, when I use: EXPLAIN SELECT * FROM l_model_to_part WHERE
i_model_id=234 AND i_model_id=456;
QUERY PLAN
-----------------------------------------------------------------------------------
Index Scan using index_50 on l_model_to_part (cost=0.00..41.84
rows=11 width=12)
Index Cond: ((i_model_id = 234) AND (i_model_id = 456))

my question is, why postgres doesn't use index_50 in second query???


How many rows are there in the table? It looks like it's probably simply
guessing that the 866 estimated rows is high enough to make the index scan
more expensive.

So the questions would be:
Is 866 a reasonable estimate of the number of rows with i_model_id=234?
What does explain analyze say for the second query with and without
set enable_seqscan=off?
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #3

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

Similar topics

5
by: Gerard M. Operana | last post by:
unsubscribe
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...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
9
by: WalterR | last post by:
This is my first time here, so there may be earlier relevant threads of which I am unaware. Though my experience with DB2 is not extensive, such as it is was under OS/390 or equ. My main...
2
by: Hervé Piedvache | last post by:
Hi, I have may be a stupid question, but I'm a little surprised with some explains I have, using date fields ... I would like to understand exactly when index are used ... I'm using...
3
by: Eric Davies | last post by:
We've implemented a 5D box data type and have implemented both RTree and GiST access methods under PostgresSQL 7.4 and PostgresSQL 7.4.1. The 5D box internally looks like: struct Box5D{ float...
2
by: Pavel Stehule | last post by:
Hello, Pg make query 1. and 2. very fast (use index), but for query 3. dont use index. I can solve its using select union, but I readed so pg 7.5 don't problem with OR operator. I use cvs pg. I...
2
by: bobby_b_ | last post by:
I have a table where fields 1 and 2 make up the primary key. Because of this, I have a unique composite index on fields 1 and 2 (as required by DB2). Now my question is: Fields 1 and 2 are also...
1
by: Steffen Stellwag | last post by:
Truely is often better to scan a table in full passing by an index , but if you can force the optimizer to use an index via a hint for testing and comparing the results. But the index in the...
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...
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,...
1
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.