|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||||
|
|||||
|
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:
Code:
Field #01: STOCK_WAREHOUSE.QTY_PURCHASED Alias:QTY_PURCHASED Type:INTEGER PLAN JOIN (SW NATURAL, BT INDEX (IDX_BILL_TRANSACTIONS1))
__________________
My blog about OpenSource Databases PDF tutorials about OSS databases, DBMonster ... Please contribute to Open Source Development, fill bug reports!!! Developer Shed eSupport Commented my.ini/my.cnf (PLEASE ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins Last edited by pabloj : March 24th, 2008 at 09:22 AM. |
|
#3
|
|||
|
|||
|
Pabloj,
Thanks for the review, i will try out your suggestions and revert back. |
|
#4
|
|||
|
|||
|
all working
thanks ....everything working perfect after the indexes were in place
|
![]() |
| Viewing: Dev Shed Forums > Databases > Firebird SQL Development > Left outer join takes a long time to excute |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|