multi-row fetch - amazon simple storage servicemullins+mrf+webinar+slid… · single row vs....

50
align © 2012 Mullins Consulting, Inc. Multi-Row Fetch Improving Application Performance By Fetching Multiple Rows Craig S. Mullins Mullins Consulting, Inc. http://www.craigsmullins.com Sponsored by:

Upload: dangque

Post on 25-Mar-2018

233 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•align

•© 2012 Mullins Consulting, Inc.

Multi-Row Fetch

Improving Application Performance

By Fetching Multiple Rows

•Craig S. Mullins•Mullins Consulting, Inc.•http://www.craigsmullins.com

•Sponsored by:

Page 2: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •2

Author

This presentation was prepared by:

Craig S. MullinsPresident & Principal Consultant

Mullins Consulting, Inc.15 Coventry CtSugar Land, TX 77479Tel: 281-494-6153Fax: 281.491.0637 E-mail: [email protected]

This document is protected under the copyright laws of the United States and other countries as an unpublished work. Any use ordisclosure in whole or in part of this information without the express written permission of Mullins Consulting, Inc. is prohibited.

© 2012 Craig S. Mullins, Mullins Consulting, Inc. All rights reserved.

•6th edition available soon

•covering thru DB2 10 for z/OS

Page 3: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •3

Overview

Multi-row FETCH, available in DB2 since Version 8, has the capability to dramatically improve the performance of DB2-based database applications.

This presentation will introduce and define multi-row FETCH, how to use it, and the performance implications of doing so.

The presentation will also touch uponmulti-row UPDATE.

And it will introduce the new

SoftBase Attach Facility MRF Feature

Page 4: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •4

Agenda

What is Multi-row Fetch?

› History and Definition

› Changes to Programming Required

› High-level Guidance

Using Multi-row Fetch

› Host Variable Arrays

› Rowset Positioning Cursors

› Checking the Data

What about Multi-row Insert?

Performance Considerations

› Benchmarks

› Guidance

SoftBase Attach Facility’s MRF Feature

Page 5: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •5

What is Multi-row Fetch?

A multi-row FETCH retrieves multiple rows at one time into column arrays in your application program.

› A single FETCH can return multiple rows

› Contrast with a traditional FETCH, which returns a single row

But perhaps we have gotten ahead of ourselves, so let’s step back and define some basic terms:

› Relational closure› Set-at-a-time processing

› Cursor

Page 6: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •6

Relational Closure

When writing SQL, remember to think in sets. Relational closure states that all operations are performed on a table and result in another table.

› a table is a set of zero or more rows

› a row is a set of one or more columns

Page 7: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •7

Set versus Record Level Processing

Typically, application programming languages operate using record-at-a-time processing

SQL operates using set-at-a-time processing

Page 8: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •8

Using a Cursor

A cursor is a moving placement or pointer that indicates a position.

› In DB2 programs, a cursor can be used to step through the results of a SQL SELECT statement

› Each SELECT statement will return 0, 1, or more rows

› A SELECT statement is opened in a cursor and the programmer can step through the results of the SQL

Page 9: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •9

OK, So Let’s Get Back to Multi-row Fetch

With multi-row Fetch, instead of obtaining data a row at a time to the program, data is obtained in blocks

› That is, multiple rows are obtained into an array in the program

› The program then must navigate through the array and request an additional block of rows when the current block has been processed

› Let’s look at high-level depictions of how a multi-row FETCH differs from a traditional, single row FETCH cursor

IF-THEN-ELSE

Page 10: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •10

•Program

•FETCH

•1 Row

•FETCH

•1 Row

•FETCH

•1 Row

•Start

•DB2 Result Set

•Row 3

•Row 2

•Row 1•Data

•Request

•Data

•Request

•Data

•Request

Typical DB2 Single-Row FETCH

Page 11: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •11

•DB2 Result Set•Program

•FETCH

•10 Rows

•FETCH

•10 Rows

•Start

•Row 21

•Row 20

•Row 19

•Row 18

•Row 17

•Row 16

•Row 15

•Row 14

•Row 13

•Row 12

•Row 11

•Row 10

•Row 9

•Row 8

•Row 7

•Row 6

•Row 5

•Row 4

•Row 3

•Row 2

•Row 1

•Request

•Data

•Request

•Data

Example DB2 Multi-Row FETCH

Page 12: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •12

Single Row vs. Multi-Row FETCH

With Multi-Row FETCH:

› CPU can be greatly reduced because moving data across address spaces is expensive

� With a multi-row FETCH multiple rows are moved with one operation

� With a row-at-a-time FETCH, each FETCH requires an operation

› More coding is required in the application program to enable

� Unless it is a distributed program using Block Fetch

� Block Fetch is a distributed technique for more efficiently blocking fetched rows; when data is blocked, less overhead is required as data is sent over the communication lines

� As of DB2 V8, Block Fetch will automatically use multi-row FETCH

� To ensure that your distributed read only cursors use Block Fetch be sure to code the FOR READ ONLY clause and BIND specifying CURRENTDATA NO.

Page 13: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •13

Performance of Multi-Row FETCH

The performance improvement using multi-row FETCH in general depends on:

› Whether or not the request is distributed

› Number of rows fetched in one FETCH

› Number of columns fetched, data type and size of the columns

� In general, the fewer columns the greater the performance improvement with multi-row FETCH will be

› Complexity of the SELECT processing

� The fixed overhead saved for not having to go between the database engine and the application program has a lower percentage impact for complex SQL that has longer path lengths

Page 14: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •14

Multi-row FETCH

Single Row vs. Multi-Row FETCH

DB2 App.Program DB2DB2DB2DB2

•Multi-row

•FETCHDDF

AddressSpace

•Multi-row

•FETCH

This must be explicitly coded into the program

This is done automatically by DB2

Page 15: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •15

Where Else is Multi-Row FETCH Used?

DDF requests are not the only place where you can automatically benefit from Multi-Row FETCH:

› DSNTEP4� DSNTEP2 with multi-row fetch

� One test resulted in 35% CPU reduction when fetching 10000 rows (with 5 and 20 columns)

› DSNTIAUL� One test resulted in 50% CPU reduction when fetching 10000 rows (with 5 and 20 columns)

› QMF

� You can turn multi-row fetch on / off using DSQSMRFI parameter

Off: DSQSMRFI=NO or MR=NO

On: DSQSMRFI=YES or MR=YES

Page 16: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •16

High Level Guidance

Multi-row FETCH is a good technique for improving the performance of your DB2 application programs that access a lot of data

› Frequently, the advice when moving from one version to another is to learn the new featuresand use them in new programs, but don’t retrofit

� Not with multi-row FETCH

� It is a good idea to review your applicationsto see where multi-row FETCH can improveperformance, and then retrofit it into thoseold programs!!!

Page 17: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •17

The Path to Use Multi-row FETCH

› Rowset Positioning used to ‘navigate’ › Uses arrays in application programs

� FETCH into the array, or;

� INSERT from the array

› Rowset Positioning Cursors› Checking for <<End of Data>>›Managing SQLCODEs

Page 18: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •18

What is a ROWSET?

ROWSET positioning must be specified for the cursor

› A ROWSET is a group of rows for the result set of a query that are returned by a single FETCH statement.

› Your program controls the size of the ROWSET

� …that is, how many rows are returned by each FETCH

› ROWSET size is specified on the FETCH statement

� The maximum rowset size is 32,767

› You can mix single row and multiple row fetches for a multi-fetch cursor

Page 19: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •19

Multi-Row FETCH

With Multi-row FETCH a single FETCH statement can retrieve multiple rows of data from the result table of a query as a rowset.

Must DECLARE the cursor for rowset positioning, for example:

Then you can FETCH multiple rows-at-a-time from the cursor.

•EXEC SQL

• DECLARE C1 CURSOR

• WITH ROWSET POSITIONING

• FOR SELECT * FROM EMP;

Page 20: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •20•Source: IBM

Page 21: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •21

Multi-Row FETCH – Examples (1)

Fetch the first x rows and leave the cursor positioned on that rowset at the completion of the fetch.

