www.sagecomputing.com.au [email protected] jdeveloper adf and the oracle database...

135
www.sagecomputing.com.au [email protected] JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised Oracle Training Workshops and Consulting Penny Cookson (Building applications using JDeveloper ADF without killing database performance)

Upload: forrest-pillen

Post on 01-Apr-2015

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

[email protected].

au

JDeveloper ADF and the Oracle database – friends

not foes

SAGE Computing ServicesCustomised Oracle Training Workshops and

Consulting

Penny Cookson

(Building applications using JDeveloper ADF without killing database performance)

Page 2: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

SAGE Computing ServicesCustomised Oracle Training Workshops and

Consulting

Penny Cookson

Managing Director and Principal Consultant

Working with since 1987

Oracle Magazine Educator of the Year 2004

Page 3: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Agenda

View Objects and the WHERE clause

How to find out what’s happening in the database

View criteria

View Objects Tuning Options

Using functions

View Accessors

Skewed data

Adding Hints

Managing database connections

Application Module Pooling

Page 4: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

“ADF Business Components stands out for the task of business service development and object relational mapping by virtue of its highly declarative metadata based development style.”

Planning Stage

Page 5: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

The database is just a persistent data store, we don’t need to worry about it

Development Stage

Page 6: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

This new web application is really slow

Production Stage

Page 7: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

What have you done to MY database

Production Stage

Page 8: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

S So how do you protect your database from the Java

people?

Page 9: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Its all about education

Page 10: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Database Centric – Model Layer

EventsOrganisations Bookings

OrganisationsVO

Bookings VO

Events VO

SELECTSELECT SELECT

OrganisationsEO

Bookings EO

Events EO

INSERTUPDATEDELETELOCK

INSERTUPDATEDELETELOCK

INSERTUPDATEDELETELOCK

BookingService (Application Module )COMMITROLLBACK

Page 11: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

We are letting JDeveloper generate our SELECT

statements

EventsOrganisations Bookings

OrganisationsVO

Bookings VO

Events VO

SELECTSELECT SELECT

OrganisationsEO

Bookings EO

Events EO

INSERTUPDATEDELETELOCK

INSERTUPDATEDELETELOCK

INSERTUPDATEDELETELOCK

BookingService (Application Module )COMMITROLLBACK

Page 12: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

SELECT …….WHERE col = ‘bbbbb’

Full table scan Index scan

aaaaabbbbbcccccdddddeeeee

aaaaagggggcccccdddddeeeee

aaaaakkkkkcccccdddddeeeee

aaaaabbbbbcccccdddddeeeee

a

z

bbbb rowidbbbb rowid

aaaaabbbbbcccccdddddeeeee

aaaaagggggcccccdddddeeeee

aaaaakkkkkcccccdddddeeeee

aaaaabbbbbcccccdddddeeeee

DB

Page 13: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Optimizer estimates cost of each possible access path and picks the cheapest

DB

Page 14: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Determining the View Object queryJdev

Bind variables

View Criteria

Custom sql (Expert mode)

Page 15: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

An example - View Object with a Bind Variable

Jdev

Page 16: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

JdevAn example - View Object with a Bind Variable

Page 17: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

That’s seems OKBut what did it do in the database

JdevAn example - View Object with a Bind Variable

Page 18: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Objects – Finding the SQL

There’s a row in here for each

optimisation of a sql statement

(until it gets aged out)

It has been executed once

With 135 blocks read per

execution

DB

Page 19: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Objects – Finding the SQL DB

Page 20: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Objects – Finding the SQL Plan

Paste the sql_id in here

DB

Page 21: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Why bother with all that database stuff when Jdev gives me an Explain Plan

Jdev

Page 22: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Jdev

Page 23: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Jdev

Is that what it will really do?

Page 24: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Jdev

Page 25: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Jdev

Page 26: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Doesn’t peek at bind variables

Optimiser statistics need to be the same as production

System statistics need to be the same as production

Environment needs to be same as production

Jdev

Explain Plan

Find out what its really doing

Page 27: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

VO Tuning Options affect the statements executed

Jdev

Page 28: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

VO Tuning options

This statement gets executed when the VO tuning options are set to: Rows in batches as needed

DB

Page 29: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Jdev

Managing Optional Parameters

Required parameter works fine, but

returns no rows if the parameter is null

Page 30: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Make the Bind variable Required = NoJdev

Page 31: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Variable Oracle Documentation

Required

Select if you want to make the value of a name bind variable required for any usage the references the named bind variable. For example, when the value is required (default), all view criteria items that reference the named bind variable will fail to execute unless a valid value is supplied at runtime. Alternatively, you can leave the value not required and use the Create View Criteria dialog to specify whether or not individual view criteria items require the value

Page 32: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Recommendations So Far

Forget about Explain plan – find out what its really done

Required Bind variable is fine if you always provide a value for an indexed column

Page 33: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Using View Criteria

View Criteria – OptionalView Criteria – Ignore Null Values =

Y

Jdev

Page 34: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Using View criteria

Execute with no parameter value

All the rows returned

Jdev

Page 35: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Parameter – Required = YView Criteria – OptionalView Criteria – Ignore Null

Values = YNo parameter value

This is the statement that returns the rows

DB

Page 36: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Parameter – Required = YView Criteria – OptionalView Criteria – Ignore Null

Values = YNo parameter value

Read the entire table

DB

Page 37: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

I am sure it will be fine if I give it a parameter value

Bind Parameter – Required = YView Criteria – OptionalView Criteria – Ignore Null

Values = Y

Parameter value was 1200

DB

Page 38: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Parameter – Required = YView Criteria – OptionalView Criteria – Ignore Null

Values = YWith parameter value

DB

Page 39: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Parameter – Required = N View Criteria – OptionalView Criteria – Ignore Null Values = Y

Required = N

Jdev

Page 40: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Parameter – Required = N View Criteria – OptionalView Criteria – Ignore Null Values = Y

View Criteria – OptionalView Criteria – Ignore Null Values =

Y

Jdev

Page 41: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Parameter – Required = N View Criteria – OptionalView Criteria – Ignore Null Values = Y

No parameter value suppliedAll the rows returned

Jdev

Page 42: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Parameter – Required = N View Criteria – OptionalView Criteria – Ignore Null Values = Y

DB

Predicate for pBookingNo not included if bind variable is null

Page 43: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Parameter – Required = N View Criteria – OptionalView Criteria – Ignore Null Values = Y

DB

Bind variable has a

value of 1206

Page 44: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Parameters – Required = N Multiple View Criteria – OptionalMultiple View Criteria – Ignore Null

Values = Y

Jdev

Page 45: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Parameters – Required = N Multiple View Criteria – OptionalMultiple View Criteria – Ignore Null

Values = Y

Jdev

Page 46: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Parameters – Required = N Multiple View Criteria – OptionalMultiple View Criteria – Ignore Null

Values = Y

Jdev

Page 47: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Parameters – Required = N Multiple View Criteria – OptionalMultiple View Criteria – Ignore Null

Values = Y

Includes the where clause if we have supplied a parameter value

DB

Page 48: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Bind Parameters – Required = N Multiple View Criteria – OptionalMultiple View Criteria – Ignore Null

Values = Y

Which allows it to choose the best index

DB

Page 49: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Recommendations So Far

Forget about Explain plan – find out what it really did

Required Bind variable is fine if you always provide a value for an indexed column

For flexibility and performance use multiple View Criteria with

Parameter Required = N View Criteria – OptionalView Criteria – Ignore Null Values = Y

Page 50: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Using Functions in the SELECTJdev

Page 51: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Using Functions in the SELECT

Didn’t someone say it was bad to do this?

Jdev

Page 52: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object Tuning Options

But it doesn’t matter - I am only getting 20 rows

Jdev

Page 53: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Using Functions in the SELECT DB

Page 54: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Sort the Rows (either User Sort or in the VO)

Jdev

Page 55: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Sort the Rows (either User Sort or in the VO)

You might be getting only getting 20 rows back to the middle tier – but the database has to read all of them

DB

Page 56: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Multiple Entities + Transient Attribute

Jdev

