473,396 Members | 2,154 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,396 software developers and data experts.

Mistake in my query or Index Scan on subquery failure? (7.4)

Hello,
I have a problem with this simple query :

explain select * from ref_artikel a where a.artnr in ( 351275 , 351346 ,
293082 ) LIMIT 20 OFFSET 0 ;
QUERY PLAN

----------------------------------------------------------------------------
------------------------------------------------------
Limit (cost=0.00..9.06 rows=3 width=299)
-> Index Scan using ref_artikel_pkey, ref_artikel_pkey, \
ref_artikel_pkey on ref_artikel a (cost=0.00..9.06 rows=3 width=299)
Index Cond: ((artnr = 351275) OR (artnr = 351346) OR (artnr =
293082))
(3 rows)

Is it okay , that the word ref_artikel_pkey will be repeated for each
condition ?

How can i optimize this, i have a number of up to 3000 "artnr" cond. to
check for equality
( and more tables joined over this query which i left away for better
understanding ) ,
is a "(x=1) or (x=2)..." faster than "x in 1,2... " at this large number of
checks ?

Maybe this is the hash-joined bug marked for this 7.4 postgresql....
I consider upgrading to 7.41 on another testing server....

Thx for ideas,
Andre

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

Nov 23 '05 #1
2 1586
Gellert, Andre wrote:
Hello,
I have a problem with this simple query :

explain select * from ref_artikel a where a.artnr in ( 351275 , 351346 ,
293082 ) LIMIT 20 OFFSET 0 ;
QUERY PLAN

----------------------------------------------------------------------------
------------------------------------------------------
Limit (cost=0.00..9.06 rows=3 width=299)
-> Index Scan using ref_artikel_pkey, ref_artikel_pkey, \
ref_artikel_pkey on ref_artikel a (cost=0.00..9.06 rows=3 width=299)
Index Cond: ((artnr = 351275) OR (artnr = 351346) OR (artnr =
293082))
(3 rows)

Is it okay , that the word ref_artikel_pkey will be repeated for each
condition ?

How can i optimize this, i have a number of up to 3000 "artnr" cond. to
check for equality
( and more tables joined over this query which i left away for better
understanding ) ,
is a "(x=1) or (x=2)..." faster than "x in 1,2... " at this large number of
checks ?

Maybe this is the hash-joined bug marked for this 7.4 postgresql....
I consider upgrading to 7.41 on another testing server....

Thx for ideas,
Andre

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

As far as I can see this is fine, especially for a small number of
values in the IN clause. If I understand you correctly the number of
values in the IN clause might extend to 3000. This would not be
particularly efficient and might end in a sequential scan.

For example,

explain select * from ref_artikel a where a.artnr in ( 351275 , 351346 ,
293082, ... <2997 more values> ) LIMIT 20 OFFSET 0 ;
A better method if you are going to use a lot of numbers would be something like the following:

-----
BEGIN;

CREATE TEMPORARY TABLE temp_num_2004_03_03 (temp_num int4);

INSERT INTO temp_num_2004_03_03 (351275);
....
INSERT INTO temp_num_2004_03_03 (293082);

CREATE INDEX temp_num_2004_03_03_temp_num_idx ON temp_num_2004_03_03 (temp_num);

SELECT * FROM ref_artikel a, temp_num_2004_03_03 b WHERE a.artnr=b.temp_num ORDER BY a.artnr LIMIT 20 OFFSET 0;

DROP INDEX temp_num_2004_03_03_temp_num_idx;
DROP TABLE temp_num_2004_03_03;

COMMIT/ABORT;
-----

This is especially true if you are going to use the set of numbers again in other queries that follow.

BTW, you will need to put an ORDER BY clause in your SELECT to guarentee the order of the rows that come back, especially when using the LIMIT/OFFSET clauses.

Nick

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #2
"Gellert, Andre" <AG******@ElectronicPartner.de> writes:
Is it okay , that the word ref_artikel_pkey will be repeated for each
condition ?


That's what it's supposed to do. EXPLAIN is trying to tell you that
this query involves three independent index probes, which should not be
very surprising.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #3

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

Similar topics

4
by: DBNovice | last post by:
I have a database that keeps records on the issue and failure of an item. Currently, the database is poorly desisned; therefore I'm performing queries to break the data into normalized tables and...
3
by: Paul Mateer | last post by:
Hi, I have been running some queries against a table in a my database and have noted an odd (at least it seems odd to me) performance issue. The table has approximately 5 million rows and...
2
by: Yonatan Goraly | last post by:
I have a query that uses the same view 6 times. It seems that the database engine is calculating the view each time. The result is very poor performance. The same query takes 2 sec with MS SQL,...
1
by: Alex Satrapa | last post by:
I have a table from which I'm trying to extract certain information. For historical reasons, we archive every action on a particular thing ('thing' is identified, funnily enough, by 'id'). So the...
8
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run...
1
by: Peter Alberer | last post by:
Hi there, i have a problem with a query that uses the result of a plsql function In the where clause: SELECT assignments.assignment_id, assignments.package_id AS package_id,...
0
by: rdnews | last post by:
Dear group, I got excellent help here a while back in optimizing a slow query, so I thought I'd try again with another one... I have a small table, around 3000 rows with two columns. One is a...
8
by: Michel Esber | last post by:
Hello, DB2 V8 FP 11 running on Linux. Given two tables: T_SW_ID (SW_ID INTEGER, SW_NAME VARCHAR); T_SW (MACHINE_ID varchar, SW_ID DECIMAL (8), VERSION varchar, Product_ID varchar)
10
by: Raj | last post by:
I have an MDC index on Big_A.Dt column. The following query always goes for a table scan. SELECT Key, Cd, Dt, SUM(Big_A ) FROM ( SELECT Big_A.Key , small_3.Cd,
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.