Fetch the next 5 rows starting at the current position of the cursor, and cause the cursor to be positioned on that rowset at the completion of the fetch.

•FETCH FIRST ROWSET FROM C1FOR x ROWS INTO ...

FETCH ROWSET FROM C1 FOR 5 ROWS INTO ...

Page 22: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •22

Multi-Row FETCH – Examples (2)

Fetch the previous ROWSET and have the cursor positioned on that rowset.

Fetch 5 rows starting with row 10 regardless of the current position of the cursor, and cause the cursor to be positioned on that rowset at the completion of the fetch.

•FETCH PRIOR ROWSET FROM C1FOR x ROWS INTO ...

FETCH ROWSET STARTING AT ABSOLUTE 10 FROM C1 FOR 5 ROWS INTO ...

Page 23: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •23

ROWSET Size

If FOR n ROWS is NOT specified and the cursor is declared for ROWSET positioning..

› The ROWSET will be the same as the previous ROWSET FETCH if…

� It was the previous FETCH for this cursor…

� Or the previous FETCH was a FETCH BEFORE or FETCH AFTER and the FETCH before that was a ROWSET FETCH.

� Otherwise the ROWSET defaults to 1

Page 24: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •24

Host Variable Arrays

Your program needs to be written to include arrays that will work with multi-row SQL operations.

› A host variable array is an array in which each element of the array contains a value for the same column

› Can only be referenced in multi-row fetch or insert

› In general, arrays may not be arrays of structures

Page 25: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •25

COBOL w/Host Variable Arrays

•01 OUTPUT-VARS.

• 05 LASTNME OCCURS 10 TIMES.

• 49 LASTNME-LGTH PIC S9(4) USAGE COMP.

• 49 LASTNME-DATA PIC X(50).

• 05 EMPNO PIC S9(9) COMP-4 OCCURS 10 TIMES.

•PROCEDURE DIVISION.

•EXEC SQL

• DECLARE C1 CURSOR WITH ROWSET POSITIONING FOR

• SELECT LASTNME, EMPNO

• FROM DSN8810.EMP

•END-EXEC.

•EXEC SQL

• OPEN C1

•END-EXEC.

•EXEC SQL

• FETCH FIRST ROWSET FROM C1 FOR 10 ROWS

• INTO :LASTNME,

• :EMPNO

•END-EXEC.

Page 26: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •26

Positioned UPDATE

The new syntax allows you to specify in the UPDATE statement the following clause to update a specified row in the rowset:

Instead, if you specify the existing WHERE CURRENT OF cursor-name, all the rows in the rowset are updated.

› Update all the rows in the rowset that cursor CSR1 is positioned on.

•UPDATE T1 SET C1 = 5

•WHERE CURRENT OF cursor-name

•FOR ROW row-number OF ROWSET

•UPDATE T1

• SET C1 = 5

•WHERE CURRENT OF CSR1

Page 27: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •27

Positioned DELETE

The new syntax allows you to specify in the DELETE statement the following clause to delete a specified row in the rowset:

DELETE FROM T1

WHERE CURRENT OF cursor-name

FOR ROW row-number OF ROWSET

Instead, if you specify the existing WHERE CURRENT OF cursor-name, all the rows in the rowset are deleted. The following example deletes the fourth row in the rowsetthat cursor CSR1 is positioned on:

DELETE FROM T1

WHERE CURRENT OF CSR1

FOR ROW 4 OF ROWSET

Page 28: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •28

Know Your Cursor Position

After a multi-row FETCH, the cursor is positioned on ALL rows in current ROWSET

•400333

•200

•900

•800

•715

•300

•950

•500

•100

•600

•175

•ACME RENTAL

•MULLINS CONSULTING

•SOFTBASE SYSTEMS

•SUPER BANK

•07-11-2004

•07-19-2004

•07-25-2004

•07-31-2004

•08-01-2004

•08-16-2004

•08-27-2004

•08-28-2004

•09-01-2004

•09-02-2004

•09-04-2004

•09-10-2004

•SPUMCO

•SIGH BASE CORP.BETH-ANN INC.

•DIAL-A-DBA•VAN THE MAN

