I expected Postgresql to use an indexed access method, but in certain cases
it is using a sequential scan. Details are below:
Table:
P1_NRN_ROAD (
sobjid int8 primary key,
v int8 not null,
ord int2 not null)
* The table contains 1.1 million rows.
* Column 'v' exhibits very high selectivity: "select count(*) from (select
distinct v from p1_nrn_road) A" returns 1,051,276.
* The table contains one index: P1_NRN_ROAD_V (v, sobjid) (The index
includes the column sobjid because the query projects this col, and its
inclusion in the index allows it to be serviced without accessing the
underlying table)
* The table was vacuumed and analyzed after the index was created (I even
set the col statistics to 1000)
Now, for the queries:
QUERY 1: select sobjid from p1_nrn_road where v = 222649748109036 5991
The plan is "Index scan using p1_nrn_road_v on p1_nrn_road (cost=0.00..6.5 2
rows=2 width=8)"
The plan was close: only one row is returned. Everything is fine here.
QUERY 2: select sobjid from p1_nrn_road where v = 1
The plan is "Seq Scan on p1_nrn_road (cost=0.00..221 58.54 rows=2 width=8)"
The plan is wrong: "select min(v) from p1_nrn_road" returns
222649748109036 5991, which indicates that the query will return 0 rows.
I can't understand why a sequential scan is selected for query 2 when the
plan suggests only two rows (high selectivity) are expected.
Oracle doesn't behave like this, and I expect Postgresql to behave similarly
(are my expectations too high?)
Thank you in advance for any assistance you can provide. 3 2049
Kevin Macdonald wrote: QUERY 2: select sobjid from p1_nrn_road where v = 1
The plan is "Seq Scan on p1_nrn_road (cost=0.00..221 58.54 rows=2 width=8)"
The plan is wrong: "select min(v) from p1_nrn_road" returns 222649748109036 5991, which indicates that the query will return 0 rows.
Hy Kevin,
please try
select sobjid from p1_nrn_road where v = '1'
(notice quotes)
I'm not sure but i think indexes that consists of more than 2 rows have
to be casted to char in PG.
Daniel.
"Kevin Macdonald" <no****@please. thankyou> writes: QUERY 2: select sobjid from p1_nrn_road where v = 1
The plan is "Seq Scan on p1_nrn_road (cost=0.00..221 58.54 rows=2 width=8)"
Incidentally, you should send the whole plan. In general you should send all
the information you have, not just the parts you think are relevant. The next
line would have clearly shown the problem to someone who knew what to look
for.
try
where v = '1'
or
where v = 1::bigint
The problem is that in 7.4 and previous indexes can't be used for cross-type
comparisons and integer constants are assumed to be integer not bigint type.
If you leave it in quotes then postgres doesn't pick a type until it looks at
what you're comparing it with. Or if you cast it then you force it to be a
bigint=bigint comparison.
7.5 will avoid this problem.
--
greg
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly
On Thu, 22 Jul 2004 04:34:26 GMT, "Kevin Macdonald"
<no****@please. thankyou> wrote: (The index includes the column sobjid because the query projects this col, and its inclusion in the index allows it to be serviced without accessing the underlying table)
No, Postgres always consults the heap to get the desired values. The
most obvious reason is that visibility information is stored in heap
tuples but not in index tuples.
Servus
Manfred
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 statement
joins 15 tables . SOme of the tables are outer joined.
It runs much slow when parameters (From & To Date) are for a month.
|
by: ryan |
last post by:
Hi Everyone,
I'm having trouble convincing myself that Oracle is executing a query
of mine as efficiently as possible, and I'm looking for a little
guidance.
The situation is pretty simple. I just have two tables, PARENT and
CHILD.
PARENT(
pkey int primary key,
|
by: Ruth |
last post by:
Hi All
I am not a DBA, but a unix administrator.
After our DBA's upgraded from oracle 8.0.5 to oracle 8.1.7.4 on our
test server, we have noticed a big slow down in our application
(acocobol). From ~10mins to ~45mins.
Server info:
|
by: Jim Garrison |
last post by:
Scenario:
1) Create a GLOBAL TEMPORARY table and populate it with
one (1) row.
2) Join that table to another with about 1 million rows.
The join condition selects a few hundred rows.
Performance: 4 seconds, the system is doing a full-table
scan of the second table, and the Explain Plan output
|
by: selma |
last post by:
I am puzzled by visual explain for a simple query ( select * from
mytable ) chooses an index scan. That index has only a single column
and the table has 30 columns not covered by the index. When running
explain for another database (same schema structure), it showed table
scan. These are all production databases with >10 GB of real data, and
stats are all up to date. Reorgchk showed nothing bad.
Per chance visual explain GUI was acting...
| |
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)
|
by: Bob Alston |
last post by:
I am looking for others who have built systems to scan documents, index
them and then make them accessible from an Access database. My
environment is a nonprofit with about 20-25 case workers who use
laptops. They have Access databases on their laptops and the data is
replicated.
The idea is that each case worker would scan their own documents,
either remotely or back at the office.
And NO I am not planning to store the scanned...
|
by: Vinod Sadanandan |
last post by:
Table Partition Performance analysis
============================================
Collection of Statistics for Cost-Based Optimization/DBMS_STATS vs. ANALYZE
The cost-based approach relies on statistics and if the cost-based
Approach is used , then statistics should be gernerated for all tables, clusters, and all types of indexes accessed by SQL statements. If the size and data distribution of your tables change frequently, then...
|
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
on various queries.
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |