SlideShare a Scribd company logo
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Oracle Database Features
Every Developer Should Know About
Gerald Venzl
Senior Principal Product Manager
Oracle Development
August, 2018
@GeraldVenzl
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
2
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Join the Conversation
3
Related Videos
• Gerald’s YouTube Channel
• Oracle Database PM Channel
Any Additional Questions
• My emails: gerald.venzl[at]oracle.com
Additional
Resources
https://geraldonit.com
https://twitter.com/GeraldVenzl
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Program Agenda
Invisible Columns
Virtual Columns
External Tables
Useful Supplied PL/SQL Packages
How to Find Your Needle in the Haystack
1
2
3
4
4
5
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Invisible Columns
5
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Invisible columns
Difficulties with the relational model today:
• Different applications may need different columns from a single table
but all applications are impacted by any DDL change on a table
– Dropping a column will break queries still referring to it
– Adding a column breaks “SELECT *” queries
– Dropping a column will delete the data from all the rows, even those that are
already archived
6
Flexible schemas in a relational model
12c
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Invisible columns
Difficulties with the relational model today:
• Different applications may need different columns from a single table
but all applications are impacted by any DDL change on a table
– Dropping a column will break queries still referring to it
– Adding a column breaks “SELECT *” queries
– Dropping a column will delete the data from all the rows, even those that are
already archived
• Invisible columns allows you to introduce non-disruptive DDL changes
7
Flexible schemas in a relational model
12c
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Invisible columns
8
Dropping columns is disruptive
SQL> SELECT first_name, last_name, initials
FROM customers;
FIRST_NAME LAST_NAME IN
---------- ---------- --
George Kolaski GK
Joseph Smith JS
Gerald Teller GT
SQL> SELECT first_name, last_name, initials
FROM customers;
FIRST_NAME LAST_NAME IN
---------- ---------- --
George Kolaski GK
Joseph Smith JS
Gerald Teller GT
App A
App B
FIRST_NAME LAST_NAMEINITIALS
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Invisible columns
9
Dropping columns is disruptive
SQL> SELECT first_name, last_name, initials
FROM customers;
SELECT first_name, last_name, initials
*
ERROR at line 1:
ORA-00904: "INITIALS": invalid identifier
App A
App B
LAST_NAMEFIRST_NAME
ALTER TABLE customers
DROP COLUMN initials;
SQL> SELECT first_name, last_name
FROM customers;
FIRST_NAME LAST_NAME
--------- ----------
George Kolaski
Joseph Smith
Gerald Teller
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Invisible columns
10
Dropping columns is disruptive
SQL> SELECT first_name, last_name
FROM customers;
FIRST_NAME LAST_NAME
--------- ----------
Geroge Kolaski
Joseph Smith
Gerald Teller
App A
App B
FIRST_NAME LAST_NAMEINITIALS
ALTER TABLE customers
MODIFY initials INVISIBLE;
SQL> SELECT first_name, last_name
FROM customers;
FIRST_NAME LAST_NAME
---------- ----------
George Kolaski
Joseph Smith
Gerald Teller
SQL> SELECT first_name, last_name, initials
FROM customers;
FIRST_NAME LAST_NAME IN
---------- ---------- --
George Kolaski GK
Joseph Smith JS
Gerald Teller GT
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Invisible columns
11
Adding columns is disruptive
App A
App C
LAST_NAMEFIRST_NAME
SQL> SELECT first_name, last_name
FROM customers;
FIRST_NAME LAST_NAME
---------- ----------
George Kolaski
Joseph Smith
Gerald Teller
SQL> SELECT *
FROM customers;
FIRST_NAME LAST_NAME
---------- ----------
George Kolaski
Joseph Smith
Gerald Teller
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
SQL> SELECT *
FROM customers;
FIRST_NAME LAST_NAME DOB
---------- ---------- ---------
George Kolaski 12-SEP-88
Joseph Smith 24-MAR-93
Gerald Teller 02-NOV-69
Invisible columns
12
Adding columns is disruptive
SQL> SELECT first_name, last_name, dob
FROM customers;
FIRST_NAME LAST_NAME DOB
---------- ---------- ---------
George Kolaski 12-SEP-88
Joseph Smith 24-MAR-93
Gerald Teller 02-NOV-69
App A
App C
LAST_NAMEFIRST_NAME DOB
ALTER TABLE customers
ADD dob date;
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
SQL> SELECT *
FROM customers;
FIRST_NAME LAST_NAME
---------- ----------
George Kolaski
Joseph Smith
Gerald Teller
Invisible columns
13
Adding columns is disruptive
App A
App C
LAST_NAMEFIRST_NAME DOB
ALTER TABLE customers
ADD dob date INVISIBLE;
SQL> SELECT first_name, last_name, dob
FROM customers;
FIRST_NAME LAST_NAME DOB
---------- ---------- ---------
George Kolaski 12-SEP-88
Joseph Smith 24-MAR-93
Gerald Teller 02-NOV-69
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Invisible columns
• Invisible columns can be used as partition keys
• Be aware that column order changes when setting columns invisible
• Use SET COLINVISIBLE ON; to see invisible columns in DESC
14
Flexible schemas in a relational model
SQL> SET COLINVISIBLE ON;
SQL> DESC CUSTOMERS;
Name Null? Type
----------------- -------- ------------
FIRST_NAME VARCHAR2(10)
LAST_NAME VARCHAR2(10)
DOB (INVISIBLE) DATE
LAST_NAMEFIRST_NAME DOB
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Virtual Columns
15
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Virtual columns
• Example: Compute total sales price
• Net = Price + (Price * Tax)
• As expressions get more complex it’s
possible developers will accidentally
define them differently in their code
• This results in inconsistent reporting
• You could change the data model
every time the business determines
a new measure & create a trigger to
populate the data
16
Analytic queries often contain complex expressions
PRODUCT TAXPRICE
Price+Price*Tax
11g
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Virtual columns
17
Add column with insert trigger
PRODUCT TAXPRICE
Price+Price*Tax
NET
SQL> ALTER TABLE sales ADD net number
INVISIBLE;
Table Altered.
SQL> UPDATE sales set net =
price+(price*tax);
15 rows updated.
SQL> CREATE OR REPLACE TRIGGER set_net
BEFORE INSERT or UPDATE ON sales
FOR EACH ROW
BEGIN
:new.net := :new.price +
(:new.price * :new.tax);
END;
/
Trigger created.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Virtual columns
18
Add column with insert trigger
PRODUCT TAXPRICE
Price+Price*Tax
NET
SQL> INSERT INTO sales (product, price, tax)
VALUES('Toy Train','5',’0.08');
1 row created.
SQL> COMMIT;
Commit complete.
SQL> SELECT product, price, tax, net
FROM sales;
PRODUCT PRICE TAX NET
---------- ---------- ---------- ----------
Toy Train 5 0.08 5.4
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Virtual columns
19
Appear to be normal table columns
PRODUCT TAXPRICE NET
SQL> ALTER TABLE sales ADD net number
INVISIBLE GENERATED ALWAYS AS
(price+(price*tax))VIRTUAL;
Table Altered
SQL> INSERT INTO sales (product, price, tax)
VALUES('Toy Train','5',’0.08');
1 row created.
SQL> COMMIT;
Commit complete.
SQL> SELECT prod, price, tax, net
FROM sales;
PRODUCT PRICE TAX NET
---------- ---------- ---------- ----------
Toy Train 5 0.08 5.4
Price+Price*Tax
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Virtual columns
20
Can be used in where clause
PRODUCT TAXPRICE NET
SQL> SELECT product, price, tax, net
FROM sales
WHERE net > 5;
PRODUCT PRICE TAX NET
---------- ---------- ---------- ----------
Toy Train 5 0.08 5.4
SQL> SELECT * FROM
TABLE(DBMS_XPLAN.DISPLAY_CURSOR());
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------
Plan hash value: 781590677
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
-----------------------------------------------------------------------------
| 0 |SELECT STATEMENT | | 1788 | 228K| 20 |
| 1|TABLE ACCESS FULL | SALES | 1788 | 228K| 20 |
------------------------------------------------------------------------------
Price+Price*Tax
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Virtual columns
21
Can be indexed
PRODUCT TAXPRICE NET
SQL> SELECT prod, price, tax, net
FROM sales
WHERE net > 5;
PROD PRICE TAX NET
---------- ---------- ---------- ----------
Toy Train 5 0.08 5.4
SQL> SELECT * FROM
TABLE(DBMS_XPLAN.DISPLAY_CURSOR());
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------
Plan hash value: 781590677
------------------------------------------------------------------------------
| Id | Operation | Name | Rows |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1788 |
| 1 | TABLE ACCESS BY INDEX ROWID | SALES | 1788 |
| 2| INDEX RANGE SCAN | IDX_NET | 1788 |
------------------------------------------------------------------------------
CREATE INDEX idx_net
ON sales(net);
Price+Price*Tax
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
External Tables
22
SALESTABLE(external)
UKPartition GermanyPartition USAPartition
SQL
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
External tables
• Query flat files as if they were tables in the database
– Provides the full power of SQL over flat files
• Preprocessor capabilities
– Un-compress, pre-format, etc. data before being read by the database
• Enables easy data loading
– Use INSERT INTO … SELECT (incl. DML error logging)
• Query data pump files
– Run queries on last nights backup to confirm it validity
• Query data store on HDFS/Hive
23
The universal out-of-database query interface
9i
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
External tables
24
Query files as if they were tables
CREATE TABLE customers_ext(
first_name varchar2 (10),
int varchar2 (2),
last_name varchar2 (10),
dob date
)
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY HOME_DIR
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
SKIP 1
FIELDS TERMINATED BY ',' (
first_name char(10),
last_name char(10),
int char(2),
DOB char (10)
DATE_FORMAT DATE 'YYYY-MM-DD')
)
LOCATION ('customers*.csv'))
REJECT LIMIT UNLIMITED;
CREATE DIRECTORY home_dir AS
‘/home/gerald/’;
/home/gerald/customers_1.csv
FName,LName,Initials,DOB
George,Kolaski,GK,1988-09-12
Joseph,Smith,JS,1993-03-24
Gerald,Teller,GT,19691102
:
:
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
External tables
25
Query files as if they were tables
SQL> SELECT first_name, last_name, dob
FROM customers_ext;
FIRST_NAME LAST_NAME DOB
---------- ---------- ---------
Geroge Kolaski 12-SEP-88
Joseph Smith 24-MAR-93
Gerald Teller 02-NOV-69
SQL> SELECT first_name, last_name
FROM customers_ext
WHERE dob > TO_DATE('1990','YYYY');
FIRST_NAME LAST_NAME
---------- ---------
Joseph Smith
FName,LName,Initials,DOB
George,Kolaski,GK,1988-09-12
Joseph,Smith,JS,1993-03-24
Gerald,Teller,GT,19691102
:
:
/home/gerald/customers_1.csv
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
External tables
26
Un-compress files on the fly
CREATE TABLE customers_ext_comp(
...
)
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY HOME_DIR
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
PREPROCESSOR USR_BIN:zcat
SKIP 1
FIELDS TERMINATED BY ',' (
...
)
)
LOCATION ('customers*.csv.gz')
)
REJECT LIMIT UNLIMITED;
/home/gerald/customers_1.csv.gz
�Ycustomers_1.csv�A
�0@�}�2�$�b�R�bz��
���є$����<
�A�Ѧ��r~(/XH�2�尫
��8�~{���t�A�Ѧ��r~
(/XH�2�尫
11g
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
External tables
27
Un-compress files on the fly
SQL> SELECT int, last_name, dob
FROM customers_ext_comp;
INT LAST_NAME DOB
--- ---------- ---------
GK Kolaski 12-SEP-88
JS Smith 24-MAR-93
GT Teller 02-NOV-69
SQL> SELECT first_name, last_name
FROM customers_ext_comp
WHERE first_name COLLATE_BINARY_CI
LIKE 'GE%';
FIRST_NAME LAST_NAME
---------- ---------
George Kolaski
Gerald Teller
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
External tables
28
Easy data loading
SQL> CREATE TABLE customers AS
SELECT * FROM customers_ext_comp;
Table created.
SQL> SELECT first_name, int, last_name, dob
FROM customers;
FIRST_NAME INT LAST_NAME DOB
---------- --- ---------- ---------
Geroge GK Kolaski 12-SEP-88
Joseph JS Smith 24-MAR-93
Gerald GT Teller 02-NOV-69
CUSTOMERS
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
External tables
29
Easy data export
SQL> CREATE TABLE customers_dump
ORGANIZATION EXTERNAL
(
TYPE ORACLE_DATAPUMP
DEFAULT DIRECTORY HOME_DIR
LOCATION ('customers.dmp')
)
AS SELECT * FROM customers;
Table created.
CUSTOMERS
11g
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
External tables
30
Easily query your dump files
CREATE TABLE customers_dmp (
first_name varchar2(10),
int varchar2 (2),
last_name varchar2 (10),
dob date
)
ORGANIZATION EXTERNAL
(
TYPE ORACLE_DATAPUMP
DEFAULT DIRECTORY HOME_DIR
LOCATION ('customers.dmp')
);
SQL> SELECT int, dob
FROM customers_dmp
WHERE last_name = 'Teller';
INT DOB
--- ---------
GT 02-NOV-69
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
External tables
31
Easily query on HDFS/Hive
CREATE TABLE customers_ext(
...
)
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY HDFS_DIR
ACCESS PARAMETERS (
RECORDS DELIMITED BY 0X'0A'
PREPROCESSOR
”OSCH_BIN_PATH":'hdfs_stream'
SKIP 1
FIELDS TERMINATED BY ',' (
...
)
)
LOCATION ('osch-20140515719-2786-1')
)
REJECT LIMIT UNLIMITED;
CAT osch-20140515719-2786-1
<?xml version="1.0"?>
<configuration>
<property>
<name>oracle.hadoop.exttab.tableName</name>
<value>SH.SALES_EXT_DIR</value>
</property>
<property>
<name>oracle.hadoop.exttab.dataPaths</name>
<value>/data/s1/*.csv,/data/s2/*.csv</value>
</property>
Requires Oracle SQL Connector for Hadoop
12c
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Useful Supplied
PL/SQL Packages
32
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_SESSION.SLEEP()
33
Accessible sleep function within PL/SQL
SQL> set timing on;
SQL> DECLARE
v_start date;
v_end date;
BEGIN
v_start := SYSDATE;
-- Sleep for 10 seconds
dbms_lock.sleep(10);
v_end := SYSDATE;
END;
/
PL/SQL procedure successfully
completed.
Elapsed: 00:00:10.02
• DBMS_LOCK includes other, more
sensitive methods
• Therefore not granted to public
• Requires DBA intervention to get a
accessible sleep function in PL/SQL
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_SESSION.SLEEP()
34
Accessible sleep function within PL/SQL
SQL> set timing on;
SQL> DECLARE
v_start date;
v_end date;
BEGIN
v_start := SYSDATE;
-- Sleep for 10 seconds
DBMS_SESSION.SLEEP(10);
v_end := SYSDATE;
END;
/
PL/SQL procedure successfully
completed.
Elapsed: 00:00:10.02
• Doesn’t require GRANT anymore
– Before required explicit grant on
DBMS_LOCK
– DBMS_SESSION granted to public
• Compatible with DBMS_LOCK.SLEEP
– You can search/replace
• Introduced thanks to the Oracle
community
– https://community.oracle.com/ideas/4852
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_UTILITY.EXPAND_SQL_TEXT
• Views can be a useful way to hide
complexity from developers
• But they can also cause problems
• It's easy to write apparently simple
statements, that result in extremely
complex SQL being sent to the database
• The DBMS_UTILITY.EXPAND_SQL_TEXT
procedure expands references to views,
turning them into subqueries in the
original statement
35
SQL> SELECT * FROM sales_v;
Determining if this really is the right view to use
12c
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_UTILITY.EXPAND_SQL_TEXT
set serveroutput on
DECLARE
l_clob CLOB;
BEGIN
dbms_utility.expand_sql_text(-
input_sql_text => 'SELECT * FROM sales_v', -
output_sql_text => l_clob);
dbms_output.put_line(l_clob);
END;
/
36
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_UTILITY.EXPAND_SQL_TEXT
SELECT "A1"."order_id" "ORDER_ID",
"A1"."time_id" "TIME_ID",
"A1"."cust_id" "CUST_ID",
"A1"."prod_id" "PROD_ID"
FROM (SELECT "A3"."order_id" "ORDER_ID",
"A3"."time_id" "TIME_ID",
"A3"."cust_id" "CUST_ID",
"A3"."prod_id" "PROD_ID"
FROM "SH"."sales" "A3",
"SH"."products" "A2"
WHERE "A3"."prod_id" = "A2"."prod_id") "A1"
37
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_UTILITY.EXPAND_SQL_TEXT
SELECT "A1"."order_id" "ORDER_ID",
"A1"."time_id" "TIME_ID",
"A1"."cust_id" "CUST_ID",
"A1"."prod_id" "PROD_ID"
FROM (SELECT "A3"."order_id" "ORDER_ID",
"A3"."time_id" "TIME_ID",
"A3"."cust_id" "CUST_ID",
"A3"."prod_id" "PROD_ID"
FROM "SH"."sales" "A3",
"SH"."products" "A2"
WHERE "A3"."prod_id" = "A2"."prod_id") "A1"
38
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_ADVANCED_REWRITE
39
Fixing the unfixable SQL statement
• You’ve been told you need to fix a
SQL statement that is no longer
returning results in the correct order
• But you can’t change the application
code directly as that would require
down time
• What do you do?
SQL> SELECT x, y, sum(z) FROM t
GROUP BY x, y;
X Y SUM(Z)
---------- ---------- ----------
1 4 110
2 3 84
Something changes and now you get
SQL> SELECT x, y, sum(z) FROM t
GROUP BY x, y;
X Y SUM(Z)
---------- ---------- ----------
2 3 84
1 4 110
10g
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_ADVANCED_REWRITE
40
Fixing the unfixable SQL statement
Step 1
• Check what changed with the
execution plan
ORIGINIAL PLAN
-----------------------------------
| Id | Operation | Name |
-----------------------------------
| 0 | SELECT STATEMENT | |
| 1 | HASH GROUP BY | |
| 2 | TABLE ACCESS FULL| T |
-----------------------------------
NEW PLAN
--------------------------------------
| Id | Operation | Name |
--------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT GROUP BY NOSORT| |
| 2 | INDEX FULL SCAN |T_IDX |
--------------------------------------
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_ADVANCED_REWRITE
41
Fixing the unfixable SQL statement
Step 2
• Check the order of the columns in the
index
SQL> SELECT column_position,
column_name
FROM user_ind_columns
WHERE index_name='T_IDX'
ORDER BY column_position;
COLUMN_POSITION COLUMN
--------------- ------
1 Y
2 X
3 Z
• New index returns the rows in a
different order because its sorted on
column Y rather than X
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_ADVANCED_REWRITE
42
Fixing the unfixable SQL statement
Step 3
• Create a view v that includes an order
by clause so the query results will
always be order based on the values
column x
SQL> CREATE OR REPLACE VIEW v
2 AS
3 SELECT x, y, sum(z) "SUM(Z)"
4 FROM t
5 GROUP BY x, y
6 ORDER BY x, y;
View created.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_ADVANCED_REWRITE
43
Fixing the unfixable SQL statement
Step 4
• Use the DBMS_ADVANCED_REWRITE procedure to map the original query
to a simple SELECT * FROM v;
SQL> BEGIN
2 sys.dbms_advanced_rewrite.declare_rewrite_equivalence(
3 name => 'DEMO_TIME',
4 source_stmt => ’SELECT x, y, sum(z) FROM t GROUP BY x, y',
5 destination_stmt => 'SELECT * FROM v',
6 validate => FALSE,
7 rewrite_mode => 'TEXT_MATCH');
8 END;
9 /
PL/SQL procedure successfully completed.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_ADVANCED_REWRITE
44
Fixing the unfixable SQL statement
• Each time our original SQL statement
is issued the
DBMS_ADVANCED_REWRITE
procedure rewrites it to be
SELECT * FROM v;
• Always get the query
output in an order list
SQL> SELECT x, y, sum(z) FROM t
GROUP BY x, y;
X Y SUM(Z)
---------- ---------- ----------
1 4 110
2 3 84
-----------------------------------
| Id | Operation | Name |
-----------------------------------
| 0 | SELECT STATEMENT | |
| 1 | VIEW | V |
| 2 | SORT GROUP BY | |
| 3 | INDEX FULL SCAN|T_IDX |
-----------------------------------
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 45
How to Find your Needle in
the Haystack
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Finding YOUR needle in the haystack
• Databases are high concurrency, multi-user data management systems
• A performance issue in your app requires to filter out the noise from
everybody else, but how to do that?
• If only there was a way to clearly identify the different modules and
actions from your application…
46
How to filter the noise from YOUR workload
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Finding YOUR needle in the haystack
DBMS_APPLICATION_INFO
• SET_CLIENT_INFO()
– Supply additional information about the client application
• SET_MODULE()
– Set the name of the current application or application module
• SET_ACTION()
– Set the name of the current action within the module
• SET_SESSION_LONGOPS()
– Record the on-going progress of a long running operation in V$SESSION_LONGOPS
47
How to filter the noise from YOUR workload
8i
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Finding YOUR needle in the haystack
48
Native APIs - Python
conn = cx_Oracle.connect(
db_user,
db_password,
cx_Oracle.makedsn(db_host, db_port, service_name=db_name))
conn.client_identifier = "Twitter Streamer”
conn.module = "DBLoader”
conn.action = “persist”
cursor = conn.cursor()
cursor.prepare("INSERT INTO TWITTER (tweet) VALUES (:tweet)")
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Finding YOUR needle in the haystack
49
Native APIs – Node.js
oracledb.getConnection({
user : db_user,
password : db_password,
connectString : db_url
},
function(err, connection) {
if (err) { console.error(err.message); return; }
connection.clientId = ”Twitter Streamer";
connection.module = ”DBLoader";
connection.action = ”persist";
connection.execute(”INSERT INTO TWITTER (tweet) VALUES (:tweet)",
function(err, result) {
. . .
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Finding YOUR needle in the haystack
50
Native APIs – Java
Connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
conn.setClientInfo("OCSID.CLIENTID", ”Twitter Streamer");
conn.setClientInfo("OCSID.MODULE", ”DBLoader");
conn.setClientInfo("OCSID.ACTION", ”persist");
Statement stmt = conn.createStatement();
stmt.execute("INSERT INTO TWITTER (tweet) VALUES (?)");
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Finding YOUR needle in the haystack
51
AWR report
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Finding YOUR needle in the haystack
52
Active Monitor
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Finding YOUR needle in the haystack
53
Active Monitor – SQL details
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
If you have more questions later, feel free to ask

More Related Content

PDF
Developers vs DBAs - How to win the war
PDF
Data Management in a Microservices World
PDF
Top 10 SQL Performance tips & tricks for Java Developers
PDF
Supercharge your Code to get optimal Database Performance
PDF
Java EE 8 - February 2017 update
PDF
JAX-RS 2.1 Reloaded
PDF
Java EE Next
PDF
Oracle Solaris Cloud Management and Deployment with OpenStack
Developers vs DBAs - How to win the war
Data Management in a Microservices World
Top 10 SQL Performance tips & tricks for Java Developers
Supercharge your Code to get optimal Database Performance
Java EE 8 - February 2017 update
JAX-RS 2.1 Reloaded
Java EE Next
Oracle Solaris Cloud Management and Deployment with OpenStack

What's hot (20)

PDF
Dockerizing Oracle Database
PDF
Another compilation method in java - AOT (Ahead of Time) compilation
PDF
HTTP/2 comes to Java
PDF
Oracle Solaris Overview
PDF
Java EE 8 Overview (Japanese)
PDF
OOW16 - Oracle E-Business Suite: Technology Certification Primer and Roadmap ...
PPT
HTML5 based PivotViewer for Visualizing LInked Data
PDF
OOW16 - Running your E-Business Suite on Oracle Cloud (IaaS + PaaS) - Why, Wh...
PPTX
Ed presents JSF 2.2 and WebSocket to Gameduell.
PPTX
Nonblocking Database Access in Helidon SE
PDF
OOW16 - Advanced Architectures for Oracle E-Business Suite [CON6705]
PDF
OOW16 - Ready or Not: Applying Secure Configuration to Oracle E-Business Suit...
PDF
Java EE 7 from an HTML5 Perspective, JavaLand 2015
PPT
Using SAP Crystal Reports as a Linked (Open) Data Front-End via ODBC
PDF
Oracle cmg15
PDF
Java EE 8 - Work in progress
PDF
Adopt-a-JSR for JSON Processing 1.1, JSR 374
PDF
JSF 2.2 Input Output JavaLand 2015
PPT
Exploiting Linked (Open) Data via Microsoft Access
PDF
OOW16 - Oracle E-Business Suite in Oracle Cloud: Technical Insight [CON6723]
Dockerizing Oracle Database
Another compilation method in java - AOT (Ahead of Time) compilation
HTTP/2 comes to Java
Oracle Solaris Overview
Java EE 8 Overview (Japanese)
OOW16 - Oracle E-Business Suite: Technology Certification Primer and Roadmap ...
HTML5 based PivotViewer for Visualizing LInked Data
OOW16 - Running your E-Business Suite on Oracle Cloud (IaaS + PaaS) - Why, Wh...
Ed presents JSF 2.2 and WebSocket to Gameduell.
Nonblocking Database Access in Helidon SE
OOW16 - Advanced Architectures for Oracle E-Business Suite [CON6705]
OOW16 - Ready or Not: Applying Secure Configuration to Oracle E-Business Suit...
Java EE 7 from an HTML5 Perspective, JavaLand 2015
Using SAP Crystal Reports as a Linked (Open) Data Front-End via ODBC
Oracle cmg15
Java EE 8 - Work in progress
Adopt-a-JSR for JSON Processing 1.1, JSR 374
JSF 2.2 Input Output JavaLand 2015
Exploiting Linked (Open) Data via Microsoft Access
OOW16 - Oracle E-Business Suite in Oracle Cloud: Technical Insight [CON6723]
Ad

Similar to Oracle Database features every developer should know about (20)

PPTX
MySQL 8.0 Released Update
PDF
SQL for Analytics.pdfSQL for Analytics.pdf
PDF
Upcoming changes in MySQL 5.7
PPTX
D73549GC10_06.pptx
PPTX
Beginners guide to_optimizer
PPTX
Five_Things_You_Might_Not_Know_About_Oracle_Database_v2.pptx
PDF
Developers’ mDay u Banjoj Luci - Bogdan Kecman, Oracle – MySQL Server 8.0
PDF
Developers' mDay 2017. - Bogdan Kecman Oracle
PPTX
Useful PL/SQL Supplied Packages
PDF
Oracle Sqlplus Pocket Reference 3rd Ed Jonathan Gennick
PDF
MySQL Day Virtual: Best Practices Tips - Upgrading to MySQL 8.0
PDF
Database Basics with PHP -- Connect JS Conference October 17th, 2015
PPTX
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
PDF
Big Data: Getting off to a fast start with Big SQL (World of Watson 2016 sess...
PPTX
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
PDF
Oracle SQL Tuning
PDF
Meetup my sql5.6_cluster
PPT
08 Dynamic SQL and Metadata
PPTX
Oracle Database 12c - New Features for Developers and DBAs
PPTX
Oracle Database 12c - New Features for Developers and DBAs
MySQL 8.0 Released Update
SQL for Analytics.pdfSQL for Analytics.pdf
Upcoming changes in MySQL 5.7
D73549GC10_06.pptx
Beginners guide to_optimizer
Five_Things_You_Might_Not_Know_About_Oracle_Database_v2.pptx
Developers’ mDay u Banjoj Luci - Bogdan Kecman, Oracle – MySQL Server 8.0
Developers' mDay 2017. - Bogdan Kecman Oracle
Useful PL/SQL Supplied Packages
Oracle Sqlplus Pocket Reference 3rd Ed Jonathan Gennick
MySQL Day Virtual: Best Practices Tips - Upgrading to MySQL 8.0
Database Basics with PHP -- Connect JS Conference October 17th, 2015
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
Big Data: Getting off to a fast start with Big SQL (World of Watson 2016 sess...
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Oracle SQL Tuning
Meetup my sql5.6_cluster
08 Dynamic SQL and Metadata
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
Ad

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Cloud computing and distributed systems.
PDF
Encapsulation theory and applications.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Approach and Philosophy of On baking technology
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
MYSQL Presentation for SQL database connectivity
cuic standard and advanced reporting.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectroscopy.pptx food analysis technology
Unlocking AI with Model Context Protocol (MCP)
20250228 LYD VKU AI Blended-Learning.pptx
sap open course for s4hana steps from ECC to s4
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation_ Review paper, used for researhc scholars
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Cloud computing and distributed systems.
Encapsulation theory and applications.pdf
Empathic Computing: Creating Shared Understanding
Approach and Philosophy of On baking technology
NewMind AI Weekly Chronicles - August'25-Week II
MYSQL Presentation for SQL database connectivity

Oracle Database features every developer should know about

  • 1. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Oracle Database Features Every Developer Should Know About Gerald Venzl Senior Principal Product Manager Oracle Development August, 2018 @GeraldVenzl
  • 2. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 2
  • 3. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Join the Conversation 3 Related Videos • Gerald’s YouTube Channel • Oracle Database PM Channel Any Additional Questions • My emails: gerald.venzl[at]oracle.com Additional Resources https://geraldonit.com https://twitter.com/GeraldVenzl
  • 4. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Program Agenda Invisible Columns Virtual Columns External Tables Useful Supplied PL/SQL Packages How to Find Your Needle in the Haystack 1 2 3 4 4 5
  • 5. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Invisible Columns 5
  • 6. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Invisible columns Difficulties with the relational model today: • Different applications may need different columns from a single table but all applications are impacted by any DDL change on a table – Dropping a column will break queries still referring to it – Adding a column breaks “SELECT *” queries – Dropping a column will delete the data from all the rows, even those that are already archived 6 Flexible schemas in a relational model 12c
  • 7. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Invisible columns Difficulties with the relational model today: • Different applications may need different columns from a single table but all applications are impacted by any DDL change on a table – Dropping a column will break queries still referring to it – Adding a column breaks “SELECT *” queries – Dropping a column will delete the data from all the rows, even those that are already archived • Invisible columns allows you to introduce non-disruptive DDL changes 7 Flexible schemas in a relational model 12c
  • 8. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Invisible columns 8 Dropping columns is disruptive SQL> SELECT first_name, last_name, initials FROM customers; FIRST_NAME LAST_NAME IN ---------- ---------- -- George Kolaski GK Joseph Smith JS Gerald Teller GT SQL> SELECT first_name, last_name, initials FROM customers; FIRST_NAME LAST_NAME IN ---------- ---------- -- George Kolaski GK Joseph Smith JS Gerald Teller GT App A App B FIRST_NAME LAST_NAMEINITIALS
  • 9. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Invisible columns 9 Dropping columns is disruptive SQL> SELECT first_name, last_name, initials FROM customers; SELECT first_name, last_name, initials * ERROR at line 1: ORA-00904: "INITIALS": invalid identifier App A App B LAST_NAMEFIRST_NAME ALTER TABLE customers DROP COLUMN initials; SQL> SELECT first_name, last_name FROM customers; FIRST_NAME LAST_NAME --------- ---------- George Kolaski Joseph Smith Gerald Teller
  • 10. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Invisible columns 10 Dropping columns is disruptive SQL> SELECT first_name, last_name FROM customers; FIRST_NAME LAST_NAME --------- ---------- Geroge Kolaski Joseph Smith Gerald Teller App A App B FIRST_NAME LAST_NAMEINITIALS ALTER TABLE customers MODIFY initials INVISIBLE; SQL> SELECT first_name, last_name FROM customers; FIRST_NAME LAST_NAME ---------- ---------- George Kolaski Joseph Smith Gerald Teller SQL> SELECT first_name, last_name, initials FROM customers; FIRST_NAME LAST_NAME IN ---------- ---------- -- George Kolaski GK Joseph Smith JS Gerald Teller GT
  • 11. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Invisible columns 11 Adding columns is disruptive App A App C LAST_NAMEFIRST_NAME SQL> SELECT first_name, last_name FROM customers; FIRST_NAME LAST_NAME ---------- ---------- George Kolaski Joseph Smith Gerald Teller SQL> SELECT * FROM customers; FIRST_NAME LAST_NAME ---------- ---------- George Kolaski Joseph Smith Gerald Teller
  • 12. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | SQL> SELECT * FROM customers; FIRST_NAME LAST_NAME DOB ---------- ---------- --------- George Kolaski 12-SEP-88 Joseph Smith 24-MAR-93 Gerald Teller 02-NOV-69 Invisible columns 12 Adding columns is disruptive SQL> SELECT first_name, last_name, dob FROM customers; FIRST_NAME LAST_NAME DOB ---------- ---------- --------- George Kolaski 12-SEP-88 Joseph Smith 24-MAR-93 Gerald Teller 02-NOV-69 App A App C LAST_NAMEFIRST_NAME DOB ALTER TABLE customers ADD dob date;
  • 13. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | SQL> SELECT * FROM customers; FIRST_NAME LAST_NAME ---------- ---------- George Kolaski Joseph Smith Gerald Teller Invisible columns 13 Adding columns is disruptive App A App C LAST_NAMEFIRST_NAME DOB ALTER TABLE customers ADD dob date INVISIBLE; SQL> SELECT first_name, last_name, dob FROM customers; FIRST_NAME LAST_NAME DOB ---------- ---------- --------- George Kolaski 12-SEP-88 Joseph Smith 24-MAR-93 Gerald Teller 02-NOV-69
  • 14. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Invisible columns • Invisible columns can be used as partition keys • Be aware that column order changes when setting columns invisible • Use SET COLINVISIBLE ON; to see invisible columns in DESC 14 Flexible schemas in a relational model SQL> SET COLINVISIBLE ON; SQL> DESC CUSTOMERS; Name Null? Type ----------------- -------- ------------ FIRST_NAME VARCHAR2(10) LAST_NAME VARCHAR2(10) DOB (INVISIBLE) DATE LAST_NAMEFIRST_NAME DOB
  • 15. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Virtual Columns 15
  • 16. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Virtual columns • Example: Compute total sales price • Net = Price + (Price * Tax) • As expressions get more complex it’s possible developers will accidentally define them differently in their code • This results in inconsistent reporting • You could change the data model every time the business determines a new measure & create a trigger to populate the data 16 Analytic queries often contain complex expressions PRODUCT TAXPRICE Price+Price*Tax 11g
  • 17. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Virtual columns 17 Add column with insert trigger PRODUCT TAXPRICE Price+Price*Tax NET SQL> ALTER TABLE sales ADD net number INVISIBLE; Table Altered. SQL> UPDATE sales set net = price+(price*tax); 15 rows updated. SQL> CREATE OR REPLACE TRIGGER set_net BEFORE INSERT or UPDATE ON sales FOR EACH ROW BEGIN :new.net := :new.price + (:new.price * :new.tax); END; / Trigger created.
  • 18. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Virtual columns 18 Add column with insert trigger PRODUCT TAXPRICE Price+Price*Tax NET SQL> INSERT INTO sales (product, price, tax) VALUES('Toy Train','5',’0.08'); 1 row created. SQL> COMMIT; Commit complete. SQL> SELECT product, price, tax, net FROM sales; PRODUCT PRICE TAX NET ---------- ---------- ---------- ---------- Toy Train 5 0.08 5.4
  • 19. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Virtual columns 19 Appear to be normal table columns PRODUCT TAXPRICE NET SQL> ALTER TABLE sales ADD net number INVISIBLE GENERATED ALWAYS AS (price+(price*tax))VIRTUAL; Table Altered SQL> INSERT INTO sales (product, price, tax) VALUES('Toy Train','5',’0.08'); 1 row created. SQL> COMMIT; Commit complete. SQL> SELECT prod, price, tax, net FROM sales; PRODUCT PRICE TAX NET ---------- ---------- ---------- ---------- Toy Train 5 0.08 5.4 Price+Price*Tax
  • 20. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Virtual columns 20 Can be used in where clause PRODUCT TAXPRICE NET SQL> SELECT product, price, tax, net FROM sales WHERE net > 5; PRODUCT PRICE TAX NET ---------- ---------- ---------- ---------- Toy Train 5 0.08 5.4 SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR()); PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------- Plan hash value: 781590677 ----------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | ----------------------------------------------------------------------------- | 0 |SELECT STATEMENT | | 1788 | 228K| 20 | | 1|TABLE ACCESS FULL | SALES | 1788 | 228K| 20 | ------------------------------------------------------------------------------ Price+Price*Tax
  • 21. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Virtual columns 21 Can be indexed PRODUCT TAXPRICE NET SQL> SELECT prod, price, tax, net FROM sales WHERE net > 5; PROD PRICE TAX NET ---------- ---------- ---------- ---------- Toy Train 5 0.08 5.4 SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR()); PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------- Plan hash value: 781590677 ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | ------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1788 | | 1 | TABLE ACCESS BY INDEX ROWID | SALES | 1788 | | 2| INDEX RANGE SCAN | IDX_NET | 1788 | ------------------------------------------------------------------------------ CREATE INDEX idx_net ON sales(net); Price+Price*Tax
  • 22. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | External Tables 22 SALESTABLE(external) UKPartition GermanyPartition USAPartition SQL
  • 23. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | External tables • Query flat files as if they were tables in the database – Provides the full power of SQL over flat files • Preprocessor capabilities – Un-compress, pre-format, etc. data before being read by the database • Enables easy data loading – Use INSERT INTO … SELECT (incl. DML error logging) • Query data pump files – Run queries on last nights backup to confirm it validity • Query data store on HDFS/Hive 23 The universal out-of-database query interface 9i
  • 24. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | External tables 24 Query files as if they were tables CREATE TABLE customers_ext( first_name varchar2 (10), int varchar2 (2), last_name varchar2 (10), dob date ) ORGANIZATION EXTERNAL ( TYPE ORACLE_LOADER DEFAULT DIRECTORY HOME_DIR ACCESS PARAMETERS ( RECORDS DELIMITED BY NEWLINE SKIP 1 FIELDS TERMINATED BY ',' ( first_name char(10), last_name char(10), int char(2), DOB char (10) DATE_FORMAT DATE 'YYYY-MM-DD') ) LOCATION ('customers*.csv')) REJECT LIMIT UNLIMITED; CREATE DIRECTORY home_dir AS ‘/home/gerald/’; /home/gerald/customers_1.csv FName,LName,Initials,DOB George,Kolaski,GK,1988-09-12 Joseph,Smith,JS,1993-03-24 Gerald,Teller,GT,19691102 : :
  • 25. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | External tables 25 Query files as if they were tables SQL> SELECT first_name, last_name, dob FROM customers_ext; FIRST_NAME LAST_NAME DOB ---------- ---------- --------- Geroge Kolaski 12-SEP-88 Joseph Smith 24-MAR-93 Gerald Teller 02-NOV-69 SQL> SELECT first_name, last_name FROM customers_ext WHERE dob > TO_DATE('1990','YYYY'); FIRST_NAME LAST_NAME ---------- --------- Joseph Smith FName,LName,Initials,DOB George,Kolaski,GK,1988-09-12 Joseph,Smith,JS,1993-03-24 Gerald,Teller,GT,19691102 : : /home/gerald/customers_1.csv
  • 26. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | External tables 26 Un-compress files on the fly CREATE TABLE customers_ext_comp( ... ) ORGANIZATION EXTERNAL ( TYPE ORACLE_LOADER DEFAULT DIRECTORY HOME_DIR ACCESS PARAMETERS ( RECORDS DELIMITED BY NEWLINE PREPROCESSOR USR_BIN:zcat SKIP 1 FIELDS TERMINATED BY ',' ( ... ) ) LOCATION ('customers*.csv.gz') ) REJECT LIMIT UNLIMITED; /home/gerald/customers_1.csv.gz �Ycustomers_1.csv�A �0@�}�2�$�b�R�bz�� ���є$����< �A�Ѧ��r~(/XH�2�尫 ��8�~{���t�A�Ѧ��r~ (/XH�2�尫 11g
  • 27. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | External tables 27 Un-compress files on the fly SQL> SELECT int, last_name, dob FROM customers_ext_comp; INT LAST_NAME DOB --- ---------- --------- GK Kolaski 12-SEP-88 JS Smith 24-MAR-93 GT Teller 02-NOV-69 SQL> SELECT first_name, last_name FROM customers_ext_comp WHERE first_name COLLATE_BINARY_CI LIKE 'GE%'; FIRST_NAME LAST_NAME ---------- --------- George Kolaski Gerald Teller
  • 28. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | External tables 28 Easy data loading SQL> CREATE TABLE customers AS SELECT * FROM customers_ext_comp; Table created. SQL> SELECT first_name, int, last_name, dob FROM customers; FIRST_NAME INT LAST_NAME DOB ---------- --- ---------- --------- Geroge GK Kolaski 12-SEP-88 Joseph JS Smith 24-MAR-93 Gerald GT Teller 02-NOV-69 CUSTOMERS
  • 29. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | External tables 29 Easy data export SQL> CREATE TABLE customers_dump ORGANIZATION EXTERNAL ( TYPE ORACLE_DATAPUMP DEFAULT DIRECTORY HOME_DIR LOCATION ('customers.dmp') ) AS SELECT * FROM customers; Table created. CUSTOMERS 11g
  • 30. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | External tables 30 Easily query your dump files CREATE TABLE customers_dmp ( first_name varchar2(10), int varchar2 (2), last_name varchar2 (10), dob date ) ORGANIZATION EXTERNAL ( TYPE ORACLE_DATAPUMP DEFAULT DIRECTORY HOME_DIR LOCATION ('customers.dmp') ); SQL> SELECT int, dob FROM customers_dmp WHERE last_name = 'Teller'; INT DOB --- --------- GT 02-NOV-69
  • 31. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | External tables 31 Easily query on HDFS/Hive CREATE TABLE customers_ext( ... ) ORGANIZATION EXTERNAL ( TYPE ORACLE_LOADER DEFAULT DIRECTORY HDFS_DIR ACCESS PARAMETERS ( RECORDS DELIMITED BY 0X'0A' PREPROCESSOR ”OSCH_BIN_PATH":'hdfs_stream' SKIP 1 FIELDS TERMINATED BY ',' ( ... ) ) LOCATION ('osch-20140515719-2786-1') ) REJECT LIMIT UNLIMITED; CAT osch-20140515719-2786-1 <?xml version="1.0"?> <configuration> <property> <name>oracle.hadoop.exttab.tableName</name> <value>SH.SALES_EXT_DIR</value> </property> <property> <name>oracle.hadoop.exttab.dataPaths</name> <value>/data/s1/*.csv,/data/s2/*.csv</value> </property> Requires Oracle SQL Connector for Hadoop 12c
  • 32. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Useful Supplied PL/SQL Packages 32
  • 33. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_SESSION.SLEEP() 33 Accessible sleep function within PL/SQL SQL> set timing on; SQL> DECLARE v_start date; v_end date; BEGIN v_start := SYSDATE; -- Sleep for 10 seconds dbms_lock.sleep(10); v_end := SYSDATE; END; / PL/SQL procedure successfully completed. Elapsed: 00:00:10.02 • DBMS_LOCK includes other, more sensitive methods • Therefore not granted to public • Requires DBA intervention to get a accessible sleep function in PL/SQL
  • 34. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_SESSION.SLEEP() 34 Accessible sleep function within PL/SQL SQL> set timing on; SQL> DECLARE v_start date; v_end date; BEGIN v_start := SYSDATE; -- Sleep for 10 seconds DBMS_SESSION.SLEEP(10); v_end := SYSDATE; END; / PL/SQL procedure successfully completed. Elapsed: 00:00:10.02 • Doesn’t require GRANT anymore – Before required explicit grant on DBMS_LOCK – DBMS_SESSION granted to public • Compatible with DBMS_LOCK.SLEEP – You can search/replace • Introduced thanks to the Oracle community – https://community.oracle.com/ideas/4852
  • 35. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_UTILITY.EXPAND_SQL_TEXT • Views can be a useful way to hide complexity from developers • But they can also cause problems • It's easy to write apparently simple statements, that result in extremely complex SQL being sent to the database • The DBMS_UTILITY.EXPAND_SQL_TEXT procedure expands references to views, turning them into subqueries in the original statement 35 SQL> SELECT * FROM sales_v; Determining if this really is the right view to use 12c
  • 36. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_UTILITY.EXPAND_SQL_TEXT set serveroutput on DECLARE l_clob CLOB; BEGIN dbms_utility.expand_sql_text(- input_sql_text => 'SELECT * FROM sales_v', - output_sql_text => l_clob); dbms_output.put_line(l_clob); END; / 36
  • 37. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_UTILITY.EXPAND_SQL_TEXT SELECT "A1"."order_id" "ORDER_ID", "A1"."time_id" "TIME_ID", "A1"."cust_id" "CUST_ID", "A1"."prod_id" "PROD_ID" FROM (SELECT "A3"."order_id" "ORDER_ID", "A3"."time_id" "TIME_ID", "A3"."cust_id" "CUST_ID", "A3"."prod_id" "PROD_ID" FROM "SH"."sales" "A3", "SH"."products" "A2" WHERE "A3"."prod_id" = "A2"."prod_id") "A1" 37
  • 38. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_UTILITY.EXPAND_SQL_TEXT SELECT "A1"."order_id" "ORDER_ID", "A1"."time_id" "TIME_ID", "A1"."cust_id" "CUST_ID", "A1"."prod_id" "PROD_ID" FROM (SELECT "A3"."order_id" "ORDER_ID", "A3"."time_id" "TIME_ID", "A3"."cust_id" "CUST_ID", "A3"."prod_id" "PROD_ID" FROM "SH"."sales" "A3", "SH"."products" "A2" WHERE "A3"."prod_id" = "A2"."prod_id") "A1" 38
  • 39. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_ADVANCED_REWRITE 39 Fixing the unfixable SQL statement • You’ve been told you need to fix a SQL statement that is no longer returning results in the correct order • But you can’t change the application code directly as that would require down time • What do you do? SQL> SELECT x, y, sum(z) FROM t GROUP BY x, y; X Y SUM(Z) ---------- ---------- ---------- 1 4 110 2 3 84 Something changes and now you get SQL> SELECT x, y, sum(z) FROM t GROUP BY x, y; X Y SUM(Z) ---------- ---------- ---------- 2 3 84 1 4 110 10g
  • 40. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_ADVANCED_REWRITE 40 Fixing the unfixable SQL statement Step 1 • Check what changed with the execution plan ORIGINIAL PLAN ----------------------------------- | Id | Operation | Name | ----------------------------------- | 0 | SELECT STATEMENT | | | 1 | HASH GROUP BY | | | 2 | TABLE ACCESS FULL| T | ----------------------------------- NEW PLAN -------------------------------------- | Id | Operation | Name | -------------------------------------- | 0 | SELECT STATEMENT | | | 1 | SORT GROUP BY NOSORT| | | 2 | INDEX FULL SCAN |T_IDX | --------------------------------------
  • 41. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_ADVANCED_REWRITE 41 Fixing the unfixable SQL statement Step 2 • Check the order of the columns in the index SQL> SELECT column_position, column_name FROM user_ind_columns WHERE index_name='T_IDX' ORDER BY column_position; COLUMN_POSITION COLUMN --------------- ------ 1 Y 2 X 3 Z • New index returns the rows in a different order because its sorted on column Y rather than X
  • 42. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_ADVANCED_REWRITE 42 Fixing the unfixable SQL statement Step 3 • Create a view v that includes an order by clause so the query results will always be order based on the values column x SQL> CREATE OR REPLACE VIEW v 2 AS 3 SELECT x, y, sum(z) "SUM(Z)" 4 FROM t 5 GROUP BY x, y 6 ORDER BY x, y; View created.
  • 43. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_ADVANCED_REWRITE 43 Fixing the unfixable SQL statement Step 4 • Use the DBMS_ADVANCED_REWRITE procedure to map the original query to a simple SELECT * FROM v; SQL> BEGIN 2 sys.dbms_advanced_rewrite.declare_rewrite_equivalence( 3 name => 'DEMO_TIME', 4 source_stmt => ’SELECT x, y, sum(z) FROM t GROUP BY x, y', 5 destination_stmt => 'SELECT * FROM v', 6 validate => FALSE, 7 rewrite_mode => 'TEXT_MATCH'); 8 END; 9 / PL/SQL procedure successfully completed.
  • 44. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_ADVANCED_REWRITE 44 Fixing the unfixable SQL statement • Each time our original SQL statement is issued the DBMS_ADVANCED_REWRITE procedure rewrites it to be SELECT * FROM v; • Always get the query output in an order list SQL> SELECT x, y, sum(z) FROM t GROUP BY x, y; X Y SUM(Z) ---------- ---------- ---------- 1 4 110 2 3 84 ----------------------------------- | Id | Operation | Name | ----------------------------------- | 0 | SELECT STATEMENT | | | 1 | VIEW | V | | 2 | SORT GROUP BY | | | 3 | INDEX FULL SCAN|T_IDX | -----------------------------------
  • 45. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 45 How to Find your Needle in the Haystack
  • 46. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Finding YOUR needle in the haystack • Databases are high concurrency, multi-user data management systems • A performance issue in your app requires to filter out the noise from everybody else, but how to do that? • If only there was a way to clearly identify the different modules and actions from your application… 46 How to filter the noise from YOUR workload
  • 47. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Finding YOUR needle in the haystack DBMS_APPLICATION_INFO • SET_CLIENT_INFO() – Supply additional information about the client application • SET_MODULE() – Set the name of the current application or application module • SET_ACTION() – Set the name of the current action within the module • SET_SESSION_LONGOPS() – Record the on-going progress of a long running operation in V$SESSION_LONGOPS 47 How to filter the noise from YOUR workload 8i
  • 48. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Finding YOUR needle in the haystack 48 Native APIs - Python conn = cx_Oracle.connect( db_user, db_password, cx_Oracle.makedsn(db_host, db_port, service_name=db_name)) conn.client_identifier = "Twitter Streamer” conn.module = "DBLoader” conn.action = “persist” cursor = conn.cursor() cursor.prepare("INSERT INTO TWITTER (tweet) VALUES (:tweet)")
  • 49. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Finding YOUR needle in the haystack 49 Native APIs – Node.js oracledb.getConnection({ user : db_user, password : db_password, connectString : db_url }, function(err, connection) { if (err) { console.error(err.message); return; } connection.clientId = ”Twitter Streamer"; connection.module = ”DBLoader"; connection.action = ”persist"; connection.execute(”INSERT INTO TWITTER (tweet) VALUES (:tweet)", function(err, result) { . . .
  • 50. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Finding YOUR needle in the haystack 50 Native APIs – Java Connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword); conn.setClientInfo("OCSID.CLIENTID", ”Twitter Streamer"); conn.setClientInfo("OCSID.MODULE", ”DBLoader"); conn.setClientInfo("OCSID.ACTION", ”persist"); Statement stmt = conn.createStatement(); stmt.execute("INSERT INTO TWITTER (tweet) VALUES (?)");
  • 51. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Finding YOUR needle in the haystack 51 AWR report
  • 52. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Finding YOUR needle in the haystack 52 Active Monitor
  • 53. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Finding YOUR needle in the haystack 53 Active Monitor – SQL details
  • 54. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | If you have more questions later, feel free to ask

Editor's Notes

  • #3: This is a Safe Harbor Front slide, one of two Safe Harbor Statement slides included in this template. One of the Safe Harbor slides must be used if your presentation covers material affected by Oracle’s Revenue Recognition Policy To learn more about this policy, e-mail: Revrec-americasiebc_us@oracle.com For internal communication, Safe Harbor Statements are not required. However, there is an applicable disclaimer (Exhibit E) that should be used, found in the Oracle Revenue Recognition Policy for Future Product Communications. Copy and paste this link into a web browser, to find out more information.   http://my.oracle.com/site/fin/gfo/GlobalProcesses/cnt452504.pdf For all external communications such as press release, roadmaps, PowerPoint presentations, Safe Harbor Statements are required. You can refer to the link mentioned above to find out additional information/disclaimers required depending on your audience.
  • #4: Here are some additional resources. Join the conversation.
  • #18: Need to update all existing rows to populate value for new invisible column
  • #20: Appear to be normal table columns but their value are derived rather than being stored
  • #21: Appear to be normal table columns but their value are derived rather than being stored
  • #22: Appear to be normal table columns but their value are derived rather than being stored
  • #25: Full details: Data: FName,LName,Initials,DateOfBirth George,Kolaski,GK,1988-09-12 Joseph,Smith,JS,1993-03-24 Gerald,Teller,GT,19691102 DDL as SYSTEM: CREATE DIRECTORY HOME_DIR AS ‘/home/oracle/’; GRANT READ,WRITE ON DIRECTORY TO GERALD; As user GERALD: CREATE TABLE CUSTOMERS ( FIRST_NAME VARCHAR2(10), INITIALS VARCHAR2(2), LAST_NAME VARCHAR2(10), DOB DATE ) ORGANIZATION EXTERNAL ( TYPE ORACLE_LOADER DEFAULT DIRECTORY HOME_DIR ACCESS PARAMETERS ( RECORDS DELIMITED BY NEWLINE SKIP 1 FIELDS TERMINATED BY ',' ( first_name CHAR(10), last_name CHAR(10), initials CHAR(2), DOB CHAR(10) DATE_FORMAT DATE 'YYYY-MM-DD' ) ) LOCATION ('customers*.csv') ) REJECT LIMIT UNLIMITED;
  • #27: CREATE DIRECTORY USR_BIN AS '/usr/bin'; GRANT READ, EXECUTE ON DIRECTORY USR_BIN TO GERALD; CREATE TABLE CUSTOMERS_COMP ( FIRST_NAME VARCHAR2(10), INITIALS VARCHAR2(2), LAST_NAME VARCHAR2(10), DOB DATE ) ORGANIZATION EXTERNAL ( TYPE ORACLE_LOADER DEFAULT DIRECTORY HOME_DIR ACCESS PARAMETERS ( RECORDS DELIMITED BY NEWLINE PREPROCESSOR USR_BIN:zcat SKIP 1 FIELDS TERMINATED BY ',' ( first_name CHAR(10), last_name CHAR(10), initials CHAR(2), DOB CHAR(10) DATE_FORMAT DATE 'YYYY-MM-DD' ) ) LOCATION ('customers*.csv.gz') ) REJECT LIMIT UNLIMITED;
  • #32: HDFS_STREAM is a bash script which invokes an Oracle SQL Connector for Hapdoop executable under the covers
  • #33: Copyright: <a href='https://www.123rf.com/profile_3dkombinat'>3dkombinat / 123RF Stock Photo</a>