•DBAZINE.com

•RENT-IT, INC.

•VANDALAY INDUST.

•EXP_DATE CUSTNO CUSTNAME +•FETCH FIRST ROWSET

•FOR 4 ROWS

•FETCH NEXT ROWSET

•FOR 4 ROWS

•FETCH NEXT ROWSET

•FOR 2 ROWS

Page 29: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •29

End of Multi-Row FETCH

If you try to fetch beyond the result set you will receive an end of data condition.

› Consider, for example, that there are only 10 rows left in the result table and you issue the following FETCH request:

FETCH NEXT ROWSET FOR 25 ROWS

› The last 10 rows will be returned along with an SQLCODE +100

› This is also the case when FETCH FIRST n ROWS ONLY has been specified

Page 30: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •30

Performance Considerations

› Benchmarks

› Guidance

Page 31: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •31

Performance Considerations

Testing has shown up to a 50% CPU time reduction when using multi-row FETCH › Due to avoiding the reduction in API calls

› The percentage improvement will be lower the fewer rows fetched per call (also, the more columns fetched, the less the improvement will be)

The “sweet spot” for multi-row FETCH is at about 100 rows. › Performance gains start with 10 rows; if you are going to retrieve less than that it probably does not make a lot of sense to invest the effort to code for multi-row FETCH

› Works great when fetching between 100 and 1000 rows

Page 32: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •32

Remember…

Multi-row FETCH avoids API overhead

› Local applications: fewer database accesses.

› Distributed applications: fewer network operations.

› Bottom line: a significant improvement in performance.

Page 33: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •33

What about Multi-row Insert?

Page 34: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •34

› Three ways to insert data:

� List of Values INSERT … VALUES

� From a SELECT INSERT … SELECT …

� From an array INSERT … FOR x ROWS

› Multi-Row INSERT: a single INSERT statement can add multiple rows of data from an array.

� For static and dynamic SQL (examples upcoming)

� FOR n ROWS

Maximum n is 32,767

Multi-Row INSERT

Page 35: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •35•Source: IBM

Page 36: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •36

ATOMIC versus NON-ATOMIC

ATOMIC versus NON-ATOMIC

› ATOMIC – if any single row insert fails, all fail

› NOT ATOMIC – rows inserted independently

� If errors occur during execution of INSERT, processing continues

� Diagnostics are available for each failed row through GET DIAGNOSTICS

� SQLCODE will indicate if:

all failed,

all were successful, or

at least one failed

Page 37: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •37

Multi-Row INSERT – Examples

Static SQL INSERT with host variable arrays.

Dynamic SQL INSERT with host variable arrays.

•INSERT INTO T FOR :x ROWSVALUES(:hva1, :hva2) ATOMIC

•stmt: ‘INSERT INTO T VALUES(?, ?)’

•attrvar: ‘FOR MULTIPLE ROWS ATOMIC’

•PREPARE my_isrt ATTRIBUTES :attrvar FROM :stmt

•EXECUTE my_isrt FOR :hv ROWS USING (:hva1, :hva2)

Page 38: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •38

Performance Considerations

Testing has shown up to a 40% CPU time reduction when using multi-row INSERT

› Due to avoiding the reduction in API calls

› The percentage improvement will be lower as the number of indexes goes up, number of rows inserted per call goes down, and/or the number of columns goes up

Page 39: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •39

So What Should You Do?

Page 40: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •40

General Advice

› Use Multi-row FETCH to improve application performance in all new development efforts

� Use it whenever 10 or more rows need to be fetched

› Consider retrofitting it into existing application programs

› Look for programs that contain SQL statements from which a lot of data is fetched

› Use Multi-row INSERT for new application development efforts that require significant amounts of data to be inserted

› Not as important to retrofit older programs for multi-row INSERT, but you might want to consider it if you have an application with significant INSERT activity

Page 41: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •41

Use SoftBase Attach Facility!

SoftBase Attach Facility’s MRF Feature

Quickly implement MRF in your existing applications

� SQL statement CPU savings as high as 66%*

� No changes to source code

� Automatically implement MRF

•*Based on observations from internal testing of individual SQL statements. Individual results may vary, and will be based on many factors, including the number of FETCH statements an application initiates.

Page 42: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •42

1

Intercept single-row

FETCH call

3

Pull rows into temporary result set

2

Issue

Multi-Row FETCH call

•DB2 Result Set

•Row 21

•Row 20

•Row 19

•Row 18

•Row 17

•Row 16

•Row 15

•Row 14

•Row 13

•Row 12

•Row 11

•Row 10

•Row 9

•Row 8

•Row 7

•Row 6

•Row 5

•Row 4

•Row 3

•Row 2

•Row 1

•Attach Facility MRF Feature

4

Return rows as they are

called>

FAST!5

After all rows are called, the process

repeats.

•Program

FETCH

1 Row

Start

•Request

•Request

FETCH

1 Row

FETCH

1 Row

SoftBase Attach Faciltiy MRF Feature

Page 43: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •43

Attach Facility’s Multi-Row FETCH Feature

How does it save CPU time?

� Each row can be pulled much faster

� Each FETCH requires only tens of instructions, versus hundreds or thousands when issued to DB2

� Tests have shown FETCH processing performance improvement by as much as 66%*

•*Results may vary

FETCH single row

•Program •MRF Temporary Table

•Row 1

•Row 2

•Row 3

•Row 4

•Row 5

•DB2 Result Set

•Row 5

•Row 4

•Row 3

•Row 2

•Row 1FETCH single row

•Program

•100’s or 1000’s of instructions

•MRF Feature FETCH Processing

•Typical DB2 FETCH Processing

10’s of instructions per fetch

100’s or 1000’s of instructions per fetch

Page 44: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •44

Use Softbase’s Batch Analyzer to quickly identify

applications that can benefit from the MRF feature

How to Identify Where MRF Can Help?

� Download and install SoftBase’s Batch Analyzer free trial

� Run for several days (very low overhead)

� Output identifies applications that will benefit the most from Attach Facility’s MRF feature

Page 45: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •45

How Hard is it to Deploy?

Simple deployment process

1. Download and install SoftBase’s Batch Analyzer free 30-day trial

� Quick and easy download for trial

2. Run Batch Analyzer to collect application data (very low overhead)

� At least 1 full day recommended

3. Using Batch Analyzer’s report, choose the applications that issue a relatively high number of individual FETCH statements

4. Contact SoftBase for instructions to download and install AttachFacility with MRF feature

5. Point to the desired programs’ cursors, and initiate the MRF feature.

6. After several days, run Batch Analyzer again to compare performance.

Page 46: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •46

How Hard is it to Deploy?

Flexible and simple to use

• You can control:

� Which cursors to enable for multi-row FETCH

• Because not every cursor should be multi-row

� The size of the rowset (buffer)

Page 47: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •47

Sample Results Using SoftBase Attach Facility Multi-Row Fetch feature

Page 48: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •48

Multi-row FETCH

You know MRF can help!

• With SoftBase Attach Facility Multi-Row Fetch feature…

• You can implement MRF without requiring application program changes!

Page 49: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •49

© 2011 Candescent SoftBase, LLCSoftBase® is a Registered Trademark. All Right Reserved.Phone: (800) 669-7076 | (828) 670-9900

•Jeff Lovette•Sr. Director of Global Sales and Marketing

•(828) 418-1650

[email protected]

•20 Fall Pippin Lane, Suite 202Asheville, NC USA 28803

Page 50: Multi-Row Fetch - Amazon Simple Storage ServiceMullins+MRF+webinar+slid… · Single Row vs. Multi-Row FETCH DB2 App. Program DB2 •Multi-row •FETCH DDF Address Space •Multi-row

•© 2012 Mullins Consulting, Inc. •50

Contact Information

Craig S. MullinsMullins Consulting, Inc.15 Coventry CourtSugar Land, TX 77479

http://www.craigsmullins.com

•http://www.craigsmullins.com/cm-book.htm

•http://www.craigsmullins.com/dba_book.htm

[email protected]

•Phone: (281) 494-6153

�6th edition coming in May…covering up thru DB2 V10!