All About Binds Thomas Kyte. All About Binds It’s.

Slides:



Advertisements
Similar presentations
Topic Reviews For Unit ET156 – Introduction to C Programming Topic Reviews For Unit
Advertisements

Using the SQL Access Advisor
Simplifications of Context-Free Grammars
PDAs Accept Context-Free Languages
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 10: Database Administration Jerry Post Copyright © 2007.
Dr. Alexandra I. Cristea CS 252: Fundamentals of Relational Databases: SQL5.
The basics for simulations
Tuning Oracle SQL The Basics of Efficient SQLThe Basics of Efficient SQL Common Sense Indexing The Optimizer –Making SQL Efficient Finding Problem Queries.
Practical SQL performance tuning, for developers and DBAs Kurt Struyf Competence Partners.
SQL Tuning Briefing Null is not equal to null but null is null.
13 Copyright © 2005, Oracle. All rights reserved. Monitoring and Improving Performance.
Overview of performance tuning strategies Oracle Performance Tuning Allan Young June 2008.
Database Performance Tuning and Query Optimization
MM4A6c: Apply the law of sines and the law of cosines.
”SEO” Search engine optimization Webmanagement training - Dar es Salaam 2008.
Thomas A. Stewart Literacy Test (OSSLT) Prep Guide 2013
23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
CMPT 120 Control Structures in Python
While Loop Lesson CS1313 Spring while Loop Outline 1.while Loop Outline 2.while Loop Example #1 3.while Loop Example #2 4.while Loop Example #3.
Clock Domain Crossing (CDC)
Arithmetic of random variables: adding constants to random variables, multiplying random variables by constants, and adding two random variables together.
PHP 5 + MySQL 5 A Perfect 10. Adam Trachtenberg PHP 5 + MySQL 5 = A Perfect mysqli extension i is for improved! All new MySQL extension for PHP.
Chapter 9 Interactive Multimedia Authoring with Flash Introduction to Programming 1.
Introduction to Recursion and Recursive Algorithms
Order of Operations And Real Number Operations
A Data Warehouse Mining Tool Stephen Turner Chris Frala
1 Non Deterministic Automata. 2 Alphabet = Nondeterministic Finite Accepter (NFA)
Announcements You survived midterm 2! No Class / No Office hours Friday.
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
Copyright © 200\8 Quest Software High Performance PL/SQL Guy Harrison Chief Architect, Database Solutions.
Gary MarsdenSlide 1University of Cape Town Statements & Expressions Gary Marsden Semester 2 – 2000.
Clarity Educational Community Clarity Educational Community Creating and Tuning SQL Queries that Engage Users.
Computer Science 1620 Programming & Problem Solving.
Tempdb Parasites Jason Hall-Dir. of Client SQL Sentry Blog-jasonhall.blogs.sqlsentry.net.
PL/SQL Bulk Collections in Oracle 9i and 10g Kent Crotty Burleson Consulting October 13, 2006.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
Lecture 16 Page 1 CS 236 Online SQL Injection Attacks Many web servers have backing databases –Much of their information stored in a database Web pages.
1 Robert Wijnbelt Health Check your Database A Performance Tuning Methodology.
Oracle PL/SQL Practices. Critical elements of PL/SQL Best Practices Build your development toolbox Unit test PL/SQL programs Optimize SQL in PL/SQL programs.
S2008Final_part1.ppt CS11 Introduction to Programming Final Exam Part 1 S A computer is a mechanical or electrical device which stores, retrieves,
Chapter 25 Formal Methods Formal methods Specify program using math Develop program using math Prove program matches specification using.
Triggers A Quick Reference and Summary BIT 275. Triggers SQL code permits you to access only one table for an INSERT, UPDATE, or DELETE statement. The.
Triggers and Stored Procedures in DB 1. Objectives Learn what triggers and stored procedures are Learn the benefits of using them Learn how DB2 implements.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Oracle tuning: a tutorial Saikat Chakraborty. Introduction In this session we will try to learn how to write optimized SQL statements in Oracle 8i We.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
Concurrency Properties. Correctness In sequential programs, rerunning a program with the same input will always give the same result, so it makes sense.
Visual Basic for Application - Microsoft Access 2003 Finishing the application.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
DB Tuning : Chapter 10. Optimizer Center for E-Business Technology Seoul National University Seoul, Korea 이상근 Intelligent Database Systems Lab School of.
Oracle9i Developer: PL/SQL Programming Chapter 11 Performance Tuning.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
CS422 Principles of Database Systems Stored Procedures and Triggers Chengyu Sun California State University, Los Angeles.
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
Closing the Query Processing Loop in Oracle 11g Allison Lee, Mohamed Zait.
Cleveland SQL Saturday Catch-All or Sometimes Queries
Data Virtualization Tutorial: Introduction to SQL Script
Stored Procedures – Facts and Myths
Loops BIS1523 – Lecture 10.
Troubleshooting SQL Server When You Cannot Access The Machine
CS 440 Database Management Systems
Tonga Institute of Higher Education IT 141: Information Systems
CSE 153 Design of Operating Systems Winter 19
Tonga Institute of Higher Education IT 141: Information Systems
Presentation transcript:

All About Binds Thomas Kyte

All About Binds It’s

Agenda Performance – Is it just about sharing SQL (or is this really a parsing talk in disguise) Scalability Security Do I always want to bind? What is bind variable peeking? – Is it good or evil in disguise or a bit of both? I’m binding, but it isn’t sharing – what’s up with that? So the developers don't bind is cursor_sharing = force/similar appropriate system wide? What is the real difference between cursor_sharing = force/similar and which should we use under what circumstances?

