Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 24th, 2008, 03:17 AM
molochgoa molochgoa is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: russia
Posts: 4 molochgoa User rank is Private First Class (20 - 50 Reputation Level)molochgoa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 h 16 m 33 sec
Reputation Power: 0
Left outer join takes a long time to excute

Hi
This is scaled down table structure for testing purpose:

The table bill_transactions contains a large no of records with duplication of batch_no.
table tbl_stock_warehouse contains all the batches.


if the tbl_bill_transactions contains few records like 1000 and tbl_stock_warehouse contains 62170, then the query excutes in 1 min 18 secs else,
if it contains 400,000 records and tbl_stock_warehouse contains 60,000 reords the query runs forever.

The aim of this query was to compute the difference in stock depleted from tbl_stock_warehouse.
Sql server does this operation super fast.
So i'm wondering is it my mistake or does this process take time with firebird or more hardware required to do the operation.


Details:

PLAN JOIN (TBL_STOCK_WAREHOUSE NATURAL, TBL_BILL_TRANSACTIONS NATURAL)


Excution time :00:01:18:0781
Prepare time :00:00:00:0000
Start memory: 9051008
Delta memory :8416
Numbe buffers: 2048
Reads: 1038
Writes: 26
Plan: PLAN JOIN (TBL_STOCK_WAREHOUSE NATURAL, TBL_BILL_TRANSACTIONS NATURAL)
Rows Affected: 62170


Query:
select qty_purchased from
tbl_stock_warehouse left outer join tbl_bill_transactions on tbl_bill_transactions.batch_no=tbl_stock_warehouse.batch_no

Test Table:
Commands CREATE TABLE tbl_stock_warehouse (
batch_no INTEGER NOT NULL,
qty_purchased integer
);

CREATE TABLE tbl_bill_transactions (
batch_no INTEGER NOT NULL,
item_qty integer,
rate integer
);

COMMIT;


CREATE UNIQUE ASC INDEX PK_batch_no ON tbl_stock_warehouse (batch_no);


COMMIT;


Please advise ...
Thanks in advance
Comments on this post
pabloj agrees: Good start, now add formatting ;-)

Reply With Quote
  #2  
Old March 24th, 2008, 04:49 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 8,257 pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Months 2 Days 11 h 54 m 38 sec
Reputation Power: 524
That's because you are pulling all rows from stock warehouse and related columns from bill transactions, this makes the only index you defined (PK_batch_no on stock warehouse) unuseful as that table will be fully scanned anyway and there is not an index to be used in comparison on bill transactions.
I added it and see how the plan turns out in my example
Remember to keep your database stats fresh, it will help keeping plans and speed consistent when number of rows in tables and size ratios in a join change.

I'd be curious to see this (exactly this) structure and query in SQLServer and it's explain plan ... I doubt it would be much different.

Note that you should first post your table creation statement, correctly formatted, then you should post your queries (again, formatted) their explain plan and a short description of what you're trying to do.

You should also prepend an alias to columns in your selects, avoild prepending a tbl_ to table names (database knows if those are tables and is willing to give you that information through it's metadata and firebird supports updateable views too) ...
Code:
CREATE TABLE BILL_TRANSACTIONS(
  BATCH_NO Integer NOT NULL,
  ITEM_QTY Integer,
  RATE Integer
);
CREATE INDEX IDX_BILL_TRANSACTIONS1 ON BILL_TRANSACTIONS (BATCH_NO);
GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE
 ON BILL_TRANSACTIONS TO SYSDBA WITH GRANT OPTION;

Code:
CREATE TABLE STOCK_WAREHOUSE(
  BATCH_NO Integer NOT NULL,
  QTY_PURCHASED Integer
);
CREATE UNIQUE INDEX PK_BATCH_NO ON STOCK_WAREHOUSE (BATCH_NO);
GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE
 ON STOCK_WAREHOUSE TO SYSDBA WITH GRANT OPTION;
sql Code:
Original - sql Code
  1. SELECT
  2.     sw.qty_purchased
  3. FROM
  4.     stock_warehouse sw LEFT OUTER JOIN bill_transactions bt
  5. ON
  6.     bt.batch_no=sw.batch_no
Code:
Field #01: STOCK_WAREHOUSE.QTY_PURCHASED Alias:QTY_PURCHASED Type:INTEGER
PLAN JOIN (SW NATURAL, BT INDEX (IDX_BILL_TRANSACTIONS1))

Last edited by pabloj : March 24th, 2008 at 09:22 AM.

Reply With Quote
  #3  
Old March 26th, 2008, 11:18 AM
molochgoa molochgoa is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: russia
Posts: 4 molochgoa User rank is Private First Class (20 - 50 Reputation Level)molochgoa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 h 16 m 33 sec
Reputation Power: 0
Pabloj,
Thanks for the review, i will try out your suggestions and revert back.

Reply With Quote
  #4  
Old March 31st, 2008, 12:18 PM
molochgoa molochgoa is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: russia
Posts: 4 molochgoa User rank is Private First Class (20 - 50 Reputation Level)molochgoa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 h 16 m 33 sec
Reputation Power: 0
all working

thanks ....everything working perfect after the indexes were in place

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Left outer join takes a long time to excute


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT