Download presentation
Presentation is loading. Please wait.
Published byForrest Pillen Modified over 10 years ago
1
www.sagecomputing.com.au penny.cookson@sagecomputing.com.au 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)
2
SAGE Computing Services Customised Oracle Training Workshops and Consulting Penny Cookson Managing Director and Principal Consultant Working with since 1987 Oracle Magazine Educator of the Year 2004
3
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
4
“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
5
The database is just a persistent data store, we don’t need to worry about it Development Stage
6
This new web application is really slow Production Stage
7
What have you done to MY database Production Stage
8
S So how do you protect your database from the Java people?
9
Its all about education
10
Database Centric – Model Layer Events Organisations Bookings Organisations VO Bookings VO Events VO SELECT Organisations EO Bookings EO Events EO INSERT UPDATE DELETE LOCK INSERT UPDATE DELETE LOCK INSERT UPDATE DELETE LOCK BookingService (Application Module ) COMMIT ROLLBACK
11
We are letting JDeveloper generate our SELECT statements Events Organisations Bookings Organisations VO Bookings VO Events VO SELECT Organisations EO Bookings EO Events EO INSERT UPDATE DELETE LOCK INSERT UPDATE DELETE LOCK INSERT UPDATE DELETE LOCK BookingService (Application Module ) COMMIT ROLLBACK
12
SELECT …….WHERE col = ‘bbbbb’ Full table scan Index scan aaaaa bbbbb ccccc ddddd eeeee aaaaa ggggg ccccc ddddd eeeee aaaaa kkkkk ccccc ddddd eeeee aaaaa bbbbb ccccc ddddd eeeee a z bbbb rowid aaaaa bbbbb ccccc ddddd eeeee aaaaa ggggg ccccc ddddd eeeee aaaaa kkkkk ccccc ddddd eeeee aaaaa bbbbb ccccc ddddd eeeee DB
13
Optimizer estimates cost of each possible access path and picks the cheapest DB
14
Determining the View Object query Jdev Bind variables View Criteria Custom sql (Expert mode)
15
An example - View Object with a Bind Variable Jdev
16
An example - View Object with a Bind Variable
17
That’s seems OK But what did it do in the database Jdev An example - View Object with a Bind Variable
18
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
19
View Objects – Finding the SQL DB
20
View Objects – Finding the SQL Plan Paste the sql_id in here DB
21
Why bother with all that database stuff when Jdev gives me an Explain Plan Jdev
23
Is that what it will really do?
24
Jdev
26
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
27
VO Tuning Options affect the statements executed Jdev
28
VO Tuning options This statement gets executed when the VO tuning options are set to: Rows in batches as needed DB
29
Jdev Managing Optional Parameters Required parameter works fine, but returns no rows if the parameter is null
30
Make the Bind variable Required = No Jdev
31
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
32
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
33
Using View Criteria View Criteria – Optional View Criteria – Ignore Null Values = Y Jdev
34
Using View criteria Execute with no parameter value All the rows returned Jdev
35
Bind Parameter – Required = Y View Criteria – Optional View Criteria – Ignore Null Values = Y No parameter value This is the statement that returns the rows DB
36
Bind Parameter – Required = Y View Criteria – Optional View Criteria – Ignore Null Values = Y No parameter value Read the entire table DB
37
I am sure it will be fine if I give it a parameter value Bind Parameter – Required = Y View Criteria – Optional View Criteria – Ignore Null Values = Y Parameter value was 1200 DB
38
Bind Parameter – Required = Y View Criteria – Optional View Criteria – Ignore Null Values = Y With parameter value DB
39
Bind Parameter – Required = N View Criteria – Optional View Criteria – Ignore Null Values = Y Required = N Jdev
40
Bind Parameter – Required = N View Criteria – Optional View Criteria – Ignore Null Values = Y View Criteria – Optional View Criteria – Ignore Null Values = Y Jdev
41
Bind Parameter – Required = N View Criteria – Optional View Criteria – Ignore Null Values = Y No parameter value supplied All the rows returned Jdev
42
Bind Parameter – Required = N View Criteria – Optional View Criteria – Ignore Null Values = Y DB Predicate for pBookingNo not included if bind variable is null
43
Bind Parameter – Required = N View Criteria – Optional View Criteria – Ignore Null Values = Y DB Bind variable has a value of 1206
44
Bind Parameters – Required = N Multiple View Criteria – Optional Multiple View Criteria – Ignore Null Values = Y Jdev
45
Bind Parameters – Required = N Multiple View Criteria – Optional Multiple View Criteria – Ignore Null Values = Y Jdev
46
Bind Parameters – Required = N Multiple View Criteria – Optional Multiple View Criteria – Ignore Null Values = Y Jdev
47
Bind Parameters – Required = N Multiple View Criteria – Optional Multiple View Criteria – Ignore Null Values = Y Includes the where clause if we have supplied a parameter value DB
48
Bind Parameters – Required = N Multiple View Criteria – Optional Multiple View Criteria – Ignore Null Values = Y Which allows it to choose the best index DB
49
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 – Optional View Criteria – Ignore Null Values = Y
50
Using Functions in the SELECT Jdev
51
Using Functions in the SELECT Didn’t someone say it was bad to do this? Jdev
52
View Object Tuning Options But it doesn’t matter - I am only getting 20 rows Jdev
53
Using Functions in the SELECT DB
54
Sort the Rows (either User Sort or in the VO) Jdev
55
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
56
View Object – Multiple Entities + Transient Attribute Jdev
57
View Object – Multiple Entity Objects Jdev
58
View Object – Multiple Entity Objects - Sort Jdev
59
View Object – Multiple Entity Objects than this This is much better DB
60
View Object – Multiple Entity Objects But why does it have to keep selecting from EVENTS DB
61
View Object – Multiple Entity Objects Jdev
62
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
63
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
64
View Object – Fetching multiple values from the same tables SELECT taxFileNo, getTaxCalcs(taxFileNo), FROM TaxDetailsTable value1 value1|value2|value3|value4 value2value3value4 Define transient attributes in the VO Jdev
65
View Object – Tuning Options It defines how many rows are returned to the middle tier NOT how many are read from the database Jdev
66
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 – Optional View 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
67
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’ WHEREsal * 1.1 = 2000 WHEREto_char(start_date,’dd/mm/yy’) = ‘01/03/93’
68
View Object – Case Sensitive View Criteria Jdev
69
View Object – Case Sensitive View Criteria Create a function based index DB
70
Validation – IN View Accessor Jdev
71
Validation – IN View Accessor Jdev
72
Validation – IN View Accessor Jdev Validating this reads 100,438 blocks in a full scan of EVENTS_LARGE (and takes a very long time)
73
Validation – KEY EXISTS in View Accessor Jdev
74
Validation – KEY EXISTS in View Accessor Jdev Validating this reads 99 blocks in a Unique Index scan of EVENTS_LARGE (and is really quick)
75
Displaying Additional Data – View Accessor Jdev
76
Displaying Additional Data – View Accessor
77
Jdev Displaying Additional Data – View Accessor
78
Jdev Displaying Additional Data – View Accessor
79
Jdev Displaying this needs a full scan of ORGANISATIONS Displaying Additional Data – View Accessor
80
Displaying Additional Data - Multiple Entity Usages Jdev
81
Displaying Additional Data - Multiple Entity Usages Jdev
82
Displaying Additional Data - Multiple Entity Usages Jdev Displaying this fetches Organisations.name from a join in the VO query
83
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 – Optional View 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
84
Skewed Data Majority value Minority value DB
85
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
86
Skewed Data in ADF Query for the minority case Jdev
87
Skewed Data in ADF DB
88
Skewed Data in ADF Query for the majority case Jdev
89
View Object – Skewed Data in ADF Even after 4 executions its still using the same plan DB
90
View Object – Execute in a different session Open the same page in a different window DB
91
View Object – BIND_AWARE Add this hint to all Vos on skewed data (with histograms) Jdev
92
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 – Optional View 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
93
So what about all the cute new query components
94
Jdev
96
xxxxxxxxxx
100
This is fine because the user picked an indexed attribute to query
101
xxxxxxxxxx
103
This has to full scan because the attribute the user queried was not indexed
104
xxxxxxxxxx
105
Running PL/SQL from Java LIKE ‘%something%’ can’t use an index even if there is one
106
xxxxxxxxxx
108
Write our own searches with a known set of parameters Don’t allow users to sort large sets of records
109
Connections - Logging Jdev
110
Connections - Logging Jdev
111
Connections - Logging Jdev
112
Connections - Logging Jdev
113
Connections Jdev
114
Using BTFs in Regions Jdev AppModule Connection defined as: java:comp/env/jdbc/conf2011DS
115
Using BTFs in Regions Jdev
116
Using BTFs in Regions Jdev
117
Database sessions in use DB
119
Using BTFs in Regions Jdev
120
Database sessions in use DB
121
Using BTFs in Regions AppModule Connection defined as: java:comp/env/jdbc/EventsServiceConnDS Jdev
122
Using BTFs in Regions Jdev
123
Database sessions in use DB
124
Using BTFs in Regions Jdev
125
Using BTFs in Regions Jdev
126
Database sessions in use DB
127
Use the same connection
128
Passivation Settings Jdev
129
Passivation Settings
130
Recommended for Development / Testing
131
Passivation Settings alter system flush shared_pool Execute With Params twice more 8 executions
132
Recommended for Development / Testing You need to run like this for development / testing But turn it back on for UAT
133
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 – Optional View 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
135
www.sagecomputing.com.au penny.cookson@sagecomputing.com.au JDeveloper ADF and the Oracle database – friends not foes SAGE Computing Services Customised Oracle Training Workshops and Consulting Penny Cookson Questions
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.