Universe Tuning Training Presentation

Post on 16-Nov-2014

182 views 2 download

description

Universe Tuning Training Presentation

Transcript of Universe Tuning Training Presentation

Tuning Business Object Universes

2

The Developer’s Dilemma

• Direct control over SQL queries has vanished

• Business Objects allows you to code SQL fragments, not completeclauses

• Reduced control over how these fragments are finally combined

• Tuning SELECT statements is OUT!

• Tuning SQL fragments, understanding how Business Objectscombines these fragments is IN!

3

Possible Areas to Consider

Data Modeling

Universe Design

Query Design

We will concentrate on the last two areas ...

4

Topics Covered

• Tips on creating better objects, joins, and queries

• Real-world examples that illustrate these tips

• Emphasis on Oracle, Sybase, Informix

5

Tip 1: Process Less Data

For all databases:

• The WHERE clause states certain conditions that must be met beforeadditional processing occurs

• This additional processing usually occurs in the SELECT clause ascalculations or complicated expressions.

• More restrictive conditions reduces the amount of data subject toSELECT processing.

6

Example - Running Totals

• Each row contains one account’s totals for a particular month and year.

• Restrict this table by creating a Business Objects join asking for the time periodup front.

• This dramatically reduces the number of rows processed by the SELECT clause.

ACCT_BALANCESacct_idmonthyearbeginning_balanceending-balance

7

Example - Large Fact Tables

• Data warehouses usually depend on a few large FACT tables that containsummarized information based on a multi-part key.

• Restrict access to that fact table by providing values for one or more of theseprimary key fields.

SALES_TRACKINGdivisionsales_mgrsalesmanperiodtotal_sales

8

Tip 2: Scan Tables Once

DB: Oracle, Sybase, Informix

• Use conditional logic (IF-THEN) functions to retrieve specificinformation from each table row.

• Several of these functions can be placed in the SELECT clause

• Applied at the same time, they read the same row once.

9

Oracle Conditional Logic

Oracle provides the DECODE function:

Code: Translation:

DECODE (<expression>.<test 1>, <result 1>,<test 2>, <result 2>.…<default result>)

If the Expressionequals Test 1. then return Result 1If it equals Test 2. return Result 2

Else return the Default Result

10

Example - Oracle DECODE

Return only revenues from Texas and Oklahoma customers

sum (DECODE (customers state.‘TX’, order_lines qty_requested * order_lines price,‘OK’, order_lines qty_requested * order_lines price,0))

11

Sybase Conditional Logic

• Sybase does not provide a DECODE function.

• Instead, several functions must be used based on datatype.

T est R esu lt Form ula

C har N um sign( charindex(<expression> , <T EST> )) * R ESU L T

N um N um sign( <expression> - TE ST ) * R E SU L T

C har C har substring ( R E SU LT , 1 ,charindex( < expression> , T EST ) * leng th o f R ESU LT >)

N um C har substring ( R E SU LT , 1 .sign( <expression - T EST ) * < leng th o f R ESU L T> )

12

Example - Sybase Logic

• Return only revenues from Texas and Oklahoma Customers

sum( sign ( charindex(customers.state, ‘TX’) +charindex( customers.state, ‘OK’ ) )

*order_lines.qty_requested * order_lines price)

13

Informix Conditional Logic

• Informix does not provide a DECODE function, either• Informix has the smallest set of SQL functions to choose from• Conditional logic can be emulated through nested TRIMs

Code:

Translation:

TRIM( BOTH LEADING TRAILING <character>, <expression>)

IF the character is attached to front or rear of the expression,THEN return the expression with the character trimmed off.

14

Example - Informix Logic

Return only revenues from 1st quarter

order_amount*LENGTH( TRIM(BOTH ‘2’,

TRIM(BOTH ‘3’,TRIM( BOTH ‘4’, quarter_o_order))))

15

Tip 3: Avoid Outer Joins

DB: All

• Outer joins force all rows from one table to be read

• Adding outer joins in some DB can severely limit Ad-Hoc potential

• Try adding an additional row within the table that has no matching data

Order Sales SP7803 1050.25 9997804 542.00 5

ID Name5 Dan Hunter999 No Salesperson

16

Time-Dependant Joins

• Some relationships are time-dependant, and cannot be resolved thisway

Requisitions Orders

Receipts

17

Tip 4: Driving Tables

DB: Oracle 6, Oracle 7 with Rule-Based optimizationSybase (After the first four tables joined)

• The driving table is usually the last table in the FROM clause

• The DB processes the driving table first, retrieving data from other tables viajoins

• Pick the smallest, most restrictive table as your driving table

Cash Accounts

10 Rows

Journal Entries

3 Million Rows

18

Example - Driving Tables

• Move to the LIBRARY subdirectory of Business Objects

• Set HIDE_BOPTIMIZE=NO in ORA7.PRM (SYB10 for Sybase)

• Open a BO universe as a developer

• New menu option available - Optimize

• Can now assign “weights” to tables

• Lowest numbered table in query becomes the driving table

19

Tip 5: Rules for Indexed Columns

DB: All

• Indexes are meant to accelerate the retrieval of rows based on columnconditions

• Certain SQL coding standards will “disable” indexes

• The following rules indicate where indexes are disabled

• Use the alternative coding techniques listed to re-enable indexes

20

Rule 1 - No Calculations

Do not use calculations or functions on indexed columns

Disables Index Uses Index

Last_Name First_Nam eLIKE …

Last_Name LIKE … andFirst_Name LIKE …

Salary/12>2000 Salary>2000*12

TRUNC(Sales_Date) >TRUNC (sysdate)

Sales_D ate BETW EEN RUNC(sysdate)and TRUNC(sysdate) + .9999

21

Rule 2 - No Open Patterns

Avoid patterns that begin with ‘%’

Disables Index Disables Index (but runs faster !)

Last_Name LIKE ‘‘% ING’ Last_Name LIKE ‘_ING ’ ORLast_Name LIKE ‘_ING ’ ORLast_Name LIKE ‘ _ING ’

22

Rule 3 - No NULL Comparisons

Avoid IS NULL, IS NOT NULL Comparisons

Disables Index Uses Index (but runs faster !)

NOTE - NULL Product ID must replaced with nonsense value

Product _ID IS null Product_ID > 0 (See Note Below)

23

Rule 4 - No NOT Comparisons

Avoid beginning a comparison with NOT

Disables Index Use Index

Note: Assumes amount field should be positive

Amount !=0 Amount > 0 (See Note)

24

Tip 6: Use ROWID

DB: Oracle, Informix

• ROWID is the fastest way to retrieve any row

• It acts like the ultimate primary key, pointing to the physical location of a row

• ROWID can be used as a field, and thought of as the primary key for uniquelyindexed tables.

• Especially helpful for tables with combination primary keys

25

Example - Using ROWID

• Counting table rows the normal way:COUNT (Employees.Last_Name)

• Faster count - Count on an indexed field:COUNT (Employees. Employee_ID)

• Fastest count - Count the ROWID:COUNT (Employees ROWID)

26

Tip 7: Expand Table Indexes

DB: All

• Add commonly-retrieved columns to a table index

• Additional columns should be short in length

• If the index columns all requested information, the DB can skip reading the table

27

Example - Expanding Indexes

• The LOOKUPS table contains a Code, Type and Description

• If the Type is normally retrieved with the code, add the Type field to the Lookupsindex

LOOKUPScodetypedescription

28

Tip 8: Mark Indexed Columns

DB: All

• Users have no idea which columns are indexed.

• Help them by assigning a special character (like *) to the name of indexedcolumns

• For combination keys, only mark the leading (first) indexed column this way

• DO NOT mark any objects whose SQL fragments disable indexes.

29

Example - Making Indexed Columns

EMPLOYEESemployee_idlast_namefirst_namecity

EMPLOYEES_INDEX1employee_id

EMPLOYEES_INDEX2last_namefirst_name

S Q L F r a g m e n t P o s s ib le O b je c t N a m e

la s t _ n a m e * E m p lo y e e L a s t N a m e

f i r s t_ n a m e E m p lo y e e F i r s t N a m e

la s t _ n a m e ‘ ,’ f i r s t_ n a m e E m p lo y e e F u l l N a m e

30

Tip 9: Postpone Processing

DB: All

• Certain database processing tasks slow down query execution

• These same tasks could be removed from the query, and saved for BusinessObjects

• Powerful post-processing allows quicker data retrieval

31

Example - Sort Data Locally

• Sorts can be removed from any query, and applied locally using theReportWriter

• One Drawback - Should not remove a sort from a query when Partial Resultsoption set

32

Example - Postpone Calculations

• Calculations and concatenations within the SELECT clause slows down thequery

• The most recent version of Business Objects contains over 80 report functions

• Remove calculations from the query, saving them for Business Objects

End of presentation