Page 57: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Multiple Entity Objects

Jdev

Page 58: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Multiple Entity Objects - Sort

Jdev

Page 59: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Multiple Entity Objects

than thisThis is much better

DB

Page 60: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Multiple Entity Objects

But why does it have to keep selecting from EVENTS

DB

Page 61: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Multiple Entity Objects

Jdev

Page 62: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Multiple Entity Objects

Now its all selected from the join

DB

So – if you include a derived attribute from another EO also include the source attributes

Page 63: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Fetching multiple values from the same tables

SELECT taxFileNo, getTaxCalc1(taxFileNo), getTaxCalc2(taxFileNo); getTaxCalc3(taxFileNo),

getTaxCalc4(taxFileNo)FROM TaxDetailsTable

All these functions get the

same rows from the tables,

they just return different columns

Jdev

Page 64: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Fetching multiple values from the same tables

SELECT taxFileNo, getTaxCalcs(taxFileNo),

FROM TaxDetailsTable

value1

value1|value2|value3|value4

value2

value3

value4

Define transient attributes in the VO

Jdev

Page 65: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Tuning Options

It defines how many rows are returned to the middle tier

NOT how many are read from the database

Jdev

Page 66: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Recommendations So Far

Forget about Explain plan – find out what it really did

Required Bind variable is fine if you always provide a value for an indexed column

For flexibility and performance use multiple View Criteria with

Parameter Required = N View Criteria – OptionalView Criteria – Ignore Null Values = Y

For derived values, don’t use functions unless you have to

Select all the sources of a derived attribute

If you have to use functions fetch everything you need in one operation

Page 67: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Modified columns in the WHERE clause

Modified columns don’t use an index on the column

DB

 Columns that are modified by expressions or functions are unable to use an index unless a function based index has been created Examples: WHERE upper(name) = ‘VALUE’ WHERE sal * 1.1 = 2000 WHERE to_char(start_date,’dd/mm/yy’) = ‘01/03/93’

Page 68: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Case Sensitive View Criteria

Jdev

Page 69: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Case Sensitive View Criteria

Create a function based index

  

 

DB

Page 70: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Validation – IN View AccessorJdev

Page 71: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Validation – IN View AccessorJdev

Page 72: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Validation – IN View AccessorJdev

Validating this reads 100,438 blocks in a full scan of EVENTS_LARGE(and takes a very long time)

Page 73: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Validation – KEY EXISTS in View Accessor

Jdev

Page 74: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Validation – KEY EXISTS in View Accessor

Jdev

Validating this reads 99 blocks in a Unique Index scan of EVENTS_LARGE(and is really quick)

Page 75: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Displaying Additional Data – View Accessor

Jdev

Page 76: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Jdev

Displaying Additional Data – View Accessor

Page 77: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Jdev

Displaying Additional Data – View Accessor

Page 78: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Jdev

Displaying Additional Data – View Accessor

Page 79: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Jdev

Displaying this needs a full scanof ORGANISATIONS

Displaying Additional Data – View Accessor

Page 80: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Displaying Additional Data -Multiple Entity Usages

Jdev

Page 81: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Displaying Additional Data -Multiple Entity Usages

Jdev

Page 82: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Displaying Additional Data -Multiple Entity Usages

Jdev

Displaying this fetches Organisations.name from

a join in the VO query

Page 83: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Recommendations So Far

Forget about Explain plan – find out what it really did

Required Bind variable is fine if you always provide a value for an indexed column

For flexibility and performance use multiple View Criteria with

Parameter Required = N View Criteria – OptionalView Criteria – Ignore Null Values = Y

For derived values, don’t use functions unless you have to

Select all the sources of a derived attribute

If you have to use functions fetch everything you need in one operation

Don’t use Ignore Case unless you have a function based index

Be wary of using View Accessors for large data sets

Page 84: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Skewed Data

Majority value

Minority value

  

 

DB

Page 85: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Skewed Data in SQL

If I execute the statement with a minority value then a

majority (twice) it reassesses the plan and makes

a different decision

  

 

DB

Page 86: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Skewed Data in ADF

Query for the minority case

Jdev

