|
Archives of the TeradataForumMessage Posted: Thu, 17 Jan 2008 @ 11:33:46 GMT
Hi all, I am working on a report where I have to join two fact tables with the same primary Index and two dimensional Tables. For my understanding the fact tables should be joined based on the PI but instead the Optimizer joins one of the fact Tables and with one of the dimension tables before joining with the other Fact tables. In this case the PI Join will get lost. Even if I bring the fact tables into a dirived table there is no change on the behaving. I mean the answerset will be returned within seconds but I also had it that these kind of reports can take forever. This behaving is usually recognized when 2 Fact Tables and multiple smaller dimensional or lookuptables will be joined. How can I force the optimizer to pick the Join between the two fact tables first before joining the dimensional tables? Cheers Joerg These are the details: I am working on TNT Demo 6.1. No sec. Index are set so far. SQL: SELECT "Orders" ."OrderDate" "OrderDate" , "CUSTOMERS"."CustomerName" "CustomerName" , "PRODUCT_DIMENSION"."ProductName" "ProductName" , "PRODUCT_DIMENSION"."ProductLine" "ProductLine" , sum("Orders"."OrderQty") "OrderQty" , sum("Orders"."UnitsReturned") "UnitsReturned" FROM ( (SELECT "ORDERHEADER"."OrderDate", "ORDERHEADER"."CustomerId", "ORDERDETAIL"."ProductNumber", "ORDERDETAIL"."OrderQty", "ORDERDETAIL"."UnitsReturned" FROM "ORDERHEADER" "ORDERHEADER" INNER JOIN "ORDERDETAIL" "ORDERDETAIL" ON "ORDERHEADER"."OrderCode" = "ORDERDETAIL"."OrderCode" ) "Orders" INNER JOIN "CUSTOMERS" ON "CUSTOMERS" ."CustomerId" = "Orders"."CustomerId" ) INNER JOIN "PRODUCT_DIMENSION" "PRODUCT_DIMENSION" ON "PRODUCT_DIMENSION" ."ProductNumber" = "Orders"."ProductNumber" GROUP BY "Orders"."OrderDate", "CUSTOMERS"."CustomerName", "PRODUCT_DIMENSION"."ProductName", "PRODUCT_DIMENSION"."ProductLine" Explain:
Table Definition and statistics: CREATE SET TABLE RETAIL.ORDERHEADER ,NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL, CHECKSUM = DEFAULT ( OrderNumber DECIMAL(18,0), OrderCode INTEGER, OrderDate DATE, ClosedDate DATE, EmployeeId INTEGER, CustomerId DECIMAL(18,0), BranchCode INTEGER, OrderMethodCode INTEGER, OrderYear INTEGER, OrderMonth INTEGER) UNIQUE PRIMARY INDEX ( OrderCode ); Statistics on: OrderCode --------------------------------------------------------------- CREATE SET TABLE RETAIL.ORDERDETAIL ,NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL, CHECKSUM = DEFAULT ( Surr_Key INTEGER, Customer_Id INTEGER, OrderCode INTEGER, OrderDetailCode DECIMAL(18,0), ProductNumber DECIMAL(18,0), OrderQty FLOAT, Discount FLOAT, ProductCost FLOAT, ProductPrice FLOAT, ProfitMargin FLOAT, UnitsReturned BYTEINT) PRIMARY INDEX ( OrderCode ); Statistics on: OrderCode ProductNumber OrderCode,ProductNumber --------------------------------------------------------------- CREATE SET TABLE RETAIL.CUSTOMERS ,NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL, CHECKSUM = DEFAULT ( CustomerId DECIMAL(18,0), CustomerName VARCHAR(255) CHARACTER SET UNICODE NOT CASESPECIFIC, CustomerAlias VARCHAR(320) CHARACTER SET UNICODE NOT CASESPECIFIC, StreetAddress VARCHAR(970) CHARACTER SET UNICODE NOT CASESPECIFIC, CityName VARCHAR(60) CHARACTER SET UNICODE NOT CASESPECIFIC, RegionName VARCHAR(60) CHARACTER SET UNICODE NOT CASESPECIFIC, CountryName VARCHAR(80) CHARACTER SET UNICODE NOT CASESPECIFIC, CustomerType VARCHAR(30) CHARACTER SET UNICODE NOT CASESPECIFIC, Industry VARCHAR(60) CHARACTER SET UNICODE NOT CASESPECIFIC, CustomerSinceDate DATE) UNIQUE PRIMARY INDEX ( CustomerId ); Statistics on: CustomerId CustomerName --------------------------------------------------------------- CREATE SET TABLE RETAIL.PRODUCT_DIMENSION ,NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL, CHECKSUM = DEFAULT ( ProductNumber DECIMAL(18,0), ProductName VARCHAR(50) CHARACTER SET UNICODE NOT CASESPECIFIC, Description VARCHAR(255) CHARACTER SET UNICODE NOT CASESPECIFIC, LanguageCode VARCHAR(50) CHARACTER SET UNICODE NOT CASESPECIFIC, UnitPrice FLOAT, ProductionCost FLOAT, MARGIN FLOAT, IntroductionDate DATE FORMAT 'YY/MM/DD', PICTURE VARCHAR(32) CHARACTER SET UNICODE NOT CASESPECIFIC, CurrentInventory INTEGER, ProductTypeCode INTEGER, ProductType VARCHAR(50) CHARACTER SET UNICODE NOT CASESPECIFIC, ProductLineCode INTEGER, ProductLine VARCHAR(40) CHARACTER SET UNICODE NOT CASESPECIFIC) UNIQUE PRIMARY INDEX ( ProductNumber ); Statistics on: ProductNumber ProductLine ProductName,ProductLine
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Copyright 2016 - All Rights Reserved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Last Modified: 15 Jun 2023 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||