Performance What is involved in all Parses – The “conventional” parse - syntax – Semantic check What about a hard parse – Optimization (can you spell C.P.U…) – Row Source Generation And then we can finally execute it Soft Parse is lighter weight – But it is called a “shared” pool, not “your” pool – Shared data structures have to be protected Optimization can be avoided Row Source Generation can be avoided Bind01.sql

Performance Wonder if it might affect memory utilization? Strange that count(*) is so low for that first query isn’t it. Unfortunate that sum(sharable_mem) is so high (and remember, it really is 10 times that amount) Bind02.sql

Scalability But it runs fast enough and I’ll buy more memory Does it really? – Run bind03.sql select 11/10000 from dual; 11/

Latch Algorithm Loop for I in loop try to get latch if got latch, return if I = 1 then misses=misses+1 end loop INCREMENT WAIT COUNT sleep Add WAIT TIME End loop;

More multi-user USERS NOBIND_CPU PARSE_MANY_CPU PARSE_ONCE_CPU

Security Google sql injectionsql injection Funny thing happened during my last columnlast column create or replace procedure set_udump (p_udump in varchar2) as begin execute immediate 'alter system set user_dump_dest = '''||p_udump||''' scope=memory'; end; /

Security Google sql injectionsql injection Funny thing happened during my last columnlast column create or replace procedure set_udump (p_udump in varchar2) as begin execute immediate 'alter system set user_dump_dest = '''||p_udump||''' scope=memory'; end; / begin set_udump('C:\ORA4\admin\ora4\udump2'' scope=memory utl_file_dir=''*'' scope=spfile user_dump_dest=''C:\ORA4\admin\ora4\udump2'); end;

Security Google sql injectionsql injection Funny thing happened during my last columnlast column create or replace procedure set_udump (p_udump in varchar2) as begin if ( p_udump NOT LIKE '%=%' ) then execute immediate 'alter system set user_dump_dest = '''||p_udump||''' scope=memory'; else raise_application_error(-20000,'Sorry, but for safety reasons this procedure does not allow "=" in the parameter value'); end if; end;

Do I always want to bind? Always say “Never say Never” Never say “Always” You do not want to – Over Bind – Always Bind – Why….

Do I always want to bind? Over Binding – Compulsive disorder to eradicate all literals in SQL – Brought on by taking good advice to an illogical extreme – Do we need to bind those? – Might it be a bad thing to bind those? Begin for x in ( select object_name from user_objects where object_type in ( ‘TABLE’, ‘INDEX’ )) loop …

Do I always want to bind? Always Binding – Data warehouse – no way. – When you run queries per second, yes. – When you run queries that take seconds, maybe, maybe no. Consider the frequency of the query o5,000 users running reports. Bind o50 users data mining. No Bind oOLTP. Bind oEnd of month report. Maybe No Bind. oCommon Sense, it is all about math

Do I always want to bind? Always Binding – But remember SQL Injection! – That password screen, binds – Typical queries, binds – Only the queries that need the advantage of literals during optimization! And those have to be looked at over and over “user dump dest”, it seemed so simple

Bind Variable Peeking It is good or pure evil in disguise (neither of course) Introduced in 9i Release 1 Makes the first hard parse of: Optimize as if you submitted: What are the assumptions then by the implementer of this feature. Select * from emp where empno = :X; Select * from emp where empno = 1234; bvp01.sql

Bind Variable Peeking Autotrace/Explain plan caveat with binds in general – Autotrace “lies” (explain plan “lies”) Well, not really. They just don’t have the facts – Is that the only time we cannot trust them completely? No, bvp02… bvp02.sql

Bind Variable Peeking What can you do when those assumptions don’t hold true for you in a specific case? – Don’t bind that query, that is a possibility. Do the math … – Don’t use histograms Get the “general plan” Consistent Plan, but typically not the “best” plan for all – Use your domain knowledge Input dates within the last month – use this query, else use that query Codes less than 50 – use this query, else use that query Status values of ‘A’, ‘M’ and ‘N’ …. Else…. – Cursor_sharing = similar – You can disable it – but that is like “don’t use histograms” in a system that uses binds.

I’m binding, but it isn’t sharing Many things can do that – Any environmental variables that affect the optimizer – Or security (this is why PLSQL rules) – Bind Type mismatch – Language – PLSQL compiler switches For example, lets tune with SQL_TRACE=TRUE And Look deeper at “bind mismatches” Desc v$sql_shared_cursor tune.sql Bindmis.sql

Cursor Sharing So the developers don't bind is cursor_sharing = force/similar appropriate system wide? No

Cursor Sharing Negatively Impacts Well Written Applications – They run slower even if plans do not change – We just did bind variable peeking, so we know about Over binding (this is over binding defined) Always binding (this is always binding defined) – Possible plan changes Optimizer has less information, doesn’t have the facts – Behavior Changes Don’t know column widths anymore Don’t know scale/precision anymore cs01.sql

Force/Similar Let’s take a look at – What is the real difference between cursor_sharing Force Similar – Which should we use under what circumstances? (neither! Both represent a bug in the developed code!)

Force/Similar Force is just that – All literals, without any regard to anything, will be replaced with binds – There will be probably one plan generated (all things considered the same! Remember v$sql_shared_cursor) – Consider the bind variable peeking implications Cold start, first query is id=99 Cold start, first query is id=1 Bouncing the database is my tuning tool?

Force/Similar Similar – When replacing the bind with a literal ( reversed purposely ) could change the plan… – Multiple child cursors will be developed – Each can have it’s own unique plan – Optimization will use the “best” plan – Is this better than force? Depends More child cursors Longer code path – But is does solve a little more of the problem. similar.sql

Force/Similar In Short, just say No To setting at the system level, this is an application level bug “workaround until we get it fixed for real” tool

A nswers Q uestions and