Bulk绑定是如何提高性能的。有空再翻译吧。(from oracle)
2006-06-02 16:43
627 查看
How Do Bulk Binds Improve Performance?
The assigning of values to PL/SQL variables in SQL statements is called binding. PL/SQL binding operations fall into three categories:in-bind When a PL/SQL variable or host variable is stored in the database by an
INSERTor
UPDATEstatement.
out-bind When a database value is assigned to a PL/SQL variable or a host variable by the
RETURNINGclause of an
INSERT,
UPDATE, or
DELETEstatement.
define When a database value is assigned to a PL/SQL variable or a host variable by a
SELECTor
FETCHstatement.
A DML statement can transfer all the elements of a collection in a single operation, a process known as bulk binding. If the collection has 20 elements, bulk binding lets you perform the equivalent of 20
SELECT,
INSERT,
UPDATE, or
DELETEstatements using a single operation. This technique improves performance by minimizing the number of context switches between the PL/SQL and SQL engines. With bulk binds, entire collections, not just individual elements, are passed back and forth.
To do bulk binds with
INSERT,
UPDATE, and
DELETEstatements, you enclose the SQL statement within a PL/SQL
FORALLstatement.
To do bulk binds with
SELECTstatements, you include the
BULK
COLLECTclause in the
SELECTstatement instead of using
INTO.
For full details of the syntax and restrictions for these statements, see "FORALL Statement" and "SELECT INTO Statement".
Example: Performing a Bulk Bind with DELETE
The followingDELETEstatement is sent to the SQL engine just once, even though it performs three
DELETEoperations:
DECLARE TYPE NumList IS VARRAY(20) OF NUMBER; depts NumList := NumList(10, 30, 70); -- department numbers BEGIN FORALL i IN depts.FIRST..depts.LAST DELETE FROM emp WHERE deptno = depts(i); END;
Example: Performing a Bulk Bind with INSERT
In the example below, 5000 part numbers and names are loaded into index-by tables. All table elements are inserted into a database table twice: first using aFORloop, then using a
FORALLstatement. The
FORALLversion is much faster.
SQL> SET SERVEROUTPUT ON SQL> CREATE TABLE parts (pnum NUMBER(4), pname CHAR(15)); Table created. SQL> GET test.sql 1 DECLARE 2 TYPE NumTab IS TABLE OF NUMBER(4) INDEX BY BINARY_INTEGER; 3 TYPE NameTab IS TABLE OF CHAR(15) INDEX BY BINARY_INTEGER; 4 pnums NumTab; 5 pnames NameTab; 6 t1 NUMBER(5); 7 t2 NUMBER(5); 8 t3 NUMBER(5); 9 10 11 BEGIN 12 FOR j IN 1..5000 LOOP -- load index-by tables 13 pnums(j) := j; 14 pnames(j) := 'Part No. ' || TO_CHAR(j); 15 END LOOP; 16 t1 := dbms_utility.get_time; 17 FOR i IN 1..5000 LOOP -- use FOR loop 18 INSERT INTO parts VALUES (pnums(i), pnames(i)); 19 END LOOP; 20 t2 := dbms_utility.get_time; 21 FORALL i IN 1..5000 -- use FORALL statement 22 INSERT INTO parts VALUES (pnums(i), pnames(i)); 23 get_time(t3); 24 dbms_output.put_line('Execution Time (secs)'); 25 dbms_output.put_line('---------------------'); 26 dbms_output.put_line('FOR loop: ' || TO_CHAR(t2 - t1)); 27 dbms_output.put_line('FORALL: ' || TO_CHAR(t3 - t2)); 28* END; SQL> / Execution Time (secs) --------------------- FOR loop: 32 FORALL: 3 PL/SQL procedure successfully completed.
相关文章推荐
- 如何提高性能SELECT TOP n * FROM [tablename] ORDER BY NEWID()
- oracle性能提高---批量绑定
- oracle 大容量表多表关联,如何提高性能?
- [翻译文章]我们是如何做到的: 提高SharePoint.Microsoft.com站点的性能
- oracle性能提高---批量绑定
- Oracle如何实现利用实体化视图提高查询性能
- PHP如何提高性能(分析)
- 如何最大限度提高.NET的性能
- 如何优化JAVA程序设计和编码,提高JAVA性能
- 如何使用Rust提高Ruby性能
- Java 编程:如何提高性能?(简单总结篇)
- 如何提高网页运行性能
- 如何清除临时文件,释放空间,提高计算机性能
- 如何提高网页运行性能
- 如何诊断Oracle Redo Log引发的性能问题
- oracle 性能优化操作七:索引提高数据分布不均匀时查询效率
- JavaScript知识点总结之如何提高性能
- oracle 使用绑定变量极大的提升性能
- 减少oracle sql回表次数 提高SQL查询性能
- CSS性能分析,如何优化CSS提高性能