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

Seq scan of table?

I am trying to tune my database and I discovered one select that does a
seq scan on a table but I can't see why... All the join fields are indexed
and I am returning just one record, so no sort is done.
Does it just pick seq scan for the heck of it or is it a reason?

Regards,

BTJ

-----------------------------------------------------------------------------------------------
Bjørn T Johansen (BSc,MNIF)
Executive Manager
bt*@havleik.no Havleik Consulting
Phone : +47 67 54 15 17 Conradisvei 4
Fax : +47 67 54 13 91 N-1338 Sandvika
Cellular : +47 926 93 298 http://www.havleik.no
-----------------------------------------------------------------------------------------------
"The stickers on the side of the box said "Supported Platforms: Windows
98, Windows NT 4.0,
Windows 2000 or better", so clearly Linux was a supported platform."
-----------------------------------------------------------------------------------------------
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #1
6 4971
Hello,
I am trying to tune my database and I discovered one select
that does a seq scan on a table but I can't see why... All
the join fields are indexed and I am returning just one
record, so no sort is done. Does it just pick seq scan for
the heck of it or is it a reason?


Are the join fields both of the exactly same type ? If no (eg : INT2 and
INT4)
you must cast in order to have the same type.

If the join fields are not of the same type, PostgreSQL will do a seq
scan.

I had exactly the same problem and learned here that tip :-)

Hope this help,

---------------------------------------
Bruno BAGUETTE - pg******@baguette.net

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #2
"Bjorn T Johansen" <bt*@havleik.no> writes:
I am trying to tune my database and I discovered one select that does a
seq scan on a table but I can't see why... All the join fields are indexed
and I am returning just one record, so no sort is done.
Does it just pick seq scan for the heck of it or is it a reason?


Who's to say, when you gave us no details? Show us the table schemas,
the exact query, and EXPLAIN ANALYZE output, and you might get useful
responses.

(btw, pgsql-performance would be a more appropriate list for this issue
than pgsql-general.)

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #3
Well, I just checked and all the join fields are of the same type...

BTJ
Hello,
I am trying to tune my database and I discovered one select
that does a seq scan on a table but I can't see why... All
the join fields are indexed and I am returning just one
record, so no sort is done. Does it just pick seq scan for
the heck of it or is it a reason?


Are the join fields both of the exactly same type ? If no (eg : INT2 and
INT4)
you must cast in order to have the same type.

If the join fields are not of the same type, PostgreSQL will do a seq
scan.

I had exactly the same problem and learned here that tip :-)

Hope this help,

---------------------------------------
Bruno BAGUETTE - pg******@baguette.net


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #4

"Bjorn T Johansen" <bt*@havleik.no> writes:
I am trying to tune my database and I discovered one select that does a
seq scan on a table but I can't see why... All the join fields are
indexed
and I am returning just one record, so no sort is done.
Does it just pick seq scan for the heck of it or is it a reason?


Who's to say, when you gave us no details? Show us the table schemas,
the exact query, and EXPLAIN ANALYZE output, and you might get useful
responses.

(btw, pgsql-performance would be a more appropriate list for this issue
than pgsql-general.)

regards, tom lane


Well, since the select involves 10-12 tables and a large sql, I just
thought I would try without all that information first... :)

And yes, pgsql-performance sounds like the right list....
BTJ

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 11 '05 #5
On Friday 05 September 2003 19:20, Neil Conway wrote:
On Fri, 2003-09-05 at 06:07, Richard Huxton wrote:
PG's parser will assume an explicit number is an int4 - if you need an
int8 etc you'll need to cast it, yes.


Or enclose the integer literal in single quotes.
You should find plenty of discussion of why in the archives, but the
short reason is that PG's type structure is quite flexible which means it
can't afford to make too many assumptions.


Well, it's definitely a bug in PG, it's "quite flexible" type structure
notwithstanding.


It certainly catches out a lot of people. I'd guess it's in the top three
issues in the general/sql lists. I'd guess part of the problem is it's so
silent. In some ways it would be better to issue a NOTICE every time a
typecast is forced in a comparison - irritating as that would be.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 11 '05 #6
Neil Conway <ne***@samurai.com> writes:
On Fri, 2003-09-05 at 06:07, Richard Huxton wrote:
You should find plenty of discussion of why in the archives, but the short
reason is that PG's type structure is quite flexible which means it can't
afford to make too many assumptions.
Well, it's definitely a bug in PG, it's "quite flexible" type structure
notwithstanding.


Let's say it's something we'd really like to fix ;-) ... and will, as
soon as we can figure out a cure that's not worse than the disease.
Dorking around with the semantics of numeric expressions has proven
to be a risky business. See, eg, the thread starting here:
http://archives.postgresql.org/pgsql...1/msg00468.php

regards, tom lane

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

Nov 11 '05 #7

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

Similar topics

6
by: Mahesh Hardikar | last post by:
Hi , Oracle 8.1.7.0.0 on HP-UX 11.0 I am a newbie as far as PL-SQL is concerned . I have Sybase/MSSQL T-SQL background. We have a report which uses a select statement . This select...
3
by: Marcus | last post by:
Hi I have a very complex sql query and a explain plan. I found there is a full table scan in ID=9 9 8 TABLE ACCESS (FULL) OF 'F_LOTTXNHIST' (Cost=84573 Card=185892...
2
by: SR | last post by:
Can someone please help me interpret this result set below and suggest on way I can speed up my table? What changes should I make? DBCC SHOWCONTIG scanning 'tblListing' table... Table:...
16
by: mamo74 | last post by:
Hello. I am administering a SQL Server (Enterprise Edition on Windows 2003) from some month and can't understand what is going on in the latest week (when the db grow a lot). The DB is around...
6
by: robert | last post by:
just got out of a "class" on EXPLAIN, from a 390/v6 maven. was told that ACCESSTYPE = 'R' in the plan_table meant a TableSpace scan. hmmmm. next step up (or down, depending on your outlook)...
10
by: Dia | last post by:
At the company I work job applicants are required to do a little test. The human resource manager recently had a candidate who claimed one of the questions was ambiguous. Dependent upon the...
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)
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
2
by: BD | last post by:
Hi, all. My background is more Oracle than db2. My skills at SQL tuning are quite limited. I'm running 8.2 on Windows. I'm tasked with some SQL optimization, and am doing some explain plans...
1
by: vivek samantray | last post by:
I have a query.When i try to create a index on one of the table the index gets created but when i take the output it stuill shows "TABLE ACCESS FULL" Please see below what i did QUERY ======...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.