Page 87: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Skewed Data in ADF  

 

DB

Page 88: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Skewed Data in ADF

Query for the majority case

Jdev

Page 89: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Skewed Data in ADF

Even after 4 executions its

still using the same plan

  

 

DB

Page 90: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – Execute in a different session

Open the same page in a different window

  

 

DB

Page 91: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

View Object – BIND_AWARE

Add this hint to all Vos on skewed data (with

histograms)

Jdev

Page 92: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Recommendations So Far

Forget about Explain plan

Required Bind variable is fine if you always provide a value for an indexed column

For flexibility and performance use multiple View Criteria with

Parameter Required = N View Criteria – OptionalView Criteria – Ignore Null Values = Y

For derived values, don’t use functions unless you have to

Select all the sources of the derived attribute

If you have to use functions fetch everything you need in one operation

Be wary of using View Accessors for large data sets

Don’t use Ignore Case unless you have a function based index

Use BIND_AWARE hint for skewed data

Page 93: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

So what about all the cute new query components

Page 94: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Jdev

Page 95: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Jdev

Page 96: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

xxxxxxxxxx

Page 97: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

xxxxxxxxxx

Page 98: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

xxxxxxxxxx

Page 99: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

xxxxxxxxxx

Page 100: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

xxxxxxxxxx

This is fine because the user picked an indexed attribute to query

Page 101: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

xxxxxxxxxx

Page 102: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

xxxxxxxxxx

Page 103: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

xxxxxxxxxx

This has to full scan because the attribute the user queried was not indexed

Page 104: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

xxxxxxxxxx

Page 105: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Running PL/SQL from Java

LIKE ‘%something%’ can’t use an index even if there is one

Page 106: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

xxxxxxxxxx

Page 107: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

xxxxxxxxxx

Page 108: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Write our own searches with a known set of parameters

Don’t allow users to sort large sets of records

Page 109: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Connections - LoggingJdev

Page 110: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Connections - LoggingJdev

Page 111: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Connections - LoggingJdev

Page 112: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Connections - LoggingJdev

Page 113: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

ConnectionsJdev

Page 114: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Using BTFs in RegionsJdev

AppModule Connection defined as:

java:comp/env/jdbc/conf2011DS

Page 115: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Using BTFs in RegionsJdev

Page 116: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Using BTFs in RegionsJdev

Page 117: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Database sessions in use  

 

DB

Page 118: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

  

 

DB

Page 119: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Using BTFs in RegionsJdev

Page 120: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Database sessions in use  

 

DB

Page 121: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Using BTFs in Regions

AppModule Connection defined as:java:comp/env/jdbc/

EventsServiceConnDS

Jdev

Page 122: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Using BTFs in RegionsJdev

Page 123: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Database sessions in use  

 

DB

Page 124: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Using BTFs in RegionsJdev

Page 125: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Using BTFs in RegionsJdev

Page 126: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Database sessions in use  

 

DB

Page 127: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Use thesame connection

Page 128: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Passivation SettingsJdev

Page 129: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Passivation Settings

Page 130: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Recommended for Development / Testing

Page 131: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Passivation Settings

alter system flush shared_pool

Execute With Params twice more 8 executions

Page 132: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Recommended for Development / Testing

You need to run like this for development / testing

But turn it back on for UAT

Page 133: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

Recommendations

Forget about Explain plan Required Bind variable is fine if you always provide a value for an indexed

column For flexibility and performance use multiple View Criteria with

Parameter Required = N View Criteria – OptionalView Criteria – Ignore Null Values = Y

For derived values, don’t use functions unless you have to Select all the sources of the derived attribute If you have to use functions fetch everything you need in one operation Don’t use Ignore Case unless you have a function based index Be wary of using View Accessors for large data sets Use BIND_AWARE hint for skewed data Use the same connection Bundle PL/SQL calls Use Application Module pooling in UAT

Page 134: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised
Page 135: Www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised

[email protected].

au

JDeveloper ADF and the Oracle database – friends

not foes

SAGE Computing ServicesCustomised Oracle Training Workshops and

Consulting

Penny Cookson

Questions