473,702 Members | 2,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bad planner results


I think this is just a bad case of "nested loops are costed wrong". But it's a
really really bad case. Like, even without any overlap in records looked up in
the nested loop I cannot imagine it ever being the wrong plan for these stats.
And Postgres is insistent on avoiding it, I have to disable both merge and
hash joins to get the 5ms nested loop join.

db=> EXPLAIN ANALYZE
SELECT distinct foo
FROM t1 join t1_t2 using (t1_id) join t2 using (t2_id)
WHERE bar = 232
;

QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Unique (cost=13036.55. .13056.98 rows=33 width=4) (actual time=1040.238.. 1040.368 rows=11 loops=1)
-> Sort (cost=13036.55. .13046.76 rows=4087 width=4) (actual time=1040.234.. 1040.291 rows=93 loops=1)
Sort Key: t1.foo
-> Hash Join (cost=267.80..1 2791.39 rows=4087 width=4) (actual time=12.511..10 40.084 rows=93 loops=1)
Hash Cond: ("outer".t1_ id = "inner".t1_ id)
-> Hash Join (cost=125.43..1 2587.72 rows=4087 width=4) (actual time=1.344..102 8.681 rows=93 loops=1)
Hash Cond: ("outer".t2_ id = "inner".t2_ id)
-> Seq Scan on t1_t2 (cost=0.00..950 7.28 rows=582828 width=8) (actual time=0.003..572 .865 rows=582828 loops=1)
-> Hash (cost=125.14..1 25.14 rows=117 width=4) (actual time=0.463..0.4 63 rows=0 loops=1)
-> Index Scan using idx_t2_bar on t2 (cost=0.00..125 .14 rows=117 width=4) (actual time=0.028..0.3 31 rows=95 loops=1)
Index Cond: (bar = 232)
-> Hash (cost=133.89..1 33.89 rows=3389 width=8) (actual time=10.537..10 .537 rows=0 loops=1)
-> Seq Scan on t1 (cost=0.00..133 .89 rows=3389 width=8) (actual time=0.018..6.4 22 rows=3389 loops=1)
Total runtime: 1040.752 ms
(14 rows)

db=> set enable_hashjoin = false;

QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Unique (cost=15715.48. .15735.92 rows=33 width=4) (actual time=98.095..98 .230 rows=11 loops=1)
-> Sort (cost=15715.48. .15725.70 rows=4087 width=4) (actual time=98.091..98 .151 rows=93 loops=1)
Sort Key: t1.foo
-> Merge Join (cost=15233.28. .15470.33 rows=4087 width=4) (actual time=85.827..97 .943 rows=93 loops=1)
Merge Cond: ("outer".t1_ id = "inner".t1_ id)
-> Index Scan using t1_pkey on t1 (cost=0.00..167 .27 rows=3389 width=8) (actual time=0.025..10. 374 rows=3291 loops=1)
-> Sort (cost=15233.28. .15243.50 rows=4087 width=4) (actual time=83.872..83 .936 rows=93 loops=1)
Sort Key: t1_t2.t1_id
-> Merge Join (cost=129.16..1 4988.13 rows=4087 width=4) (actual time=13.992..83 .729 rows=93 loops=1)
Merge Cond: ("outer".t2_ id = "inner".t2_ id)
-> Index Scan using t1_t2_all on t1_t2 (cost=0.00..136 00.12 rows=582828 width=8) (actual time=0.016..58. 722 rows=24533 loops=1)
-> Sort (cost=129.16..1 29.45 rows=117 width=4) (actual time=0.866..0.9 74 rows=163 loops=1)
Sort Key: t2.t2_id
-> Index Scan using idx_t2_bar on t2 (cost=0.00..125 .14 rows=117 width=4) (actual time=0.024..0.6 48 rows=95 loops=1)
Index Cond: (bar = 232)
Total runtime: 98.406 ms
(16 rows)

db=> set enable_hashjoin = false;
SET
db=> set enable_mergejoi n = false;
SET

QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Unique (cost=42624.09. .42644.53 rows=33 width=4) (actual time=4.257..4.3 90 rows=11 loops=1)
-> Sort (cost=42624.09. .42634.31 rows=4087 width=4) (actual time=4.255..4.3 10 rows=93 loops=1)
Sort Key: t1.foo
-> Nested Loop (cost=0.00..423 78.94 rows=4087 width=4) (actual time=0.249..4.0 95 rows=93 loops=1)
-> Nested Loop (cost=0.00..292 19.05 rows=4087 width=4) (actual time=0.220..2.2 47 rows=93 loops=1)
-> Index Scan using idx_t2_bar on t2 (cost=0.00..125 .14 rows=117 width=4) (actual time=0.029..0.3 72 rows=95 loops=1)
Index Cond: (bar = 232)
-> Index Scan using t1_t2_code on t1_t2 (cost=0.00..245 .63 rows=243 width=8) (actual time=0.012..0.0 15 rows=1 loops=95)
Index Cond: (t1_t2.t2_id = "outer".t2_ id)
-> Index Scan using t1_pkey on t1 (cost=0.00..3.2 1 rows=1 width=8) (actual time=0.012..0.0 15 rows=1 loops=93)
Index Cond: (t1.t1_id = "outer".t1_ id)
Total runtime: 4.564 ms
(12 rows)

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

Nov 23 '05 #1
1 1735
Greg Stark <gs*****@mit.ed u> writes:
I think this is just a bad case of "nested loops are costed wrong".


Looks to me like a statistical failure. Why does it think there will be
4000 rows out of that join when there are only 93?

regards, tom lane

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

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

Nov 23 '05 #2

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

Similar topics

0
1513
by: Michele | last post by:
Hi all, There's a web-based project I'm working on, which my boss insists should be implemented as a java web service: I know Java, but I'm a complete newcomer to web services, so I would badly need your enlightened opinion to figure out if my boss is right. I'm going to have two sorts of clients connecting to my (Apache) web server: a "planner" user, making schedules of activities to be performed and recording them on a MySQL database,...
0
2736
by: Shailesh | last post by:
Hello, I am using Oracle 10g and have configured OEM grid control. I am searching for some tool like Capacity Planner which was present in Oracle 9i OEM as a part of Oracle EM9i Management Packs. Somewhere I read on metalink, that the package is not yet supported (available) in 10g and will be introduced later. Is this true? If its not supported are there any other tools or facilities available for STORAGE CAPACITY PLANNING?
1
2487
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 only way to find out the current state of a particular combination of attributes is to "select distinct on (id, ...) ... order by date desc". In the examples below, I've taken real output from psql and done a global search/replace on various...
2
1278
by: Chris Travers | last post by:
Hi all; I suspect I know what the answer here is, but I thought I would ask anyway. How transparent are SQL language functions from the planner's perspective? For example if I create a table: CREATE TABLE proof_of_concept( poc_id serial primary key, testing text );
4
2813
by: Fabrizio | last post by:
HI, I need to create a form that shows a planner (with employees and working days ) where i can use a different colors for "busy" days and "available" days (i'll read the data from a Database). Is it an Excel sheet the only one way to create a Planner? Any other way? Thanks, Fabrizio
3
1854
by: Denis | last post by:
RE: http://www.rental-planner.com/mainscreen.jpg Hello everyone, I am trying to build a car rental bookings software but I am not sure how to implement the drag'n'drop functionality. ..you know, where you get the coloured-bars on the calendar/table and you can drag and drop them, or right-click and edit them, etc Any suggestions on how i could do this? Any help is appreciated. (you may
59
7189
by: Jeff Bowden | last post by:
For ease of configuration and other reasons, I would like for my single-user GUI app to be able to use postgresql in-process as a library accessing a database created in the users home directory. I think I could possibly get what I want by launching a captive copy of postmaster with appropriate args but it seems conceptually cleaner to not have a seperate process at all. Has anyone tried to do anything like this? I've looked at sqlite...
1
1456
by: Martin Marques | last post by:
I was reading the section about Planner Method Configuration, and I just don't get why all the options have this message: "This is used for debugging the query planner". Are they all debugging options, because they don't look like. http://www.postgresql.org/docs/current/interactive/ -> runtime-config.html#RUNTIME-CONFIG-QUERY -- 15:45:02 up 64 days, 22:01, 2 users, load average: 1.49, 1.32, 0.85...
2
1616
by: Ed L. | last post by:
The planner is choosing a sequential scan for my query. I am trying to understand why since it is clearly not the fastest choice, and what the proper tuning dial is to adjust here. Here's the query: select count(1) from measurement where measure_id = 98; TIA. Here are the details: % psql -c "\d measurement" Table "public.measurement"
3
2914
by: WB | last post by:
Hi, Is it poosible to build an appointment planner on a webform using asp:Calendar control? I would like to display one month at a time and show all the appointments scheduled in every day (something like the Calendar in Microsoft Outlook)... Can this be done? Or do I have to build that from scratch?
0
8739
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8652
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,...
0
9234
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, 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...
0
9089
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 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...
1
8983
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6575
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 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...
0
4667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3107
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
3
2036
bsmnconsultancy
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...

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.