New Features Guide To Sybase Ase 15
New Features Guide To Sybase Ase 15
Larry Ellison
CEO, Oracle Inc.
This page intentionally left blank.
Several years later…
Taylor, Brian.
The official new features guide to Sybase ASE 15 / by Brian Taylor ... [et al.].
p. cm.
Includes index.
ISBN-13: 978-1-59822-004-9
ISBN-10: 1-59822-004-7 (pbk.)
1. Client/server computing. 2. Sybase. I. Taylor, Brian (Brian Robert), 1972- .
QA76.9.C55O4 2006
005.2'768--dc22 2005036445
ISBN-13: 978-1-59822-004-9
ISBN-10: 1-59822-004-7
10 9 8 7 6 5 4 3 2 1
0602
Sybase, Adaptive Server, and the Sybase Fibonacci symbol are registered trademarks of Sybase, Inc. in the
United States of America and/or other countries. Other brand names and product names mentioned in this book
are trademarks or service marks of their respective companies. Any omission or misuse (of any kind) of service
marks or trademarks should not be regarded as intent to infringe on the property of others. The publisher
recognizes and respects all marks used by companies, manufacturers, and developers as a means to distinguish
their products.
This book is sold as is, without warranty of any kind, either express or implied, respecting the contents of this
book and any disks or programs that may accompany it, including but not limited to implied warranties for the
book’s quality, performance, merchantability, or fitness for any particular purpose. Neither Wordware
Publishing, Inc. nor its dealers or distributors shall be liable to the purchaser or any other person or entity with
respect to any liability, loss, or damage caused or alleged to have been caused directly or indirectly by this book.
Portions of this book contain charts, graphs, tables, and other materials that are copyrighted by Sybase, Inc., and
are used with permission.
All inquiries for volume purchases of this book should be addressed to Wordware Publishing, Inc.,
at the above address. Telephone inquiries may be made by calling:
(972) 423-0090
SYBASE, INC., AND ITS SUBSIDIARIES DO NOT TAKE ANY
RESPONSIBILITY FOR THE CONTENT OF THE BOOK.
SYBASE DISCLAIMS ANY LIABILITY FOR INACCURACIES,
MISINFORMATION, OR ANY CONTENT CONTAINED IN, OR
LEFT OUT OF THIS BOOK.
This page intentionally left blank.
Dedications
vii
This page intentionally left blank.
Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii
ix
Contents
x
Contents
Partitioning Strategies. . . . . . . . . . . . . . . . . . . . . . . . . 83
Inserting, Updating, and Deleting Data in Partitions . . . . . . . . . 84
Inserting Data into Semantic Partitions . . . . . . . . . . . . . 84
Inserting Data into Range Partitions . . . . . . . . . . . . . . . 84
Inserting Data into Hash Partitions. . . . . . . . . . . . . . . . 86
Inserting Data into List Partitions . . . . . . . . . . . . . . . . 86
Deleting Data from All Semantic Partitions . . . . . . . . . . . 86
Updating Data in All Semantic Partitions . . . . . . . . . . . . 86
Built-in Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Data Partition Implementation and Upgrade Strategies . . . . . . . 89
Index Partitioning . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Local Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Clustered Prefixed Index on Range Partitioned Table . . . 95
Clustered Non-Prefixed Index on Range
Partitioned Table . . . . . . . . . . . . . . . . . . . . . 97
Clustered Prefixed Index on List Partitioned Table . . . . . 99
Clustered Non-Prefixed Index on List
Partitioned Table . . . . . . . . . . . . . . . . . . . . 101
Clustered Prefixed Index on Round-robin
Partitioned Table . . . . . . . . . . . . . . . . . . . . 104
Clustered Non-Prefixed Index on Round-robin
Partitioned Table . . . . . . . . . . . . . . . . . . . . 106
Clustered Non-Prefixed Index on Hash
Partitioned Table . . . . . . . . . . . . . . . . . . . . 108
Clustered Prefixed Index on Hash Partitioned Table . . . 110
Global Index . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Global Nonclustered Prefixed Index on Range
Partitioned Table . . . . . . . . . . . . . . . . . . . . 114
Global Nonclustered Prefixed Index on List
Partitioned Table . . . . . . . . . . . . . . . . . . . . 116
Global Nonclustered Prefixed Index on
Round-robin Partitioned Table . . . . . . . . . . . . . 118
Global Nonclustered Prefixed Index on Hash
Partitioned Table . . . . . . . . . . . . . . . . . . . . 120
Query Processor and Partition Support . . . . . . . . . . . . . . . 122
ASE 15 Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Partition Maintenance . . . . . . . . . . . . . . . . . . . . . . . . 124
Altering Data Partitions. . . . . . . . . . . . . . . . . . . . . 124
Unpartition a Table. . . . . . . . . . . . . . . . . . . . . 125
Change the Number of Partitions . . . . . . . . . . . . . 126
Add a Partition to a Table . . . . . . . . . . . . . . . . . 126
Drop Partitions . . . . . . . . . . . . . . . . . . . . . . . 130
Modifications to the Partition Key . . . . . . . . . . . . . 131
Partition Information . . . . . . . . . . . . . . . . . . . . . . . . 134
xi
Contents
xii
Contents
or Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Star Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
xiii
Contents
xiv
Contents
xv
Contents
xvi
Contents
xvii
Contents
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
xviii
Foreword
Sybase Adaptive Server Enterprise (ASE) has been a leading
RDBMS for mission-critical applications for almost two decades.
With ASE 15, Sybase has continued the tradition of introducing
leading edge database technologies to address our customers’ needs.
These technologies cover security, unstructured data management,
and operational intelligence. ASE 15 provides significant improve-
ments for DSS and OLTP applications thanks to innovative query
processing technology. The result is a clear understanding of the opti-
mal usage of the features and functionality.
The Official New Features Guide to Sybase ASE 15 is the first
book describing ASE 15. Of particular interest are details about new
features such as semantic partitions, computed columns, function
indexes, and scrollable cursors. The book is valuable also for its guid-
ance for diagnosing, resolving, and optimizing the overall system
performance.
The authors collectively have more than 40 years of experience
with Sybase ASE as DBAs at some of Sybase’s largest and most
demanding customers. Their background has enabled them to create
a book with great practical value.
The authors’ material is presented in a way that is useful to read-
ers independent of their experience level with ASE. The Official New
Features Guide to Sybase ASE 15 will be an invaluable asset to
DBAs, developers, and consultants working with Sybase ASE.
xix
This page intentionally left blank.
Acknowledgments
The authors would like to thank Celeste Noren for starting this whole
process. Your continual support and upbeat attitude have allowed us
to stay focused on the job at hand. We thank Joe Pearl for his tireless
and thorough editing and brilliant input. Special thanks to Irfan Khan
at Sybase Engineering for providing us with early access to the new
features and documentation for ASE 15. We need to thank
Rob Verschoor, Mark Kusma, and Jeff Tallman of Sybase for their
thorough technical reviews and timely feedback. We thank Joan
Fronske and Tom Traubitz from Sybase Marketing for making all
the arrangements with Sybase. We would like to thank Tim McEvoy
at Wordware Publishing for getting this book put together in such a
timely manner. A special thanks goes to Dean Kent for his legal
counsel during the process and for all the good lunches. Mostly,
we would like to thank our families for being understanding and
gracious.
xxi
Acknowledgments
xxii
Acknowledgments
First, I would like to thank Brian for taking on this initiative and con-
sidering me to be an author in developing this work. Second, I would
like to thank the other authors for the time and patience that each of
you have shown during this process. As difficult as it is for one per-
son to produce such a work, four people can make it even more
strenuous. Thank you, guys, for keeping the process lighthearted and
fun. It was a pleasure working with you. I would like to thank my
parents, Charlie and Betty, for instilling in me the desire and pride to
do the best I can in whatever I attempt. And most importantly, I
would like to thank my best friend for all of her support during this
time — my wife and my love, Carol.
— SWB
xxiii
This page intentionally left blank.
About the Authors
Brian Taylor is a Sybase Certified Professional DBA
with over 11 years of experience in the Information Tech-
nology (IT) industry. Brian has been a presenter at the
Sybase TechWave conference. He has also presented an
ASE 15 case study through a live web seminar, as well as
delivered web seminars based on his beta testing efforts
with ASE 15. He is a contributing author to Wordware’s
Administrator’s Guide to Sybase ASE 12.5. Brian has a
BS in management information systems and finance from
Florida State University and is currently pursuing his
MBA from Florida State University.
xxv
About the Authors
xxvi
Introduction
We’ve read the newsgroups. We’ve seen the blogs. We know you’re
out there. The talented Sybase database administrators, developers,
managers, and users are out there. This book is for you.
We will attempt to guide you, the reader, through the enhance-
ments of ASE 15. In addition to the enhancements, we will also
discuss how these enhancements can be applied to a “real-life” situa-
tion. We have polled many fellow database administrators about their
thoughts on Sybase ASE regarding the new features. We have tried to
incorporate as many of these ideas as possible.
Audience
The audience for this book is wider than just database administrators.
This book can be used by managers to foresee possible project direc-
tion for more than just the next release of a product or application. It
can assist the system architect in determining the best solution for
enterprise applications. It can be used to educate the developer about
features that are now available that will make the development pro-
cess easier and more manageable. But most importantly, this book is
for the database administrator. This book will guide you through the
practical use of the new features in Sybase ASE 15.
Scope
This book is an overview of the new features available in ASE 15.
We also touch on some existing features that were implemented since
the last series of administration guides was released. These preexist-
ing features were deemed worthy of reference based on the overall
ASE road map for future releases and the direction of Sybase toward
a flexible product geared toward service-oriented architecture (SOA).
We will demonstrate and clarify the new features and how they inte-
grate into existing systems.
xxvii
Introduction
Conventions
This book follows certain typographic conventions, as outlined
below:
xxviii
Introduction
Disclaimer
Some of this material is based upon a prereleased version of ASE 15.
Some of the details, syntax, and output of some of the commands and
procedures may differ slightly from the General Availability (GA)
release of ASE 15.
While the authors have attempted to ensure the screen shots,
syntax, and output reflect the GA release of ASE 15, it is possible the
book may contain some information from the prereleased version of
ASE 15, which may or may not be materially different from the GA
release of ASE 15.
xxix
This page intentionally left blank.
Part I
1
This page intentionally left blank.
Chapter 1: Exploring the Sybase Galaxy | 3
Chapter 1
Scrollable Cursors
Scrollable cursors are in line with Sybase’s goal to increasingly lower
the TCO of Sybase ASE. Scrollable cursors can also ease or speed
the development process by replacing supplemental middleware or
client tools used to manipulate a cached result set.
Chapter 4 describes how to create a scrollable cursor, explains
how to manipulate a scrollable cursor, and discusses the global vari-
ables associated with a scrollable cursor.
6 | Chapter 1: Exploring the Sybase Galaxy
Computed Columns
In accordance with the Sybase road map to provide operational excel-
lence within the database, ASE 15 introduces computed columns.
The implementation of computed columns affords the database
administrator the opportunity to ease development costs and provide
a foundation to offer increased data velocity.
The utilization of computed columns can reduce TCO by simpli-
fying the application development effort. The simplification is
accomplished by the placement of the computational burden on the
server as opposed to within the client layer. This enhancement is
especially applicable to the handling of unstructured data, such as
XML documents.
Chapter 7 provides the technical details on the implementation of
computed columns. The chapter outlines the syntax to implement
computed columns and includes several examples. Materialization
and the deterministic properties of computed columns are also
explained.
Functional Indexes
Sybase offers computed column indexes and function-based indexes
to maximize the scalability and performance capabilities of Sybase
ASE. These new index types allow Sybase ASE to maintain indexes
based on derived data. This enhancement further emphasizes the data
velocity initiatives incorporated into the release of ASE 15.
8 | Chapter 1: Exploring the Sybase Galaxy
Plan Viewer
The introduction of the Plan Viewer in ASE 15 is aligned with
Sybase’s goal to ease the overall management needs of ASE. The
Plan Viewer is a graphical user interface (GUI) utility wrapped in the
interactive ISQL tool included with the ASE 15 open client product.
This new feature provides database administrators and developers a
tool to help visualize query plans for the purpose of quick and easy
identification of performance issues.
Chapter 10 provides instructions on how to set up and launch the
Plan Viewer. The chapter continues with a demonstration on how to
extract useful information from the Plan Viewer, and discusses the
information and concepts contained in the Plan Viewer’s output.
Installation of ASE 15
The focus in Chapter 12 is the installation of ASE 15. This chapter
provides an overview of the server installation process, using three
distinctly different installation methods. With each method, server
installation is covered in an easy-to-follow step-by-step manner.
10 | Chapter 1: Exploring the Sybase Galaxy
MDA Tables
MDA tables are another ASE feature first available in release
12.5.0.3. While there are a few known publications on this feature,
we decided to incorporate the MDA tables into this 15 book to pro-
vide another resource on MDA table application.
In Chapter 14, the new MDA table and column additions are
identified. The chapter also walks through the basics of MDA table
setup, identifies the information collected by the MDA tables, sug-
gests how to manage the “statefulness” of MDA tables, and discusses
the impact of changing some of the MDA table’s configuration
parameters.
The MDA tables are another ASE feature in line with the Sybase
goal to increasingly lower the TCO of Sybase ASE. The MDA tables
Chapter 1: Exploring the Sybase Galaxy | 11
The Appendices
Use Cases
All ASE 15 material covered in this book is put to practical use
through the business cases presented in Appendix B. Through practi-
cal examples, the use cases demonstrate how Sybase ASE 15 can
assist businesses with lowering TCO. Additionally, the examples
highlight the many advantages provided by the ASE 15 “Galaxy”
features.
12 | Chapter 1: Exploring the Sybase Galaxy
3, 2, 1, Contact!
It is a new and exciting time in the universe of database technology.
The use of the database will broaden to handle the new challenges of
not only data management, but information management. The future
of information management is here today. So sit back, buckle up, and
enjoy the ride as we explore the outer reaches of the “Galaxy” release
known as Sybase ASE 15.
Chapter 2: System Maintenance Improvements | 13
Chapter 2
System Maintenance
Improvements
Multiple tempdb
The multiple tempdb capability was introduced in ASE 12.5.0.3.
This feature allows the database administrator to create special
“user-defined” temporary databases and to distribute tempdb activity
across multiple temporary databases. The enhancement helps to elim-
inate a long-standing point of contention within the ASE architecture.
Constructed properly, the multiple tempdb feature can allow for a
“back door” into ASE in the event of a full system tempdb. A prudent
database administrator can create a privileged login bound to a
user-defined tempdb. From this user-defined tempdb, the privileged
user can perform maintenance on the system tempdb in the event the
system tempdb experiences a log full problem. The setup of this
“back door” is relatively simple, and can save the database adminis-
trator from an unplanned recycle of ASE.
For further information on the implementation of multiple
tempdb in ASE, please see Chapter 13, as well as the Sybase Adap-
tive Server System Administration Guide.
dbcc traceon(3604)
go
dbcc page (5,1282,1) -- specify 1 as the third option to dump the
contents of the page.
go
t Encrypted data, as opposed to plain text, is stored in the transac-
tion log. This can be verified with the dbcc log command:
dbcc log (dbid, objid, pageno, rowno, nrecs, type, printopt)
dbcc traceon(3604)
go
dbcc log (6, 553769030)
go
t No external programming logic is necessary to decrypt encrypted
data.
The Basics
The sp_dbextend system procedure is the tool used to set up and
maintain automatic database expansion. The procedure can be used to
provide a listing of the syntax options, which are included here for
reference:
sp_dbextend "help"
go
the disk allocations. Finally, for users of the dbcc checkstorage con-
sistency checker, alteration of the dbccdb configuration may be
necessary for databases where automatic expansion has occurred.
Job Scheduler
As a precursor to some of the automatic administration tasks, Job
Scheduler was introduced in ASE 12.5.1. In introducing this feature,
Sybase took the first steps toward offering automatic administration
from within a Sybase product.
Job Scheduler allows an administrator to create and schedule
jobs, as well as share jobs and schedules. This means one database
administrator can create a job and other database administrators can
then schedule and run that job on another server. Job Scheduler jobs
can be created from scratch using the command line or GUI, or from
a SQL batch file. Jobs can also be created from a predefined
template.
Job Scheduler can also be used as a tool for messaging. It cap-
tures the results and output of jobs and records that information in log
tables. This data can then be queried and used for creating meaning-
ful messages. In addition, Job Scheduler keeps a history of scheduled
jobs. Job Scheduler is self-monitoring and removes outdated, unnec-
essary history records. By doing this, a limit can be kept on the size
of the history table. In addition, many of the new features in ASE 15
have been integrated with Job Scheduler.
Basic Components
Job Scheduler has two main functional components: the Job Sched-
uler Task (JS Task) and the Job Scheduler Agent (JS Agent). The JS
Task manages the schedules and notifies the JS Agent to execute a
job. The JS Agent then carries out job execution.
ASE 15 Improvements
Tip: Multiple tempdbs are still a good idea to relieve log and cache
contention.
Update Statistics
The update statistics command for ASE 15 is enhanced twofold.
First, the statistics can be updated at the partition level in ASE 15.
Additionally, Sybase introduces the datachange function, which
allows the database administrator to measure the amount of change to
the data underlying the collected statistics at the table, index, column,
and partition level. Based on the values returned by the datachange
function, database administrators can make update statistics opera-
tions optional, as the datachange function provides a basis to
measure the amount of changed data at a specified level. Let’s begin
by exploring the enhanced syntax for update statistics in ASE 15.
Syntax:
update statistics table_name [[partition data_partition_name]
[(column_list)] | index_name [partition index_partition_name]]
[using step values] [with consumers = consumers]
Datachange
The datachange function is the key to identifying whether update
statistics operations on a table, index, partition, or column is neces-
sary. The datachange function returns a percentage value to indicate
how much the data has changed within a table, partition, index, or
column. A value of 0% indicates no changes to the object are mea-
sured by the datachange function. As the data changes, the value
returned will increase.
Syntax:
select datachange(object_name, partition_name, column_name)
Chapter 2: System Maintenance Improvements | 23
Examples:
Measure the data changed at the table level:
select datachange("authors", null, null)
identification rowcount
Carrie Taylor 40000
Steve Bradley 30000
Naresh Adurty 20000
Jagan Reddy 10000
Brian Taylor 10000
24 | Chapter 2: System Maintenance Improvements
Output:
0.0
update authors
set identification = "Testing"
where identification = "Steve Bradley"
Output:
127.272727
Note that 63% of the data changed based on the contents of the table;
however, the datachange function is reporting that 127% of the data
in the identification column has changed. Since this operation was an
update, the data changes are counted twice, therefore the datachange
value is computed by ASE as follows:
70,000 updates = 70,000 inserts + 70,000 deletes
= 140,000 datachange counts
= 140,000 datachange counts/110,000 rows in table
= 1.272727, or 127.27%
Chapter 2: System Maintenance Improvements | 25
Now let’s consider how the datachange value is calculated for deletes
using the same table data described above.
Output:
0.0
Step 3: Delete 30,000 rows from the authors table, reducing the
rowcount from 110,000 to 80,000:
delete authors
where identification = "Steve Bradley"
go
Output:
37.5
Output:
0.0
Step 3: Insert 30,000 rows into the authors table, increasing the
rowcount from 110,000 to 140,000.
Step 4: Run the datachange function against the identification col-
umn of the authors table:
select datachange("authors", null, "identification")
go
Output:
21.428571
Chapter 2: System Maintenance Improvements | 27
Tip: Two conclusions can be drawn from this example. First, the
datachange function evaluates the percentage of data changed based
upon the current rowcount of the table. Second, deletes have a greater
impact than inserts on the datachange calculation as demonstrated in
this example.
Tip: Use the datachange function prior to the launch of any update sta-
tistics command to determine whether the update statistics command is
necessary. Use of the datachange function provides an opportunity for
the database administrator to minimize or eliminate one of the tradition-
ally largest maintenance windows for Sybase ASE databases.
Output:
datachange: 1.4% for identification column of authors table, update stats
skipped.
Tip: Very often, only a portion of the data within various tables in an
ASE database changes. Traditionally, update statistics could only target
the table as a whole to match statistics to the actual table data. With ASE
15’s semantic partitions and the datachange function, database adminis-
trators should take advantage of the ability to focus update statistics
operations on only those portions of tables, indexes, or columns where
data has changed.
Chapter 2: System Maintenance Improvements | 31
Local Indexes
With local indexes, database administrators can create indexes that
are local to specific partitions of a table. Local indexes can be clus-
tered or nonclustered. Additionally, local indexes can be on the
classic round-robin style partition as well as on semantic partitions.
Further, it is possible to mix partitioned (local) and unpartitioned
(global) indexes on partitioned tables. As a rule, an unpartitioned
table can have only unpartitioned indexes, so this topic is only rele-
vant to partitioned tables in ASE 15 where the number of partitions is
greater than one.
This chapter focuses on the basics of local indexes. More
detailed information on local indexes can be found in Chapter 3.
Benefits
The main benefit of local indexes is the ability to perform partition-
specific maintenance at the local index level. With local indexes, it is
possible to localize reorg, dbcc, and update statistics operations to a
specific partition. This aspect of local indexes allows for maintenance
to either be minimized or spread across multiple smaller maintenance
windows as opposed to one large index maintenance window.
Syntax:
The additional syntax for create index in ASE 15 adds the following
clause to the end of the create index statement:
index_partition_clause:
[local index] [partition_name [on segment_name]
[,partition_name [on segment_name] ...]]
Examples:
Create local, nonclustered index on the authors table, on the named
partitions of batch1, batch2, batch3, and batch4:
create nonclustered index authors_idx4
on authors(effectiveDate) local index batch1,batch2,batch3,batch4
Create local, nonclustered index on the authors table and accept the
system-generated index partition names:
create nonclustered index authors_idx2
on authors(identification) local index
32 | Chapter 2: System Maintenance Improvements
Create local clustered index on the authors table and accept the sys-
tem-generated index partition names:
create clustered index authors_clustered_idx
on authors(identification) local index
sp_helpindex
The sp_helpindex system procedure in ASE 15 will indicate which
indexes are global and which are local for a table. The output will
also indicate the index partition names, which can be useful as some
of the partition-specific dbcc operations, such as dbcc indexalloc and
dbcc checkindex, require the index partition ID as an input parame-
ter. From the output of sp_helpindex, we know the authors table has
three indexes. Of these three indexes, two are local indexes. The local
index partition IDs are displayed as the last portion of output from
this system procedure.
Example:
sp_helpindex authors
go
Output:
index_name index_keys index_description index_max_rows_per_page
index_fillfactor index_reservepagegap index_created
index_local
authors_nc1 identification nonclustered 0 0 0
9/30/2005 10:34:10.353 PM Global Index
Chapter 2: System Maintenance Improvements | 33
index_ptn_name index_ptn_seg
authors_nc1_649769372 default
authors_idx2_681769486 default
authors_idx2_697769543 default
authors_idx2_713769600 default
authors_idx2_729769657 default
authors_idx3_761769771 default
authors_idx3_777769828 default
authors_idx3_793769885 default
authors_idx3_809769942 default
(return status = 0)
Partition-level Utilities
Partition-level utilities allow the database administrator to periodi-
cally perform maintenance tasks at the partition, or sub-object, level.
Maintenance can be directed toward a single partition or cycle
through all partitions in a partitioned table. Partition maintenance has
also been integrated with the Job Scheduler. Semantic partitioning
can improve performance and help manage data as discussed in this
section. In particular, semantic partitions can help manage large
tables and indexes by dividing them into smaller, more manageable
pieces. Additionally, semantic partitions are the building blocks for
parallel processing, which can significantly improve performance.
In this section, the partition-level utilities and configuration
parameters are discussed in the following order:
t Partition configuration parameters
t Utility benefits from semantic partitions
t Partition-specific database consistency checks (dbccs)
t Reorg partitions
t Changes to the bcp utility
t Truncate partitions
34 | Chapter 2: System Maintenance Improvements
Example:
dbcc checktable(authors, null, batch1)
Output:
Checking partition 'batch1' (partition ID 569769087) of table 'authors'.
The logical page size of this table is 2048 bytes.
The total number of data pages in partition 'batch1' (partition ID
569769087) is 981.
Partition 'batch1' (partition ID 569769087) has 55000 data rows.
DBCC execution completed. If DBCC printed error messages, contact a user
with System Administrator (SA) role.
Output:
Checking partition 'batch1' (partition ID 841770056) of table 'authors'.
The logical page size of this table is 2048 bytes.
Table has 55000 data rows.
Index has 55000 leaf rids.
The total number of data pages in this table is 1002.
DBCC execution completed. If DBCC printed error messages, contact a user
with System Administrator (SA) role.
Example:
-- checkindex executed on system named index partition:
dbcc checkindex(authors, 3, null, authors_idx2_729769657)
Output:
Checking partition 'authors_idx2_729769657' (partition ID 729769657) of
table 'authors'. The logical page size of this table is 2048 bytes.
DBCC execution completed. If DBCC printed error messages, contact a user
with System Administrator (SA) role.
Chapter 2: System Maintenance Improvements | 37
Example:
dbcc indexalloc(713769600, 3, full, fix)
Output:
***************************************************************
TABLE: authors OBJID = 553769030
PARTITION ID=713769600 FIRST=610281 ROOT=610280 SORT=0
Indid : 3, partition : 713769600. 47 Index pages allocated and 7 Extents
allocated.
TOTAL # of extents = 7
Alloc page 610048 (# of extent=2 used pages=9 ref pages=9)
Alloc page 610304 (# of extent=5 used pages=39 ref pages=39)
Total (# of extent=7 used pages=48 ref pages=48) in this database
DBCC execution completed. If DBCC printed error messages, contact a user
with System Administrator (SA) role.
Example:
dbcc tablealloc(569769087, full, fix)
Output:
***************************************************************
TABLE: authors OBJID = 553769030
PARTITION ID=569769087 FIRST=16642 ROOT=75755 SORT=0
Data level: indid 0, partition 569769087. 1002 Data pages allocated and 126
Extents allocated.
38 | Chapter 2: System Maintenance Improvements
Reorg Partitions
ASE 15 enables the reclaim_space, forwarded_rows, and compact
parameters of the reorg command to run on a single partition. The
reorg rebuild command can also be run against single index
partitions.
Benefits of Reorg Partitions
Traditionally, reorg operations on the largest of tables is a very time-
consuming operation for ASE servers. Additionally, reorg operations
have only been permitted to operate at the table or index level. Reorg
at the partition level is a new feature for ASE 15.
Using reorg at the partition level provides the database adminis-
trator a mechanism to divide the reorg tasks for very large tables to
multiple maintenance windows. Additionally, if the database admin-
istrator knows only a subset of the table or index’s partitions are
fragmented, reorg operations can be directed to only those partitions
where reorgs are necessary.
Syntax:
reorg forwarded_rows table_name partition partition_name [with {resume,
time = no_of_minutes}]
Note: For ASE 15 GA, reorg rebuild works at the table level, even when
passed a partition name as an input parameter. The ability to perform
reorg rebuild at the partition level may be available in a future IR release
of ASE 15.
Examples:
Run reorg rebuild on the rental_idx local index of the Rental table.
The rental_idx2 local index resides on the rental_idx2_681769486
system-named index partition:
reorg rebuild Rental rental_idx2 partition rental_idx2_681769486
Run reorg compact on the portion of the Rental table specific to the
range partition range_part2:
reorg compact Rental partition range_part2
where:
t slice_num — A number designating the partition from which you
are bulk copying data. This number ranges from 1 to the total
number of partitions in the table. For example, if the table has 15
partitions, the range for slice_num would be from 1 to 15.
slice_num is only valid for bcp in round-robin partitioned tables.
t partition pname — Specifies a comma-delimited set of one or
more unique partitions. This parameter can be used for both bcp
out and bcp in. This parameter cannot be used in conjunction
with the slice_num option.
Chapter 2: System Maintenance Improvements | 41
Copies the contents of partitions p2, p3, and p4 to the rentals.dat file:
bcp Properties..Rental partition p2, p3, p4 out rentals.dat
Usage
t For bcp out, if you specify both the partition pname clause and
filename clause, either:
• The filename parameter contains a single datafile and all data
will be copied to that file, or
• There is a one-to-one mapping between the partition names
and the datafiles, and the data from a partition will be copied
to its specific datafile.
t If a specified partition does not exist, the bcp out command fails
and does not copy out any of the partitions.
t You cannot use partition_id with bcp out.
t For bcp out, if you do not specify a file name, each partition’s
data is copied to a file that is named after the partition and
appended with a .dat extension.
t For bcp in, if you do not specify any partitions, you can list
multiple data files. If you specify partitions, you must include a
one-to-one mapping between the partition names and the
datafiles.
When you bcp data into a table, the input file can contain data for one
or more partitions. Clients can send data across parallel connections,
and each connection is a dedicated channel for a set of one or more
partitions.
If the bcp client has partition-level information to map files to
partitions, bcp can initiate dedicated connections for each partition
into which data is being copied.
bcp: Client-side Parallelism
The bcp client determines the number of connections to the server.
For maximum parallelism, this includes a separate connection for
each partition to the file mapping provided as parameters to the bcp
command.
The maxconn value indicates the maximum number of connec-
tions the bcp client is allowed to set up. Without this parameter, the
Chapter 2: System Maintenance Improvements | 43
Truncate Partitions
With ASE 15, truncate table has been enhanced to deallocate the data
from ASE 15 partitions. Truncate partitions can be performed on the
default round-robin style partition in addition to tables semantically
partitioned.
As with truncations at the table level, pages are deallocated with
truncate, but only at the partition level. Similar to truncate table,
using the partition argument does not log the deletes one row at a
time, and is much faster than a delete with a where clause to delete
data from a single partition.
Note: Truncate table at the partition level can only truncate one partition
at a time.
Truncate syntax:
truncate table authors partition authors_1449772222
After truncate:
partition_name partition_id pages
p1 1433772165 131
44 | Chapter 2: System Maintenance Improvements
p2 1449772222 1
p3 1465772279 132
p4 1481772336 130
Note that after a truncate partition of the hash partitioned table, the
database administrator will need to consider partition rebalancing.
Looking Forward — Drop Partition
Note: Since drop partition is not available in the GA release of ASE 15,
use truncate partition where drop partition would otherwise be used.
Disk Init
In order to allocate disk devices to ASE, the disk init command is
utilized. With ASE 15, the disk init command no longer requires the
vdevno parameter in order to create an ASE device, making the man-
agement of ASE simpler. However, the disk init command will still
accept the vdevno parameter provided the following conditions are
met:
t The vdevno number specified is not already used
t The vdevno number is within the range of allowed values (0 to
2,147,483,647)
t Upper limit specified by the configuration parameter number of
devices has not been obtained
t The vdevno specified cannot be 0 as this is reserved for the mas-
ter device
If vdevno is not passed as an input parameter to the disk init com-
mand, ASE will select a vdevno for the device that is higher than the
highest vdevno held in ASE. So, if the active vdevno numbers uti-
lized are as follows: 0, 1, 2, 3, 4, 12, 34, 56, 57, 58, 75, then ASE will
assign a vdevno for the next device created, where vdevno is not
specified as an input parameter, to be 76 or greater for this example.
Large Identifiers
There are new limits for the length of object names and identifiers:
255 bytes for regular identifiers and 253 bytes for the delimited iden-
tifiers. The new large identifier applies to most user-defined
identifiers including table name, column name, index name, and so
on. Due to the expanded limits, some system catalogs and built-in
functions have been expanded.
46 | Chapter 2: System Maintenance Improvements
For the #temporary table, the large identifier can have a maxi-
mum of 238 bytes since the suffix for the temporary table is 17 bytes.
For variables, the “@” is counted as 1 byte and the allowed name for
it will be 254 bytes long.
Below are lists of identifiers, system catalogs, and built-in func-
tions that are affected by the new limits. The pre-ASE 15 restriction
was 30 bytes.
Long Identifiers
Application context name Procedure name
Cache name Rule name
Column name Table name
Constraint name Time range name
Default name Trigger name
Function name User-defined datatype
Index name Variable name
JAR name View name
LWP or dynamic statement name
Short Identifiers
(The maximum length for these identifiers remains 30 bytes.)
New Datatypes
t bigint — Supports signed integers from
–9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
t unsigned <xx> — Allows for range extension on the ASE integer
datatypes of smallint, int, and bigint
Ranges for unsigned datatypes:
Datatype Range
unsigned smallint 0 to 65,535
unsigned int 0 to 4,294,967,295
unsigned bigint 0 to 18,446,744,073,709,551,615
Note: The range for each of the unsigned datatypes doubles on the pos-
itive side of zero since it is not possible to declare a negative number
with unsigned integer variables. The storage size for each of the
unsigned datatypes remains the same as the signed version of the corre-
sponding datatype.
48 | Chapter 2: System Maintenance Improvements
New Functions
t audit_event_name() — Returns the event name for an audit
event
Syntax:
audit_event_name(event_id)
Example:
select * from sybsecurity..sysaudits_01 where
audit_event_name(event) = "Drop Table"
select audit_event_name(event) from sybsecurity..sysaudits_01
Example:
select biginttohex(123451234512345)
Output:
----------------
000070473AFAEDD9
Example:
select count_big(identification) from authors
Output:
--------------------
22500
Example:
select hextobigint("12345fffff")
Output:
--------------------
78188118015
Example:
select is_quiesced(5)
Output:
-----------
0
Example:
select partition_id("authors_hash", "p2")
Output:
-----------
1449772222
Example:
select partition_name(3, 681769486)
Output:
------------------
rentals_idx2_part3
Example:
select tran_dumpable_status("Events")
Output:
-----------
120
Deprecated Functions
As with any changed function or system-generated output, there may
be an impact on any custom routines that rely on or scrutinize the
specific function. When a function is deprecated, it is not fully
removed from ASE. A deprecated function no longer functions in the
way it was designed; instead, the functions will return only a zero.
This deprecation, as opposed to full removal from ASE, keeps
third-party applications many database administrators use from
crashing due to references to invalid functions.
t data_pgs — Deprecated and replaced with the data_pages
command
t ptn_data_pgs — Deprecated and replaced with the data_pages
command
t reserved_pgs — Deprecated and replaced with the
reserved_pages command
t row_cnt — Deprecated and replaced with row_count
Chapter 2: System Maintenance Improvements | 51
Variable Description
@@cursor_rows Number of cursor rows in the cursor result set, when fully
populated
@@fetch_status Reports on success or failure of fetch from cursor
@@setrowcount Returns value for set rowcount at session level
@@textdataptnid Partition ID of a text partition referenced by @@txtptr
@@textptnid Partition ID of a data partition referenced by @@txtptr
Summary
By now you will have noticed that there are sufficient material
enhancements and changes that are relevant to the topic of “system
administration” to constitute a full volume in itself. From Chapter 2,
one can gain at least a basic understanding of the progress made in
system administration with the ASE 15 release. In addition, the
examples illustrate the power of many of the new maintenance tech-
niques made possible with the introduction of semantic partitions,
which are covered in detail in Chapter 3.
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 53
Chapter 3
Introduction
When Sybase first introduced table partitioning in ASE 11.0, the goal
was to reduce the last page contention on tables and page chains
where all of the data was being added to the end of the chain. The last
page contention included last page lock contention. This was referred
to as table slicing or equi-partitioning, whereby the table was divided
into equal-sized parts or slices. Sybase later introduced row-level
locking in ASE 11.9 to further address the page chain contention by
locking the row instead of the page. Until ASE 15, index partitioning
was not even addressed.
As data volumes grow because of retention requirements, tradi-
tional online transaction processing (OLTP) databases are fast
54 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
Data partitioning has the potential for reducing the resource require-
ments for queries by accessing only a subset of data in a table by
utilizing partition elimination and directed joins at the data partition
level. These concepts are detailed later in this chapter. Index parti-
tioning reduces physical I/O by reducing the number of index tree
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 55
Benefits of Partitioning
When Sybase first introduced partitioning, there were two immediate
benefits. First, partitioning reduced contention on the “hot spot” at
the end of the table’s page chain. If a table did not have a clustered
index, all inserted rows were added to the end of the page chain. This
hot spot was a major performance bottleneck for applications where
large amounts of data were being added to a table. The partitioning
addressed the hot spot since ASE would randomly choose a partition
for each transaction. If any rows were inserted by the transaction,
ASE would place them on the assigned partition. This type of parti-
tioning is called non-semantic partitioning. Second, the partitioning
provided the optimizer with the ability to determine how many paral-
lel worker processes could be considered for use when performing a
table scan on a partitioned table. This type of partitioning is called
horizontal partitioning.
With ASE 15, partitioning has been extended to include defin-
able partitioning strategies. This vertical partitioning is based on
several industry-accepted partitioning methods. This is a significant
benefit for users who have very large tables where table scans are a
major performance issue. When partitioning is combined with paral-
lel worker processes and segment placement, high degrees of
performance improvement are possible.
Prior to Sybase ASE 15, data skew has been an issue. The pro-
vided partition strategies will also address the issue of data skew. The
problem with data skew previously was that as the equi-partitions
became unbalanced, the effectiveness of parallel queries became
much less — and eventually not advisable. In ASE 15 with semantic
partitioning, the optimizer is able to use the semantics of the data val-
ues used in the partitioning keys to determine more appropriate
parallel query algorithms, effectively eliminating data skew as a con-
cern. This is important as the very semantics of the data is likely to
lead to skew. For example, if partitioning customers by state, the par-
titions are likely going to be very skewed as the population of more
populous states such as California will be larger than small or
sparsely populated states such as Idaho.
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 57
With ASE 15, the ability to partition on local indexes allows for
relevant portions of the index to be used when they are directly pro-
portionate to the table partition. This reduces the amount of I/O
required to interrogate the index pages when only a portion of the
index is necessary to resolve the query.
When your ASE server is upgraded to ASE 15, table partitioning
will be the default. An entry will be added to the syspartitions table
for each table and table/partition combination. Although partitions
are not required to be specified at table creation, the table will be
created with one partition if none are specified. The new
ASE_PARTITIONS license is not necessary in order for you to cre-
ate tables. It only becomes required if you decide to use the new
semantic partitioning. Licensing is discussed in the section in this
chapter called “Configuring ASE for Semantic Partitioning.”
One major issue facing many companies is the management of
historical data. As data ages, fewer queries are directed at the aged
data. As the data ages to the point where it is no longer useful, it has
to be purged. In most cases, purging of aged data can be a resource
and performance problem. By partitioning data appropriately, new
functionality within ASE 15 can ease the maintenance associated
with aged data. Truncating partitions is one such option for removing
aged data easily.
Vertical partitioning of data and indexes is a major step forward
for Sybase. Vertical partitioning addresses many performance issues
associated with very large tables. In data warehousing terminology,
fact tables will benefit from partitioning. The dimensions on which
fact tables are built lend themselves to data partitioning. By combin-
ing partition segmentation with data and index segmentation, DSS
applications should be able to achieve acceptable performance levels.
Partition Terminology
Sybase has introduced several new terms into our partitioning vocab-
ulary. Many of the terms are known in the industry. However, in
order to understand how partitioning is enhanced, an understanding
of the underlying terminology is necessary.
Semantic partition — A method of dividing a domain according to
the principles of what the data means.
58 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
Semantic Partitions
With ASE 15, partitioning has been extended to include new partition
types. In addition to reducing the page lock contention, the new parti-
tioning schemes extend the data access paths by defining partitions
based on application needs. For example, it would be great to be able
to define a table with zip codes where the customer’s data would be
placed in the corresponding partition for the zip codes instead of par-
titioning the table into a number of unrelated partitions. Also, ASE 15
partitions, for the most part, can be defined so that they are self con-
tained with their local indexes. Therefore, a search operation can be
performed on the indexed portion and thus a former need to split
large tables into many small tables is no longer necessary. It is evi-
dent that splitting a database with large tables into many databases
with small tables exacerbates database management problems. For
example, recreating a clustered index or running reorg rebuild opera-
tions were predicated with a pre-ASE 15 database with a requirement
of extra free space of 20% of the object size. If you split a 500 GB
database into 50 databases each of 10 GB, you would be wasting 100
GB additional disk space to perform clustered index maintenance
activities because of the aforementioned space requirement. On the
other hand, if 50 partitions of 10 GB each were to be used, you need
62 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
• Hash-based partitioning
• Range partitioning
• List partitioning
t Index partitioning:
• Global indexes
• Local indexes
t Partition-aware query processor engine — Takes advantage of
partitions and underlying disk devices/segments, and provides
highly scalable performance gains.
t Data placement for I/O parallelism — Individual partitions or
indexes can be placed on separate devices/segments.
t Partition-level operations — dbccs, update statistics, reorgs, table
truncations, and bcps can selectively be done on partitions. The
level of concurrency that can be expected in a partitioned object
environment is shown in the following diagram.
64 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
The effect of DBA utilities and query processing on partitioned and unpartitioned tables
OLTP
partition1
Large Table update
this month’s data
statistics
update
statistics partition2
last month’s data truncate
large OLTP
DSS
QUERY deletes
partition3
two months old reorgs
reorgs
DSS QUERY
partition4
data load on historical data 13 months old data load
Figure 3-1
Partition Types
The pre-15 partitioning is now referred to as round-robin partitioning.
This continues to be the only non-semantic and unlicensed partition-
ing scheme.
ASE 15 extends the partitioning with three new licensed parti-
tioning methods.
t Range partitioning
t Hash partitioning
t List partitioning
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 65
Range Partitioning
This is a partitioning strategy that places data and index pages on a
partition based on the value of the partition key as it relates to the
range of values that are assigned to a particular partition. The data
values of a range partition cannot overlap. Rows placed in a range
partition are deterministic and support partition exclusion by the
optimizer when it is cost estimating and selecting the access paths
and devices/CPUs to be used to resolve the query. By allowing for
data exclusion or partition elimination, performance improvements
can be gained because unnecessary partitions are not utilized. In
order to get additional performance gains, segmenting the partition
across multiple devices and associating segments with partitions
allows parallel I/O processing to occur.
Range partitions are defined by specifying an upper bound parti-
tion key value for each partition defined to the table. The lower
bound of the partition range is one unit more than the upper bound of
the previous range partition. In the cases where a table that contains
range data is first being created, only creating one partition sets the
table up to be altered to add additional partitions as they become nec-
essary. Consider, for example, sales data for a region. If the table is
futuristic (i.e., allowing for growth in the company), the first partition
may be allocated for the initial sales region. As the company grows
and new sales regions are defined, the database administrator can add
another partition by simply altering the table. Example 1 shows the
command used to create a one-range partition table followed by the
output of sp_helpartition table-name.
Example 1:
create table RangeTable
( SalesRegion int,
TotalSales char(5),
)
partition by range (SalesRegion)
(Region1 values <= (100))
go
(1 row affected)
66 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
Partition_Conditions
--------------------
VALUES <= (100)
Given the following scenario for disk layout, Example 2 shows parti-
tion data placement on different segments.
Figure 3-2
Example 2:
create table AlterPartitionKeyColumn
( ColumnA int,
ColumnB char (5),
ColumnC varchar (5),
ColumnD smallint,
ColumnE bit,
ColumnF datetime,
ColumnG numeric(10,2),
ColumnH tinyint,
ColumnI smalldatetime
)
partition by range (ColumnA, ColumnB)
(value1 values <= (100, "aaaa") on seg1,
value2 values <= (200, "hhhh") on seg2,
value3 values <= (300, MAX) on seg3)
go
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 67
sp_helpsegment seg1
go
You can also get data placement information about all of the parti-
tions of a table using the sp_objectsegment system stored procedure.
sp_objectsegment AlterPartitionKeyColumn
go
A value of MAX is also allowed for the value of the last partition.
Please note a MAX partition clause may not be necessary in this
example as there are just 52 weeks in a year even if it is a leap
year. The value of MAX should be considered where the upper
bound value is unknown for the last partition. ASE 15 allows
computed columns, columns for which data is generated during
run time. In ASE 15 computed columns cannot be used as parti-
tion keys. In this example, week of the year could either be a
materialized or nonmaterialized computed column, depending on
your application; however, this cannot be used as a semantic par-
tition key.
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 69
If the partition with MAX value grows faster than other partitions,
resulting in an obvious partition skew, the partition cannot be split.
The only way to overcome this deficiency is to add one or more new
partitions and bcp the data out from this partition, truncate the parti-
tion that needs to be split, and reload the data into the new partitions.
You do not need to split the input files; the data will be loaded
according to the partition key.
Range partitioning allows for archival and truncation of data that
has aged out.
Range partitioning also has the benefit of permitting a mixed
workload environment to coexist. For example, if the table is parti-
tioned with the key “year,” then the current year’s data may be the
target for OLTP operations while previous years’ data can be used
for DSS operations. While such a database will assume the propor-
tions and characteristics of a VLDB, range partitioning helps
maintain performance objectives in OLTP, DSS, and mixed data pro-
cessing modes.
Application examples include:
t “Rolling-window” operations — Cyclical operations where the
same operation or event occurs at regular cycles, such as daily
sales for 31 days per month. After the 31st partition has been uti-
lized, the first partition can be used again.
t Historical data — Data grows continuously. No purge is per-
formed (assuming DSS proportions).
t Delete bank statements more than five years old — Massive
delete operations are performed.
In all of the above cases, the table is expected to have one or more
time-sensitive columns (e.g., date last signed on, date account closed,
transaction date, etc.). In each of these cases, the leading column of
the partition key is this date column. So, potentially you may end up
70 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
having 365 partitions if you want to track data for each day of the
year.
In a multi-gigabyte database table with millions of transactions
per measure of time, a logged operation — like the delete command
— would generate multiple problems. For example, to accommodate
a delete operation you need to:
t Manage space usage within the transaction log.
t Find a large enough processing window during off-peak time to
handle deleting the data.
t Accommodate high resource requirements for such deletes.
Hash Partitioning
This is a partitioning strategy that places data pages on a particular
partition based on a hashing algorithm. The hashing algorithm is
based on the datatype and length and is managed internal to Sybase;
therefore, the hashing algorithm cannot be manipulated by the user.
However, altering a table and changing a partition key column’s
datatype may affect the partitioning. The goal of this partitioning
method is to attempt to equally balance the distribution of values
across the partition, eliminating data skew. As this is based on the
datatype, the assumption is based on the data being spread across the
entire domain of the datatype and in equal proportions. As a result,
even hash partitions are likely to have skew. The data has the charac-
teristic of being deterministic, similar to the range partition; however,
a hashing function is used to determine the partition where the data or
index row will be placed. Although hashing is deterministic, partition
elimination cannot occur for table scans on portions of the table —
for example, a range scan. The reason is that it is likely that the
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 71
different values within the range will have different hash values and
consequently be spread across multiple partitions.
The following SQL code would create a table with four hash par-
titions. The diagram that follows illustrates how the hash partitions
can be split across devices.
create table sales_history
(store_id int not null,
ord_num int not null,
sale_date datetime not null,
item_num char(10) not null,
qty smallint not null,
discount float not null)
partition by hash(item_num)
(p1, p2, p3, p4)
go
Figure 3-3
(1 row affected)
Partition_Conditions
--------------------
NULL
Note that if you do not include data placement clauses, the partitions
are created on the default segment.
When to Use Hash-based Partitioning
Hash-based partitioning can benefit queries that are searching for a
single row or a small number of rows in a very large table or for
tables in which the primary search arguments are high cardinality
data elements such as SSN, product SKUs, customer IDs, account
numbers, etc., that are accessed using equality (i.e., product_sku=
'N12345BA234') vs. range scans. If most table queries require full
table scans, hash partitioning may be the best partitioning strategy.
Hash partitioning is also a good choice for tables with many parti-
tions as the user does not need to know or define the dividing criteria
for each partition.
The main goal of hash-based partitioning is to address the issue
of data skew while maintaining the placement of deterministic data.
To define a table with hashed partitions in such a way as to avoid
data skew, the column(s) chosen for the partition key should define
the key to be as unique as possible. Keys that are not defined
uniquely will tend to bunch the data together, thereby nullifying the
benefits of the hashed partitions. The following examples of hashed
tables illustrate both good and bad hashed partitions.
Example 1: Bad hash partitioning
create table HashedTable (
store_id int not null,
item_id int not null,
date_sold datetime not null,
sales_person varchar(30))
partition by hash (date_sold)
(hash1 on seg1,
hash2 on seg2,
hash3 on seg3)
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 73
go
insert into bad_hash_key values (1, 1, "10/27/2005", "JaneDoe")
go 1001
(1 row affected)
1001 xacts:
Because the insert statement used the date portion only and all the
date values happen to be the same, the resulting data placement has
hash partition skew. If you insert a large number of rows where the
partition key column has a high duplication ratio, hash partitioning
also results in partition skew. To avoid that skew, just use the full
value of the datetime portion. While it is not possible to list all 1001
rows of data with specific time stamp values, it is essential to note
that by just changing the time value to a more granular value, much
of the skew can be avoided. In the following example, an algorithm is
used to increment the initial datetime value by 500 milliseconds.
Example 2: Good hash partitioning
declare @increment int, declare @myinittime datetime
select @increment=1
select @myinittime="10/27/2005 00:00:000"
The following list identifies some of the criteria that might lead
toward selecting hashing as the partitioning strategy for a table.
t If your table is large, with no particular ordering of values on any
key column that is commonly used in applications for ordering or
grouping the resulting data
t For load balancing of data across partitions
t To avoid data skew when you expect data that is likely to skew
because of the nature of the data. Recall the earlier example that
stored greeting card sales. If you use sale date and time as the
hash partition key, the data will be distributed across the parti-
tions irrespective of date and time it was sold.
t When you are likely to have a large table and you do not know
what columns to specify as the basis for partitioning. In this case,
you could use hash partitioning on a representative key of the
data within the table. It is easy to create “n” hash partitions as
opposed to specifying a range or list for each partition.
You should keep the following items in mind when choosing
hash-based partitioning.
t Most datatypes can be used as hashkey columns.
t Choose a key that isn’t skewed!
t Choosing a partition key with a high degree of duplicates or
where one value is far more frequent than others can lead to par-
tition skew. Going back to the greeting card sales example, if you
were to use only the date part of the greeting card sales and 90%
of the sales happen on one day, then even hash partitioning may
be skewed.
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 75
List Partitioning
This is a partitioning strategy where lists of data are grouped together
to create a partition. For example, a sales territory may be composed
of several continents. In order to access information about a particu-
lar sales territory, list partitions allow for partition elimination of all
sales territories except for the one of interest. The following example
and the corresponding diagram illustrate list partitioning.
Example:
create table continents
( country_code integer not null,
country_name char (25) not null,
region_code varchar (30) not null,
comment varchar (152) not null
) on seg1
partition by list (region_code)
( region1 values ('The_Americas'),
region2 values ('Asia'),
region3 values ('Europe'),
region4 values ('Australia', 'Other'))
go
Seg1
Figure 3-4
(1 row affected)
Partition_Conditions
-----------------------------------------------------------------------------------
VALUES ('NY','NJ','MD','VA')
VALUES ('FL','PA','DE','NC')
VALUES ('OH','DC','SC')
VALUES ('CA','other')
VALUES ('TX')
(1 row affected)
List partitioning also has the added benefit of acting as a check con-
straint mechanism. If an attempt is made to insert data into a list that
does not belong to that list, an error is generated and the row is not
added to the list as shown in the following command.
1> insert into ListPartition1 values('AP','Jane Doe')
2> go
Round-robin Partitioning
This is the continuation partitioning scheme from the prior releases.
This is also the default partitioning scheme during the upgrade pro-
cess. In the absence of any partitioning defined on a table, this
partitioning is automatically applied with one partition. This parti-
tioning scheme enjoys most of the benefits of the new partitioning
schemes except the “partition elimination,” which is the cornerstone
for improved performance via an improved optimizer and smart
query processor. The partition elimination is not possible with this
method because this partitioning scheme does not include a partition-
ing key, which is critical to eliminate partitions. This is the only
partitioning scheme that does not require a separate license.
The main characteristics of round-robin partitioning are:
t Randomly distributed data among the partitions
t No help to the optimizer on queries since there were no seman-
tics associated with the distribution of data
t Reduces last page contention
t Supports parallel create index and parallel data access depending
on the data placement
Round-robin partitioned tables can have global or local indexes, and
are the only tables where a clustered index can be either local or
global. The data placement and partition balance in this scheme
depends on the existence of a clustered index. As you may notice in
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 79
Then, remove the data from the table. (This example assumes that
data has already been bcped out.)
truncate table sales
go
(4 rows affected)
(1 row affected)
(return status = 0)
80 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
sp_helpartition sales
go
(4 rows affected)
If a clustered index does not exist, then the data may be placed in any
partition. It is important to understand that the partitions may not be
balanced. The only way to balance the round-robin partitions is to
drop and recreate the clustered index. Even if your business require-
ments do not necessitate a clustered index on the table, a clustered
index on an appropriate column has to be created in order to
rebalance the partitions. You will notice that such an inconvenience
is avoided in the three new partitioning schemes.
An alternative approach to balancing the round-robin partitions is
to split the input data into equal input-sized input files and bulk load
them into specific partitions by specifying the partition number in the
bcp command.
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 81
4> )
5>
6> go
1> sp_help NoPartitionTable
2> go
Name Owner Object_type Create_date
---------------------------- ------------ ------------ -------------------
NoPartitionTable dbo user table Sep 18 2005 9:24PM
(1 row affected)
< some output deleted>
partition_name partition_id pagessegment create_date
--------------------------- ------------ ------------ -------------------
NoPartitionTable_592002109 592002109 1 default Sep 18 2005 9:24PM
Partition_Conditions
--------------------
NULL
Example 2:
create table RoundRobinTableNoSegments
( ColumnA int,
ColumnB char(5)
)
partition by roundrobin 3
Example 3:
create table RoundRobinTableOneSegment
( ColumnA int,
ColumnB char(5)
)
partition by roundrobin 3 on (seg1)
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 83
Example 4:
create table RoundRobinTableOnSegments
( ColumnA int,
ColumnB char(5)
)
partition by roundrobin 3 on (seg1, seg2, seg3)
Partitioning Strategies
As presented earlier, there are four industry recognized partitioning
options that are available with ASE 15: range, list, hash, and
round-robin. The option chosen to implement partitions depends on
the data access requirements. The dimensions on which fact tables
are built lend themselves to data partitioning. By combining partition
segmentation with data and index segmentation, DSS applications
should be able to achieve acceptable performance levels. Each parti-
tioning strategy is implemented to allow the database administrator to
select the strategy that best fits the needs of the data, application, or
performance goals to support the strategic direction of the organiza-
tion. While each strategy has benefits that allow it to stand alone as
an implementation option, in some cases combinations of data and
index partitioning may be desirable. For any partitioning strategy to
be an effective method for I/O balancing, the DBMS has to provide
parallel processing options in conjunction with the host environment
supporting parallel access to data. In the case of ASE, parallelism is
available in both partitioned tables and table scans.
84 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
evaluated all the keys each time, then the number of comparisons on
inserts and updates would be greater, causing degradation in OLTP
performance on mixed workload systems.
Built-in Functions
Several built-in functions now support partitioning. Many built-in
functions have been deprecated and in their place new built-in func-
tions supporting partitioning have been introduced. Here are some of
the built-in functions and some general usage patterns.
t data_pages — Replaces data_pgs and ptn_data_pgs.
data_pages returns the number of pages used by a table, index,
or partition. The syntax is:
data_pages(dbid, object_id [, indid [, ptnid]])
(3 rows affected)
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 89
The above query shows that for a unpartitioned table, the parti-
tion ID and object_id are same.
t partition_id() — A new system function that returns the partition
ID for a specified table and partition.
The first action to consider is which tables can benefit from parti-
tioning. Although partitioning may be considered for small and
medium-sized tables, the greater performance benefits will be gained
from partitioning large tables. For that reason, the discussions will
focus on the criteria for choosing large candidate tables. However,
the criteria discussed in this chapter will be applicable to any size
table.
The tables that you want to look for are:
t Tables that are frequently accessed using table scans. Each table
might be a candidate for round-robin or range partitioning.
t Tables that contain portions of data used to resolve a higher per-
centage of the queries. For example, 80% of your queries might
go against the current six months of data, 15% against the next
six months of data, and the remaining 5% against data that is one
to two years old. This type of table would be a candidate for
range partitions.
t Tables where data can be grouped, such as sales territory data.
The data might be grouped by states within a territory. In this
case, list partitioning would be a candidate partition method. The
data might be grouped by territory IDs. This data might be either
list or range partitioned based on your knowledge of the data.
t Tables where data queries would return a unique row or a very
small number of rows would best be handled by hash-based
partitioning.
As with any changes that are being considered for an existing table,
there should be a business rule or performance issue that identifies a
need for considering making structural changes to the database. Ran-
domly choosing a table for partitioning may not have the desired
benefits. Large tables that are infrequently accessed or for which the
read performance is not an issue should not be considered when you
first start implementing the new partitioning strategies.
If you want to be proactive, use the MDA tables (as detailed in
Chapter 14) to determine candidate tables based on data read volume
and the number of rows in the table. Once you have identified possi-
ble tables, search your database to determine which stored procedures
are using the tables. After you have identified the stored procedures,
query the MDA tables to determine the frequency with which the
stored procedures are executed. Along with the information about the
frequency of usage, average execution times should be identified and
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 91
used as baseline data. You may choose to use the Query Plan Matrix
feature to record the baseline data. You are now ready to take further
steps to implement a data partitioning strategy.
At this point, the potential table has been identified. The next
step is to determine the appropriate partitioning strategy to utilize.
Before you can determine the appropriate partition strategy to
use, you have to identify the business goal that you are trying to
address. The goal will lead you to the partition strategy that is most
likely to address the issue(s). For example, if the goal is to reduce
contention on the end of the table and allow for parallel worker pro-
cesses to be used during large table scans, then the simple choice is
the round-robin partition. By identifying and understanding the goal
that you are trying to accomplish, the choice of which strategy to use
should be easily recognized. Review the discussion on each strategy
presented earlier to determine which strategy best meets the business
goal that you have identified. Keep in mind that partitioning strate-
gies cannot be combined (e.g., range and list). You can only define
the table as having a specific partitioning strategy.
At this point, the potential table has been identified and the parti-
tion strategy has been selected. If the partition strategy selected is
round-robin, you are ready to set up the table for partitioning. If the
partition strategy was not round-robin, then the next step is to deter-
mine the appropriate partition key to utilize.
If you have selected range, hash, or list partitioning strategies, the
proper partition key has to be identified. The same queries and stored
procedures that helped identify potential candidate tables can be used
in defining the column or columns that will offer the appropriate par-
tition key. The partition key should be composed of columns that are
consistently found in the where clause. One goal of the partition key
is to promote partition elimination during query resolution. A good
partition key can support this goal if the database administrator takes
the time to analyze the range of values in the columns being
considered.
Let’s examine the case where gender might be considered as a
part of a partition key. For most organizations, the classifications for
gender fall into two categories: male and female. In this case, gender
might not be a viable candidate column for a partition key as it would
only eliminate 50% of the table. However, for the FBI, there are 11
categories for gender. Potentially, in the worst case, 50% of the data
would be eliminated from the data to be processed. However, if 2%
92 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
| partition by roundrobin
{(partition_name [on segment_name]
[, partition_name [on segment_name]]...)
| number_of_partitions [on (segment_name
[, segment_name]...)]}]
...
[{partition by range (column_name[, column_name]...)
([partition_name] values <= ({constant | MAX}
[, {constant | MAX}] ...) [on segment_name]
[, [partition_name] values <= ({constant | MAX}
[, {constant | MAX}] ...) [on segment_name]]...)
| partition by roundrobin
{(partition_name [on segment_name]
[, partition_name [on segment_name]]...)
| number_of_partitions [on (segment_name
[, segment_name]...)]}]
from ...
Index Partitioning
New to ASE 15 is index partitioning. Similar to data partitioning, the
goal of index partitioning is to allow for segregation of index chains
based on the partitioning strategy and/or the partition key. There are
two types of partitioned indexes: local and global. The difference
between them is local indexes are local to the partition whereas
global indexes span the partitions. Global indexes are independent of
the partition definitions. Local indexes are linked to a specific data
partition.
Partitioned indexes inherit the table’s partition key’s partitioning
strategy. If a primary key constraint is defined on a table, the primary
key is partitioned according to the table’s partition, thereby becoming
a local index. However, there is a problem if a primary key constraint
is not the leading column in the partition key. The local index will
94 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
Local Index
As noted earlier in the chapter, a local index can be either clustered or
nonclustered. A local clustered index must be built on a table that is
equi-partitioned. What does this mean? For a local clustered index to
be effective, the data needs to be equally distributed across partitions.
This type of index is best utilized for large tables that need the data
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 95
presorted (via the clustered index) and need to allow for parallel
query processing.
Since a local index is associated with a particular partition, the
index typically provides faster access to the data pages. This is espe-
cially true for nonclustered local prefixed indexes. This is a result of
partition elimination by the optimizer based on the requirement that,
at a minimum, the partition key must contain as its first column the
corresponding column of the partitioning index. For example, if a
table is partitioned on month, the prefixed index should have month
as its first component. It can have additional columns, but the first
column of the index needs to be the same as the first column of the
partition key.
When creating a non-partitioned clustered index on a partitioned
table, the default index type is a local index. The following examples
show the various indexes on partitioned tables.
***********************************************************
Clustered Non-Partitioned Prefixed Index
on Range Partitioned Table
***********************************************************
Name Owner Object_type Create_date
------------- ----- ----------- --------------------------
GP_TableRange dbo user table May 8 2005 6:30PM
(1 row affected)
96 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
(1 row affected)
index_ptn_name index_ptn_seg
----------------- -------------
GPIndex_724194599 default
GPIndex_740194656 default
GPIndex_756194713 default
GPIndex_772194770 default
(4 rows affected)
No defined keys for this object.
name type partition_type partitions partition_keys
------------- ---------- -------------- ----------- --------------
GP_TableRange base table range 4 ColumnA
(1 row affected)
Partition_Conditions
--------------------
VALUES <= (1000)
VALUES <= (2000)
VALUES <= (3000)
VALUES <= (4000)
(1 row affected)
concurrency_opt_threshold optimistic_index_lock dealloc_first_txtpg
------------------------- --------------------- -------------------
0 0 0
(return status = 0)
*****************************************************
Clustered Non-Partitioned Non-Prefixed Index
on Range Partitioned Table
*****************************************************
Name Owner Object_type Create_date
------------- ----- ----------- --------------------------
GP_TableRange dbo user table May 8 2005 6:30PM
(1 row affected)
Column_name Type Length Prec Scale Nulls Default_name Rule_name Access_Rule_name
Computed_Column_object Identity
----------- ---- ----------- ---- ----- ----- ------------ --------- ----------------
---------------------- --------
ColumnA int 4 NULL NULL 0 NULL NULL NULL
NULL 0
ColumnB char 5 NULL NULL 0 NULL NULL NULL
NULL 0
(1 row affected)
index_ptn_name index_ptn_seg
----------------- -------------
GPIndex_916195283 default
GPIndex_932195340 default
GPIndex_948195397 default
GPIndex_964195454 default
(4 rows affected)
No defined keys for this object.
name type partition_type partitions partition_keys
------------- ---------- -------------- ----------- --------------
GP_TableRange base table range 4 ColumnA
(1 row affected)
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 99
Partition_Conditions
--------------------
VALUES <= (1000)
VALUES <= (2000)
VALUES <= (3000)
VALUES <= (4000)
(1 row affected)
concurrency_opt_threshold optimistic_index_lock dealloc_first_txtpg
------------------------- --------------------- -------------------
0 0 0
(return status = 0)
*****************************************************
Clustered Non-Partitioned Prefixed Index
on List Partitioned Table
*****************************************************
Name Owner Object_type Create_date
------------ ----- ----------- --------------------------
GP_TableList dbo user table May 8 2005 6:30PM
(1 row affected)
Column_name Type Length Prec Scale Nulls Default_name Rule_name Access_Rule_name
Computed_Column_object Identity
----------- ---- ----------- ---- ----- ----- ------------ --------- ----------------
---------------------- --------
ColumnA int 4 NULL NULL 0 NULL NULL NULL
NULL 0
ColumnB char 5 NULL NULL 0 NULL NULL NULL
NULL 0
(1 row affected)
index_ptn_name index_ptn_seg
------------------ -------------
GPIndex_1108195967 default
GPIndex_1124196024 default
GPIndex_1140196081 default
GPIndex_1156196138 default
(4 rows affected)
No defined keys for this object.
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 101
(1 row affected)
Partition_Conditions
--------------------
VALUES (1000)
VALUES (2000)
VALUES (3000)
VALUES (4000)
(1 row affected)
concurrency_opt_threshold optimistic_index_lock dealloc_first_txtpg
------------------------- --------------------- -------------------
0 0 0
(return status = 0)
*****************************************************
Clustered Non-Partitioned Non-Prefixed Index
on List Partitioned Table
*****************************************************
Name Owner Object_type Create_date
------------ ----- ----------- --------------------------
GP_TableList dbo user table May 8 2005 6:30PM
(1 row affected)
Column_name Type Length Prec Scale Nulls Default_name Rule_name Access_Rule_name
Computed_Column_object Identity
----------- ---- ----------- ---- ----- ----- ------------ --------- ----------------
---------------------- --------
ColumnA int 4 NULL NULL 0 NULL NULL NULL
NULL 0
ColumnB char 5 NULL NULL 0 NULL NULL NULL
NULL 0
(1 row affected)
index_ptn_name index_ptn_seg
------------------ -------------
GPIndex_1300196651 default
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 103
GPIndex_1316196708 default
GPIndex_1332196765 default
GPIndex_1348196822 default
(4 rows affected)
No defined keys for this object.
name type partition_type partitions partition_keys
------------ ---------- -------------- ----------- --------------
GP_TableList base table list 4 ColumnA
(1 row affected)
Partition_Conditions
--------------------
VALUES (1000)
VALUES (2000)
VALUES (3000)
VALUES (4000)
(1 row affected)
concurrency_opt_threshold optimistic_index_lock dealloc_first_txtpg
------------------------- --------------------- -------------------
0 0 0
(return status = 0)
104 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
*****************************************************
Clustered Non-Partitioned Prefixed Index
on Round-robin Partitioned Table
*****************************************************
Warning: Clustered index 'GPIndex' has been created on the empty partitioned table
'GP_TableRR'. All insertions will go to the first partition. To distribute the data
to all the partitions, re-create the clustered index after loading the data.
Name Owner Object_type Create_date
---------- ----- ----------- --------------------------
GP_TableRR dbo user table May 8 2005 6:31PM
(1 row affected)
Column_name Type Length Prec Scale Nulls Default_name Rule_name Access_Rule_name
Computed_Column_object Identity
----------- ---- ----------- ---- ----- ----- ------------ --------- ----------------
---------------------- --------
ColumnA int 4 NULL NULL 0 NULL NULL NULL
NULL 0
ColumnB char 5 NULL NULL 0 NULL NULL NULL
NULL 0
(1 row affected)
index_ptn_name index_ptn_seg
------------------ -------------
GPIndex_1460197221 default
GPIndex_1476197278 default
GPIndex_1492197335 default
(3 rows affected)
No defined keys for this object.
name type partition_type partitions partition_keys
---------- ---------- -------------- ----------- --------------
GP_TableRR base table roundrobin 3 NULL
(1 row affected)
Partition_Conditions
--------------------
NULL
(1 row affected)
concurrency_opt_threshold optimistic_index_lock dealloc_first_txtpg
------------------------- --------------------- -------------------
0 0 0
(return status = 0)
*****************************************************
Clustered Non-Partitioned Non-Prefixed Index
on Round-robin Partitioned Table
*****************************************************
Warning: Clustered index 'GPIndex' has been created on the empty partitioned table
'GP_TableRR'. All insertions will go to the first partition. To distribute the data
to all the partitions, re-create the clustered index after loading the data.
Name Owner Object_type Create_date
---------- ----- ----------- --------------------------
GP_TableRR dbo user table May 8 2005 6:31PM
(1 row affected)
Column_name Type Length Prec Scale Nulls Default_name Rule_name Access_Rule_name
Computed_Column_object Identity
----------- ---- ----------- ---- ----- ----- ------------ --------- ----------------
---------------------- --------
ColumnA int 4 NULL NULL 0 NULL NULL NULL
NULL 0
ColumnB char 5 NULL NULL 0 NULL NULL NULL
NULL 0
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 107
(1 row affected)
index_ptn_name index_ptn_seg
------------------ -------------
GPIndex_1604197734 default
GPIndex_1620197791 default
GPIndex_1636197848 default
(3 rows affected)
No defined keys for this object.
name type partition_type partitions partition_keys
---------- ---------- -------------- ----------- --------------
GP_TableRR base table roundrobin 3 NULL
(1 row affected)
Partition_Conditions
--------------------
NULL
(1 row affected)
concurrency_opt_threshold optimistic_index_lock dealloc_first_txtpg
------------------------- --------------------- -------------------
0 0 0
(return status = 0)
*****************************************************
Clustered Non-Partitioned Non-Prefixed Index
on Hash Partitioned Table
*****************************************************
Name Owner Object_type Create_date
------------ ----- ----------- --------------------------
GP_TableHash dbo user table May 8 2005 6:31PM
(1 row affected)
Column_name Type Length Prec Scale Nulls Default_name Rule_name Access_Rule_name
Computed_Column_object Identity
----------- ---- ----------- ---- ----- ----- ------------ --------- ----------------
---------------------- --------
ColumnA int 4 NULL NULL 0 NULL NULL NULL
NULL 0
ColumnB char 5 NULL NULL 0 NULL NULL NULL
NULL 0
(1 row affected)
index_ptn_name index_ptn_seg
------------------ -------------
GPIndex_1924198874 default
GPIndex_1940198931 default
GPIndex_1956198988 default
(3 rows affected)
No defined keys for this object.
name type partition_type partitions partition_keys
------------ ---------- -------------- ----------- --------------
GP_TableHash base table hash 3 ColumnA
(1 row affected)
Partition_Conditions
--------------------
NULL
(1 row affected)
concurrency_opt_threshold optimistic_index_lock dealloc_first_txtpg
------------------------- --------------------- -------------------
0 0 0
(return status = 0)
*****************************************************
Clustered Non-Partitioned Prefixed Index
on Hash Partitioned Table
*****************************************************
Name Owner Object_type Create_date
------------ ----- ----------- --------------------------
GP_TableHash dbo user table May 8 2005 6:31PM
(1 row affected)
Column_name Type Length Prec Scale Nulls Default_name Rule_name Access_Rule_name
Computed_Column_object Identity
----------- ---- ----------- ---- ----- ----- ------------ --------- ----------------
---------------------- --------
ColumnA int 4 NULL NULL 0 NULL NULL NULL
NULL 0
ColumnB char 5 NULL NULL 0 NULL NULL NULL
NULL 0
(1 row affected)
index_ptn_name index_ptn_seg
------------------ -------------
GPIndex_1764198304 default
GPIndex_1780198361 default
GPIndex_1796198418 default
(3 rows affected)
No defined keys for this object.
name type partition_type partitions partition_keys
------------ ---------- -------------- ----------- --------------
GP_TableHash base table hash 3 ColumnA
(1 row affected)
Partition_Conditions
--------------------
NULL
(1 row affected)
concurrency_opt_threshold optimistic_index_lock dealloc_first_txtpg
------------------------- --------------------- -------------------
0 0 0
(return status = 0)
Example:
create clustered index LocalPartitionedIndex
on TableName (ColumnA)
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 113
local index
partition1 on seg1,
partition2 on seg2,
partition3 on seg3
go
sp_helpindex TableName
go
Object has the following indexes
index_name
index_keys index_description
index_max_rows_per_page index_fillfactor index_reservepagegap
index_created index_local
------------------------------------------------------------------------
------------ --------------------------------
------------------------------------ -----------------------
---------------- -------------------- --------------------------
--------------------------------------------
LocalPartitionedIndex
ColumnA clustered
0 0 0 Oct 28 2005 10:56AM Local
Index
(1 row affected)
index_ptn_name index_ptn_seg
------------------------------------------- ----------------------------
LocalPartitionedIndex_860527068 default
partition1 seg1
partition2 seg2
partition3 seg3
(4 rows affected)
(return status = 0)
Global Index
A global index can be either clustered or nonclustered. A global
index can also be prefixed. Prefixed global indexes are available for
all data partitioning strategies. Non-prefixed global indexes are not
supported in ASE 15 as the industry deems this concept to not be
useful in real applications.
114 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
*****************************************************
Global Nonclustered Non-Partitioned Prefixed Index
on Range Partitioned Table
*****************************************************
Name Owner Object_type Create_date
------------- ----- ----------- --------------------------
GP_TableRange dbo user table May 8 2005 1:47PM
(1 row affected)
Column_name Type Length Prec Scale Nulls Default_name Rule_name
Access_Rule_name Computed_Column_object Identity
----------- ---- ----------- ---- ----- ----- ------------ ---------
---------------- ---------------------- --------
ColumnA int 4 NULL NULL 0 NULL NULL
NULL NULL 0
ColumnB char 5 NULL NULL 0 NULL NULL
NULL NULL 0
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 115
(1 row affected)
No defined keys for this object.
name type partition_type partitions partition_keys
------------- ---------- -------------- ----------- --------------
GP_TableRange base table range 4 ColumnA
(1 row affected)
Partition_Conditions
--------------------
VALUES <= (1000)
VALUES <= (2000)
VALUES <= (3000)
VALUES <= (4000)
(1 row affected)
concurrency_opt_threshold optimistic_index_lock dealloc_first_txtpg
------------------------- --------------------- -------------------
0 0 0
(return status = 0)
*****************************************************
Global Nonclustered Non-Partitioned Prefixed Index
on List Partitioned Table
*****************************************************
Name Owner Object_type Create_date
------------ ----- ----------- --------------------------
GP_TableList dbo user table May 8 2005 1:47PM
(1 row affected)
(1 row affected)
index_ptn_name index_ptn_seg
------------------ -------------
GPIndex_2142627645 default
(1 row affected)
(1 row affected)
Partition_Conditions
--------------------
VALUES (1000)
VALUES (2000)
VALUES (3000)
VALUES (4000)
(1 row affected)
(1 row affected)
(1 row affected)
index_ptn_name index_ptn_seg
----------------- -------------
GPIndex_139144510 default
(1 row affected)
(1 row affected)
Partition_Conditions
--------------------
NULL
(1 row affected)
concurrency_opt_threshold optimistic_index_lock dealloc_first_txtpg
------------------------- --------------------- -------------------
0 0 0
(return status = 0)
*****************************************************
Global Nonclustered Non-Partitioned Prefixed Index
on Hash Partitioned Table
*****************************************************
Name Owner Object_type Create_date
------------ ----- ----------- --------------------------
GP_TableHash dbo user table May 8 2005 1:47PM
(1 row affected)
(1 row affected)
index_ptn_name index_ptn_seg
----------------- -------------
GPIndex_315145137 default
(1 row affected)
(1 row affected)
Partition_Conditions
--------------------
NULL
(1 row affected)
placed on seg1 with 2 disk placed on default segment placed on seg3 with 3 disk
chunks with 4 disk devices chunks
table:
items_sold
join join
ated in ated in
elimin elimin
Partitions joined directly
ion n
Part it Partitio
table:
customer
placed on seg1 with 4 disk placed on seg2 with 2 disk placed on seg3 with 4 disk
chunks chunks chunks
Figure 3-5
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 123
Figure 3-6
t Local indexes on partitions — Increased concurrency through
multiple index access points. The number of index levels per par-
tition will likely be less compared to having one large index.
QueryX
Partitioned Index
Unpartitioned Index
Figure 3-7
ASE 15 Optimizer
The newly revised Sybase ASE 15 optimizer is cognizant of the new
partitioning schemes. The optimizer can pick only those partitions
that would satisfy the query, thus eliminating all other partitions from
the access paths. This “partition elimination” is expected to increase
the performance not just to OLTP queries but also to DSS queries.
The optimizer can now consider one or more individual partitions
rather than the entire table or all partitions (as in pre-15 partitioning).
Please note the partition elimination does not apply to the default and
unlicensed partitioning scheme called round-robin partitioning,
which is equivalent to partitioning in pre-15. Sybase realized that in
order to improve the data access performance of very large tables, the
data has to be able to be partitioned in ways other than just defining
“n” partitions on the table. “n” partitions are good for inserting large
amounts of data into the table when all data is being added to the end
of the table; however, with the proliferation of decision support sys-
tems and management’s need to slice-and-dice data, Sybase needed
to extend partitioning with meaning or semantics into new areas.
Partition Maintenance
This section highlights some of the maintenance functions and stored
procedures available to help manage partitioned tables and indexes.
For more details about the new stored procedures, see Chapter 2,
“System Maintenance Improvements.”
Unpartition a Table
alter table [database-name.[owner-name].]table-name unpartition
Only range and list partitioned tables can have partitions added to
them. In order to add a partition to a hash or round-robin partitioned
table, it will be necessary to recreate the table with the additional par-
tition(s). Data will need to be reloaded using select into or bcp.
There is a difference in the following two syntax examples for
altering a range partition. If you specify the keyword by range (<par-
tition key>) and if the key value is the next highest increment value of
the last partition, instead of adding a new partition, it will change the
previous partition to the value of the new range. To add new parti-
tions, use the syntax without by range (<partition key>).
create table RangeTable2 (sales_region int, sales float)
partition by range(sales_region)
(region1 values <= (100),
region2 values <= (200),
region3 values <= (300))
go
sp_helpartition RangeTable2
go
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 127
(1 row affected)
Partition_Conditions
------------------------------------------------------------
VALUES <= (100)
VALUES <= (200)
VALUES <= (300)
sp_helpartition RangeTable2
go
(1 row affected)
Partition_Conditions
------------------------------------------------------------
VALUES <= (400)
128 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
(1 row affected)
Partition_Conditions
------------------------------------------------------------
VALUES <= (100)
VALUES <= (200)
VALUES <= (300)
VALUES <= (400)
If you try to add a new list partition with the following syntax, it will
not succeed. Recall that similar syntax to add a new range partition
would succeed, wiping out all range partitions and giving just one
partition that you added.
1> alter table ListPartition1
2> partition by list (state)
3> (region5 values ('TX'))
4> go
Msg 9573, Level 16, State 1:
Server 'DMGTD02A2_SYB', Line 1:
The server failed to create or update a row in table 'ListPartition1'
because the values of the row's partition-key columns do not fit into
any of the table's partitions.
The only way to add a new list partition is to use the add clause as
follows:
1> alter table ListPartition1
2> add partition
3> (region5 values ('TX'))
4> go
Now the partitions include the new partition that was just added.
Partition name partition key Rows per partition
-------------------------- ----------------------- ---------------------
ListPartition1 region1 1
ListPartition1 region2 21
ListPartition1 region3 21
130 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
ListPartition1 region4 21
ListPartition1 region5 0
Drop Partitions
alter table [database-name.[owner-name].]table-name
drop partition partition-name
(1 row affected)
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 133
Partition_Conditions
-----------------------
VALUES <= (100, "aaaa")
VALUES <= (200, "hhhh")
VALUES <= (300, MAX)
Partition Information
Information about the partitioning on a table or index is available
through several new stored procedures, system table columns, and
system functions. A revised system stored procedure, sp_helpartition,
is available to retrieve information about the partitioning on a table.
This stored procedure is also called by sp_help when used to gather
information about a table. The procedure is also executed when the
stored procedure sp_helpindex is issued. The example below shows
the various methods that can be used to view partition information. In
addition, review the section called “Partition-level Utilities” in Chap-
ter 2 to find various other tools that may be used to find partition
information.
create table AlterPartitionKeyColumn
( ColumnA int,
ColumnB char(5),
ColumnC varchar(5),
ColumnD smallint,
ColumnE bit,
ColumnF datetime,
ColumnG numeric(10,2),
ColumnH tinyint,
ColumnI smalldatetime
)
partition by range (ColumnA, ColumnB)
(value1 values <= (100, "aaaa") on seg1,
value2 values <= (200, "hhhh") on seg2,
value3 values <= (300, MAX) on seg3 )
go
create nonclustered index GPIndex on dbo.AlterPartitionKeyColumn (ColumnA,
ColumnB)
go
insert into AlterPartitionKeyColumn values (10, 'bbbb', 'bbbb',
10,1,"5/5/2005",999.99, 1,"5/5/2005")
insert into AlterPartitionKeyColumn values (20, 'bbbb', 'bbbb',
10,1,"5/5/2005",999.99, 1,"5/5/2005")
insert into AlterPartitionKeyColumn values (30, 'bbbb', 'bbbb',
10,1,"5/5/2005",999.99, 1,"5/5/2005")
insert into AlterPartitionKeyColumn values (40, 'bbbb', 'bbbb',
10,1,"5/5/2005",999.99, 1,"5/5/2005")
insert into AlterPartitionKeyColumn values (50, 'bbbb', 'bbbb',
10,1,"5/5/2005",999.99, 1,"5/5/2005")
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 135
Results:
************************************************************
* CMD: sp_help AlterPartitionKeyColumn
************************************************************
Name Owner Object_type Create_date
----------------------- ----- ----------- --------------------------
AlterPartitionKeyColumn dbo user table May 9 2005 10:47PM
(1 row affected)
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 137
(1 row affected)
index_ptn_name index_ptn_seg
------------------ -------------
GPIndex_2109247538 default
(1 row affected)
No defined keys for this object.
138 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
(1 row affected)
Partition_Conditions
-----------------------
VALUES <= (100, "aaaa")
VALUES <= (200, "hhhh")
VALUES <= (300, MAX)
(1 row affected)
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 139
************************************************************
* CMD: sp_helpartition AlterPartitionKeyColumn
************************************************************
name type partition_type partitions
partition_keys
----------------------- ---------- -------------- -----------
----------------
AlterPartitionKeyColumn base table range 3
ColumnA, ColumnB
(1 row affected)
Partition_Conditions -----------------------
VALUES <= (100, "aaaa")
VALUES <= (200, "hhhh")
VALUES <= (300, MAX)
************************************************************
* CMD: sp_helpartition AlterPartitionKeyColumn, null, value1
************************************************************
140 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
(1 row affected)
Partition_Conditions
-----------------------
VALUES <= (100, "aaaa")
(return status = 0)
************************************************************
* CMD: sp_helpartition AlterPartitionKeyColumn, GPIndex
************************************************************
name type partition_type partitions partition_keys
------- ------------ -------------- ----------- --------------
GPIndex global index roundrobin 1 NULL
(1 row affected)
Partition_Conditions
--------------------
NULL
Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support | 141
************************************************************
* CMD: sp_helpindex AlterPartitionKeyColumn, GPIndex
************************************************************
Object has the following indexes
(1 row affected)
index_ptn_name index_ptn_seg
------------------ -------------
GPIndex_2109247538 default
(1 row affected)
(return status = 0)
Sybase has also provided new system functions and updated some
existing ones to allow the user to query information about the parti-
tions. These system functions include:
t data_pages — Returns information about the number of data
pages used by the partition.
Syntax:
data_pages (dbid, object_id [, indid [, ptnid]])
t reserved_pages — Returns information about the number of
reserved pages used by the partition.
Syntax:
reserved_pages (dbid, object_id [, indid [, ptnid]])
142 | Chapter 3: Semantic Partitions and Very Large Database (VLDB) Support
Summary
Partitioning of tables and indexes is considered one of the major fea-
tures of ASE 15. For the first time, Sybase has provided a feature that
allows the ASE server to manage large tables and large databases.
The ability to select a partitioning strategy allows the DBA the flexi-
bility to manage large databases and tables with the knowledge that
performance will be improved by partitioning a table or index. The
DBA will have to keep in mind that to fully utilize the benefits of
partitioned tables and indexes, parallelism will need to be activated
on the server.
ASE 15 delivers
! Higher availability
! Partitioned maintenance
! Reduced downtime
lower
! Supports OLTP/DSS/Mix workload cost of
ownership
! Improved performance via partition
elimination and directed joins
Figure 3-8
Chapter 4: Scrollable Cursors | 145
Chapter 4
Scrollable Cursors
Introduction
As part of ASE 15, Sybase introduces scrollable cursors. This new
functionality allows for bidirectional movement of the cursor’s posi-
tion. The scrollable cursor allows the cursor to be positioned directly
at an arbitrary row in the cursor’s result set. Further, with scrollable
cursors, the cursor position can revisit the same row more than one
time, with no limit. Prior to version 15, cursors were unidirectional
(forward-only) and each row in the cursor set could be fetched no
more than once.
To further enhance cursors, Sybase introduces cursor sensitivity.
As this chapter will explain, cursor sensitivity determines if data
changes independent of the cursor set are visible to the cursor. In
146 | Chapter 4: Scrollable Cursors
Cursor Scrollability
As stated in the introduction, a scrollable cursor allows bidirectional
movement of the cursor position through a result set. In addition, the
scrollable cursor allows for cursor positioning at specifically called
rows in the cursor set. In this section, we elaborate on how to control
cursor scrollability.
Chapter 4: Scrollable Cursors | 147
Note: For scrollable cursors in ASE 15, the only valid cursor specifica-
tion is “for read only.” If you declare a scrollable cursor with a
specification clause of “for update” in ASE 15, ASE will return a syntax
error. Sensitive cursors may be updated provided they are declared as
non-scrollable. Stay tuned to future releases of ASE, as cursor
scrollability and sensitivity features may be enhanced in future releases.
Examples:
declare CSR1 scroll cursor for
select order_date from orders
declare CSU1 scroll cursor for
select start_date, end_date
from payroll where emp_name = "Brian Taylor"
Extension Explanation
first Fetch the first row from the cursor result set.
last Fetch the last row from the cursor result set.
next Fetch the next row from the cursor result set. This is the default fetch
performed when retrieving a row from a non-scrollable cursor. It is the only
extension to the fetch command allowed in a non-scrollable cursor.
prior Fetch the previous row in the cursor result set.
absolute n Fetch the nth row in the cursor result set from the beginning of the cursor
set.
relative n Fetch the nth row in the cursor result set from the current cursor position.
148 | Chapter 4: Scrollable Cursors
Fetch the 10th row forward from the current cursor position:
fetch relative 10 CSI
@@fetch_status
@@cursor_rows
Note: A fetch of the last row in the cursor set with the fetch last cur-
sor_name command will seed the @@cursor_rows global variable with
the number of rows in the cursor set.
150 | Chapter 4: Scrollable Cursors
Note: A subsequent fetch of the next cursor row will fail after an abso-
lute fetch outside the range of the cursor set. A subsequent cursor call
will need to reposition the cursor position within the range of the cursor’s
total row count.
Example scenario:
• Declare and open a cursor with 10 rows in the result set.
• Fetch the 15th row in the cursor set:
fetch absolute 15 CSR1
Cursor position will then be after the 10th row in the result set.
• Fetch the “prior” row in the cursor set:
fetch prior CSR1
Cursor position will then be after the 10th row in the result set.
• Fetch the “prior” row in the cursor set:
fetch prior CSR1
Cursor Sensitivity
Cursor sensitivity refers to the effect independent row modifications
in the base table will have on the cursor result set. A sensitive cursor
states the cursor result set can be affected by independent changes to
the base table. In contrast, with an insensitive cursor, independent
data changes are not visible within the cursor’s result set. In order to
create a sensitive cursor, it is declared as semi_sensitive in ASE 15.
The basic syntax to declare a sensitive cursor is as follows:
declare cursor_name semi_sensitive cursor
Chapter 4: Scrollable Cursors | 153
Example:
declare Employee_CSR semi_sensitive cursor
for select from Employee
where hire_date >= "01/01/2005"
Rules:
t The default sensitivity for a cursor is insensitive.
t A sensitive cursor can be declared as a scrollable cursor.
t A sensitive cursor can only be declared as an updatable cursor in
ASE 15 as long as the cursor is not scrollable.
The sensitive cursor also has rules to govern the sensitivity in relation
to data changes. Data changes are visible to the cursor only if an
independent data modification:
t To the base table causes a row in the cursor result set to be
inserted or deleted.
t To the base table causes the value of a referenced column to
change.
t Forces a reorder of the rows in a cursor result set.
Note: The examples and text within this chapter are performed with the
default isolation level of 1. Modification of the isolation level may produce
different results.
Example table:
create table dbo.brian
(
a int NOT NULL,
b int NOT NULL,
c varchar(10) NOT NULL
154 | Chapter 4: Scrollable Cursors
)
lock datarows
go
a b c
1 1 Brian
2 2 Carrie
3 3 Elliot
14 4 Jonah
5 5 Sammy
6 6 Wrigley
7 7 Nancy
8 8 Robert
9 9 Grant
10 10 Arthur
open CIN
go
declare @a int,
@c varchar(10)
Output:
A C
1 brian
Output:
a b c
11 1 brian
Output:
a c
1 brian
Output:
a b c
14 4 jonah
USER A runs fetch next for three iterations to reach the newly quali-
fied row:
fetch next CIN
into @a,
@c
select @a, @c
go
Chapter 4: Scrollable Cursors | 157
Iteration 2:
a c
3 elliot
Iteration 3:
a c
4 jonah
data is stored. The text or image page chain is not locked after the
rows are brought into the cursor’s worktable.
Note: For cursors containing both text and image along with other
datatypes, only the text or image portion of the cursor will exhibit this
exceptional behavior.
open large_cursor
go
sp_helpdb tempdb
go
Output excerpt:
device_fragments free kbytes
tempdb_data1 2039938
tempdb_data2 2039986
tempdb_data3 2039986
Output excerpt:
device_fragments free kbytes
tempdb_data1 2039442
tempdb_data2 2040000
tempdb_data3 1946948
Note the decrease in free tempdb space after skipping to the last row
in the cursor large_cursor. A fetch of the last row of a scrollable sen-
sitive cursor materializes the worktable based on the return of all
rows, despite the need for only the last row. A similar impact exists if
we select the absolute 1,000th row from the cursor, for example. All
160 | Chapter 4: Scrollable Cursors
qualified cursor rows from 1 through 1,000 may load into the cursor’s
worktable in tempdb. For reasons discussed in the section called
“Sybase Engineer’s Insight” later in this chapter, the qualified rows
load into tempdb if the size of the result set exceeds the size threshold
of an internal memory structure designed to hold the cursor result set.
Note: Once the cursor’s position reaches the last row in the scrollable
sensitive cursor, subsequent fetches of prior rows will not cause the
worktable to grow or be rebuilt.
statistics io output:
Table: Events scan count 1, logical reads: (regular=4 apf=0 total=4),
physical reads: (regular=0 apf=0 total=0), apf IOs used=0
-- skip backward to the first cursor row, the worktable will be accessed
since it is now materialized:
-- skip to the last row in the cursor set, and the worktable is fully
materialized. All subsequent scans for cursor rows will now scan the
cursor’s worktable.
-- return to the first row in the cursor set, and the worktable is
scanned.
open large_cursor
go
-- Worktable is materialized on the "open cursor" statement. Tempdb’s
available space is now reduced by the cursor’s fully materialized
size, before a single row is fetched from the cursor.
In the above example, the sensitive cursor returned the first row from
the cursor set after only four I/Os on the initial fetch. Zero I/Os are
performed on the sensitive cursor when the cursor is opened. In con-
trast, upon opening the insensitive cursor, all potential cursor rows
are loaded into a worktable before a single row is fetched from the
cursor. In this example, 14 million I/Os were performed before a sin-
gle row could be fetched from the insensitive cursor.
164 | Chapter 4: Scrollable Cursors
Summary
In order to ensure user satisfaction with the applications many of us
develop and support, it is crucial to deliver feedback to the end user
in the most timely fashion. We have all worked with users frustrated
at the appearance of the hourglass when their application begins to
look up a certain part, order, or customer.
The sensitive cursor provides the developer and DBA with an
additional tool in order to combat user frustration. As demonstrated
in this chapter, we displayed an example where a sensitive cursor
returned the first set of rows in four I/Os in comparison to the 14 mil-
lion I/Os associated with an otherwise identical insensitive cursor.
Chapter 4: Scrollable Cursors | 165
Your I/O savings will vary with sensitive cursors since most cursors
are probably not designed for the mass processing of data, but most
applications will benefit from cursor sensitivity.
As demonstrated, the scrollable cursor feature assists the devel-
opment effort by providing a mechanism to bidirectionally scroll
through result sets. The creation of special code to handle the manip-
ulation of a result set linked to objects such as “drop-down” lists will
no longer be necessary.
Future Direction
At the time of this book’s publication, the future direction of
scrollable cursors is not yet defined. The engineering team at Sybase
has not ruled on the feasibility of allowing scrollable and sensitive
cursors that can be declared for update, including fully sensitive
cursors.
The authors remain encouraged by Sybase’s commitment to
bring ASE into competitive balance with the introduction of
scrollable cursors. It should also be recognized that Sybase has done
an excellent job with the implementation of cursor sensitivity. This
enhancement clearly allows a very fast response time to return the
initial row from a cursor.
This page intentionally left blank.
Chapter 5: Overview of Changes to the Query Processing Engine | 167
Chapter 5
Introduction
Queries used for OLTP (online transaction processing) and for DSS
(decision support system) have different performance requirements.
OLTP queries are relatively less complex and the desired response
time is anywhere from split seconds to a few minutes. DSS queries,
on the other hand, are more complex and their response time can be
from a few minutes to many hours. Because of their differences in
usage and the performance requirements, OLTP and DSS used to be
handled on different systems. Today, the increasing complexity of
business requirements and the pressure to lower the total cost of own-
ership (TCO) are requiring the data servers to move toward a mixed
workload environment where the OLTP system also performs
168 | Chapter 5: Overview of Changes to the Query Processing Engine
Optimization Goals
The new "optimization goal" configuration parameter allows the user
to choose the optimization strategy that best fits the query environ-
ment. The optimization goals are preset groupings of the optimization
criteria that in combination affect the behavior of the optimizer.
These goals direct the optimizer to use the features that will allow it
to find the most efficient query plan. The optimization goals are
shorthand for enabling logical “sets” of specific optimization criteria.
The optimization goals can be set at the server, session, or query
level. The server-level optimization goal is overridden at the session
level, which in turn is overridden at the query level.
The possible values for this parameter are allrows_oltp,
allrows_mix, and allrows_dss.
allrows_oltp
OLTP applications such as stock trading applications have
transactional queries of low or medium complexity. The allrows_oltp
option directs the query processing engine to use the features and
techniques that will generate the query plans most efficient for a
purely OLTP query. When this option is set, the optimizer optimizes
queries so that ASE uses a limited number of optimization criteria to
find a good query plan. Also, fewer sorting operations are performed.
This optimization goal is useful in applications that are performing
only transactional work and don’t need all the capabilities of ODSS.
Limiting the capabilities available to OLTP results in a fewer number
of query plans to be evaluated, which in turn improves the overall
query processing time.
The command to set the allrows_oltp optimization goal at the
server level is:
sp_configure "optimization goal", 0, "allrows_oltp"
Chapter 5: Overview of Changes to the Query Processing Engine | 169
The command to set the allrows_oltp goal at the session level is:
set plan optgoal allrows_oltp
And the command to set the allrows_oltp goal at the query level is:
select * from A
order by A.col1 plan "(use optgoal allrows_oltp)"
allrows_mix
When this option is set, the query processor optimizes queries so that
ASE uses all available optimization techniques, including the new
features and functionality, to find the best query plan. This is the
default strategy and is most useful in a mixed-query environment.
allrows_mix is basically allrows_oltp + merge joins + parallelism.
The command to set the allrows_mix optimization goal at the
server level is:
sp_configure "optimization goal", 0, "allrows_mix"
The command to set the allrows_mix goal at the session level is:
set plan optgoal allrows_mix
And the command to set the allrows_mix goal at the query level is:
select * from A
order by A.col1 plan "(use optgoal allrows_mix)"
Note: Optimization goals at the server level will have impact on all data-
bases, and may not be the intent of the DBA when making performance
tweaks to a single query.
allrows_dss
This option is useful in the DSS environment where the queries are of
medium to high complexity. This option is basically allrows_mix +
hash joins.
The command to set the allrows_dss optimization goal at the
server level is:
sp_configure "optimization goal", 0, "allrows_dss"
170 | Chapter 5: Overview of Changes to the Query Processing Engine
The command to set the allrows_dss goal at the session level is:
set plan optgoal allrows_dss
And the command to set the allrows_dss goal at the query level is:
Select * from A
order by A.col1 plan "(use optgoal allrows_dss)"
Tip: In environments where the server is used for OLTP during the day
and as a DSS in the evening, you can have a scheduled job that sets the
configuration to allrows_mix in the morning and changes it to allrows_dss
in the evening before the batch jobs kick in.
------------------------------
allrows_dss
(1 row affected)
Optimization Criteria
Optimization criteria are specific algorithms or relational techniques
for the query plan. Each optimization goal has a default setting for
each optimization criterion. Even though these criteria can be set by a
DBA, Sybase does not recommend it at this point. Resetting optimi-
zation criteria may interfere with the default settings of the current
optimization goal, hurt the overall performance, and even produce an
error message. Please consult Sybase Technical Support if you see a
need to tune the optimization criteria.
Following are brief descriptions of some of the new optimization
criteria.
Chapter 5: Overview of Changes to the Query Processing Engine | 171
merge_join
The merge join algorithm relies on ordered input. merge_join is most
valuable when input is ordered on the merge key — for example,
from an index scan; it is less valuable if sort operators are required to
order input.
merge_union_all
merge_union_all maintains the ordering of the result rows from the
union input. merge_union_all is particularly valuable if the input is
ordered and a parent operator (such as merge join) benefits from that
ordering. Otherwise, merge_union_all may require sort operators that
reduce efficiency.
merge_union_distinct
merge_union_distinct is similar to merge_union_all, except that
duplicate rows are not retained. merge_union_distinct requires
ordered input and provides ordered output.
multi_table_store_ind
multi_table_store_ind determines whether the query processor may
use reformatting on the result of a multiple table join. Using
multi_table_store_ind may increase the use of worktables.
opportunistic_distinct_view
opportunistic_distinct_view determines whether the query processor
may use a more flexible algorithm when enforcing distinctness.
parallel_query
parallel_query determines whether the query processor may use par-
allel query optimization.
172 | Chapter 5: Overview of Changes to the Query Processing Engine
hash_join
hash_join determines whether the Adaptive Server query processor
may use the hash join algorithm. Join queries that involve joining
columns without indexes, or with expressions, can suffer perfor-
mance penalties when used with table scans and nested loop joins. In
this case, hash join performs the join much more efficiently than the
nested loop join. However, performance of hash joins can be greatly
affected by the data cache size available.
Note: Optimization timeout at the server level will have impact on all
databases, and may not be the intent of the DBA when making perfor-
mance tweaks to a single query.
Chapter 5: Overview of Changes to the Query Processing Engine | 173
The output will show the “optimizer timed out” message. Following
is a part of the output from the above set option for a select query that
was joining nine tables. The optimization timeout limit was set to
10%.
...
...
------------------------------------------
Search Engine Statistics (Summary)
------------------------------------------
------------------------------------------
...
...
...
The best global plan (Pop tree):
------------------------------------------
Datatype Mismatch
If there is a join between two tables where the joining columns do not
match, then the query processor resolves the datatype mismatch inter-
nally and generates a plan with index scans. This will only happen if
the compatibility is allowed by the datatype conversion rules.
In the following example, the query is able to use an index even
though the join is on a mismatched column. The datatype of the col-
umn l_orderkey is double, whereas the datatype of o_totalprice is
integer.
select avg(o_totalprice), max(l_linenumber) from orders_mismatch,
lineitem where
orders_mismatch.o_totalprice = lineitem.l_orderkey and
orders_mismatch.o_totalprice >= 500.00
go
|RESTRICT Operator
|
| |SCALAR AGGREGATE Operator
| | Evaluate Ungrouped MAXIMUM AGGREGATE
| | Evaluate Ungrouped COUNT AGGREGATE
| | Evaluate Ungrouped SUM OR AVERAGE AGGREGATE
| |
| | |NESTED LOOP JOIN Operator (Join Type: Inner Join)
| | |
| | | |SCAN Operator
| | | | FROM TABLE
| | | | orders_mismatch
| | | | Index : order_x
| | | | Forward Scan.
| | | | Positioning by key.
| | | | Index contains all needed columns. Base table will not be
read.
| | | | Keys are:
| | | | o_totalprice ASC
| | | | Using I/O Size 2 Kbytes for index leaf pages.
| | | | With LRU Buffer Replacement Strategy for index leaf
pages.
| | |
| | | |RESTRICT Operator
| | | |
| | | | |SCAN Operator
| | | | | FROM TABLE
| | | | | lineitem
| | | | | Index : lineitem_x
| | | | | Forward Scan.
| | | | | Positioning by key.
| | | | | Keys are:
| | | | | l_orderkey ASC
| | | | | Using I/O Size 16 Kbytes for index leaf pages.
| | | | | With LRU Buffer Replacement Strategy for index leaf
pages.
| | | | | Using I/O Size 16 Kbytes for data pages.
| | | | | With LRU Buffer Replacement Strategy for data pages.
Figure 5-1
ROOT:EMIT Operator
|RESTRICT Operator
|
| |SCALAR AGGREGATE Operator
| | Evaluate Ungrouped COUNT AGGREGATE
| | Evaluate Ungrouped SUM OR AVERAGE AGGREGATE
| |
| | |NESTED LOOP JOIN Operator (Join Type: Inner Join)
| | |
| | | |SCAN Operator
| | | | FROM TABLE
| | | | lineitem_frequency
| | | | Index : lineitem_xf
| | | | Forward Scan.
| | | | Positioning by key.
| | | | Keys are:
| | | | l_orderkey ASC
| | | | Using I/O Size 16 Kbytes for index leaf pages.
| | | | With LRU Buffer Replacement Strategy for index leaf
pages.
| | | | Using I/O Size 16 Kbytes for data pages.
| | | | With LRU Buffer Replacement Strategy for data pages.
| | |
| | | |RESTRICT Operator
| | | |
| | | | |SCAN Operator
| | | | | FROM TABLE
| | | | | orders_frequency
Chapter 5: Overview of Changes to the Query Processing Engine | 181
| | | | | Index : order_xf
| | | | | Forward Scan.
| | | | | Positioning by key.
| | | | | Index contains all needed columns. Base table will
not be read.
| | | | | Keys are:
| | | | | o_orderkey ASC
| | | | | Using I/O Size 16 Kbytes for index leaf pages.
| | | | | With LRU Buffer Replacement Strategy for index leaf
pages.
or Queries
For queries involving ors, the optimizer can now select a new sort
avoidance/duplicate elimination technique called hash union distinct.
This plan avoids creating worktables. In the following example,
indexes are lineitem (l_orderkey) and lineitem (l_suppkey).
select l_orderkey, l_suppkey from lineitem
where l_orderkey between 1000 and 1500 or
l_suppkey <= 100
go
Star Queries
Star queries, which are very common in ODSS applications, are joins
between a large fact table and small dimension tables. ASE 15 can
quickly recognize star joins and generate efficient plans. The key
characteristic of an efficient plan for a star query is that the fact table
is accessed at the very end of the join order via the composite index,
and the dimension tables are joined in the order of the fact table’s
composite index. The statistics on the tables have to be up to date and
accurate for the optimizer to recognize the fact tables and dimension
tables.
In the following example, lineitem_fact is the fact table with a
composite index on (l_orderkey, l_partkey, l_suppkey). The plan
Chapter 5: Overview of Changes to the Query Processing Engine | 183
shows that the joins are between fact and dimension tables only and
there are no joins between dimensions.
select avg(l_extendedprice) from lineitem_fact,
orders_dim, part_dim, supplier_dim
where
lineitem_fact.l_partkey = part_dim.p_partkey and
lineitem_fact.l_orderkey = orders_dim.o_orderkey and
lineitem_fact.l_suppkey = supplier_dim.s_suppkey
and p_partkey < 8
and o_orderkey < 5
and s_suppkey < 3
| | | | p_partkey ASC
| | | | Using I/O Size 2 Kbytes for index leaf pages.
| | | | With LRU Buffer Replacement Strategy for index leaf
pages.
| | |
| | | |SCAN Operator
| | | | FROM TABLE
| | | | supplier_dim
| | | | Index : supplier_xd
| | | | Forward Scan.
| | | | Positioning by key.
| | | | Index contains all needed columns. Base table will not
be read.
| | | | Keys are:
| | | | s_suppkey ASC
| | | | Using I/O Size 2 Kbytes for index leaf pages.
| | | | With LRU Buffer Replacement Strategy for index leaf
pages.
| | |
| | | |RESTRICT Operator
| | | |
| | | | |SCAN Operator
| | | | | FROM TABLE
| | | | | lineitem_fact
| | | | | Index : lineitem_starcomp
| | | | | Forward Scan.
| | | | | Positioning by key.
| | | | | Keys are:
| | | | | l_orderkey ASC
| | | | | l_partkey ASC
| | | | | l_suppkey ASC
| | | | | Using I/O Size 2 Kbytes for index leaf pages.
| | | | | With LRU Buffer Replacement Strategy for index leaf
pages.
| | | | | Using I/O Size 2 Kbytes for data pages.
| | | | | With LRU Buffer Replacement Strategy for data pages.
Chapter 5: Overview of Changes to the Query Processing Engine | 185
Summary
ASE 15’s new features improve the performance of the data server
with minimal or no tuning of the query processing engine. The
improved performance not only reduces the hardware resources
required, but also decreases the time a DBA spends performance tun-
ing. This in turn lowers the total cost of ownership (TCO), the goal
most managers strive to achieve.
This page intentionally left blank.
Chapter 6: Detection and Resolution of Query Performance Issues | 187
Chapter 6
Introduction
This chapter focuses on the detection and resolution of performance
issues at the individual query level. Performance and tuning is a
broad topic and could fill an entire book. This chapter, however, will
focus on showplan messages and set option show query processor set
commands. In pre-ASE 15 terms, set option show is utilized to dis-
play optimizer diagnostics. The detection and resolution of
performance issues with some of the new features are explored. In
particular, an emphasis is on diagnosing situations with incorrect par-
tition strategies in an ASE server. Further, this chapter demonstrates
the importance of proper partition strategy with examples on how to
detect and resolve problems that are a direct result of selecting the
wrong partition key or the wrong partition type.
For Sybase ASE 15, the showplan output has evolved to a new for-
mat. This chapter uses the new formats and offers insight into the
ASE 15 showplan messages through example. Further, this chapter
offers areas of consideration within ASE and external to ASE that
should be analyzed prior to the diagnosis of a query issue within
ASE.
188 | Chapter 6: Detection and Resolution of Query Performance Issues
Note: The traditional dbcc traceflags such as 302 and 310 will be elimi-
nated by Sybase within the near future. It is advisable for database
administrators and privileged system users to become familiar with the
new set options in preparation for the pending elimination of the tradi-
tional dbcc traceflags used for optimizer debugging purposes.
Fragmentation of Data
Analyze the optdiag output on the key columns. Is fragmentation
reported? Look at the cluster ratios, forwarded rowcounts, and
deleted rowcounts in the optdiag output. Query the systabstats table
for fragmentation hints offered by the forwrowcnt and delrowcnt col-
umns. To remedy the problem, possibly drop/recreate clustered
indexes for single partition tables, or possibly drop and recreate local
indexes at the partition level for semantically partitioned tables. Use
bcp out/truncate/bcp in, or run the reorg commands to eliminate data
fragmentation.
Chapter 6: Detection and Resolution of Query Performance Issues | 193
Overengineered Forceplan
Remove instances of forced indexes from the query, and resubmit the
same query without the forceplan. Measure the performance differ-
ence between the forceplan execution and the execution with
forceplan disabled. Check whether the join order of tables is different
between the two executions. If the join order is different and perfor-
mance is better without the forceplan, this may be a sign to drop the
forceplan statement from the query.
Example:
dbcc traceon(3604)
go
set option show_histograms normal
go
Note: Despite the initiative to migrate away from the old numeric dbcc
trace commands for optimizer diagnostic output (and the potential
replacement of these dbcc commands), the new set options require
traceflag 3604 set to “on” for the results to return to the client. This is in
line with the “classic” optimizer debugging as it exists in previous
releases of ASE.
select o.name
from master..sysobjects o,
master..syscolumns c
where o.id = c.id
and c.name = "id"
go
Output:
DBCC execution completed. If DBCC printed error messages, contact a user
with System Administrator (SA) role.
name
sysobjects
sysindexes
198 | Chapter 6: Detection and Resolution of Query Performance Issues
syscolumns
.
.
.
Note: The weighting factors employed in the total cost formula are not
configurable.
show_missing_stats
The set option of show_missing_stats is used to return a message to
indicate if the optimizer determines that a column has optimization
potential. In order for this message to appear, no statistics or densities
can be available for this column. When the optimizer recognizes this
situation, a message can be returned to the user’s screen or to the
errorlog, depending on the traceflag settings.
The set option of show_missing_stats, even with long specified
as the display option, only shows hints of where the optimizer could
have used stats. In the following example, the optimizer indicates sta-
tistics would be beneficial on the code column of the customers table.
1> dbcc traceon(3604)
2> go
DBCC execution completed. If DBCC printed error messages, contact a user
with System Administrator (SA) role.
1> set option show_missing_stats long
2> go
Chapter 6: Detection and Resolution of Query Performance Issues | 201
(1 row affected)
Emit
(VA = 1)
1 rows est: 6000
cpu: 0
/
TableScan
OrderTracking..customers
(VA = 0)
1 rows est: 6000
lio: 268 est: 1100
pio: 0 est: 138
============================================================
(1 row affected)
202 | Chapter 6: Detection and Resolution of Query Performance Issues
Update the statistics on the code column and reissue the same com-
mand. Our estimate of rows returned by the optimizer drops from
6000 to 2. A “missing stats” problem has been successfully solved
with this simple example.
1> select * from OrderTracking..customers where code = 30000
2> go
Emit
(VA = 1)
1 rows est: 2
cpu: 0
/
TableScan
OrderTracking..customers
(VA = 0)
1 rows est: 2
lio: 268 est: 1100
pio: 0 est: 138
============================================================
(1 row affected)
Note: It should be noted the estimated row counts would have been
estimated more inaccurately if the underlying table did not employ the
range partition strategy on the code column. The partition awareness of
the ASE 15 optimizer eliminated three unqualified partitions according to
the showplan output, thus offering an advantage over the same query
issued against a non-partitioned table containing the exact same data:
ROOT:EMIT Operator
|SCAN Operator
| FROM TABLE
| OrderTracking..customers
| [ Eliminated Partitions : 1 3 4 ]
| Table Scan.
| Forward Scan.
| Positioning at start of table.
| Using I/O Size 16 Kbytes for data pages.
| With LRU Buffer Replacement Strategy for data pages.
show_elimination
The set option of show_elimination is useful for reviewing the steps
taken by the ASE 15 query processor to eliminate semantic partitions
from consideration by the query. With this diagnostic command, par-
tition elimination can be verified by the database administrator.
Consider the following query:
select effectiveDate, count(*)
from customers
where code = 30004
or (code < 42000
and code > 41000)
group by effectiveDate
order by 2 desc
Showplan excerpt:
| | | |SCAN Operator
| | | | FROM TABLE
| | | | brian
| | | | [ Eliminated Partitions : 1 2 4 ]
| | | | Table Scan.
| | | | Forward Scan.
| | | | Positioning at start of table.
| | | | Using I/O Size 16 Kbytes for data pages.
show_abstract_plan
The set option of show_abstract_plan is used to generate an abstract
plan for a query. This plan can then be extracted from the show_
abstract_plan output and used as a starting point for query tuning
with abstract plans. The following example demonstrates how to gen-
erate an abstract plan with the set option:
Chapter 6: Detection and Resolution of Query Performance Issues | 205
dbcc traceon(3604)
go
set option show_abstract_plan long
go
select d.Name
from Distribution d,
Extension e
where d.distributionID = e.distributionID
and d.market = (select max(d2.market)
from Distribution d2
where d2.distributionID = d.distributionID)
go
Output:
The abstract plan (AP) of the final query execution plan:
( nested
( m_join
( i_scan Distribution_1CUP
( table ( d Distribution ) ) )
( i_scan Extension_1NUP
( table ( e Extension ) ) ) )
( subq
( scalar_agg
( i_scan Distribution_1CUP
( table ( d2 Distribution ) ) ) ) ) )
( prop
( table ( d Distribution ) )
( parallel 1 )
( prefetch 16 )
( lru ) )
( prop
( table ( e Extension ) )
( parallel 1 )
( prefetch 16 )
( lru ) )
( prop
( table ( d2 Distribution ) )
( parallel 1 )
( prefetch 2 )
( lru ) )
To experiment with the optimizer behavior, this AP can be modified and then
passed to the optimizer using the PLAN clause:
SELECT/INSERT/DELETE/UPDATE ... PLAN '( ... )
206 | Chapter 6: Detection and Resolution of Query Performance Issues
As the above message indicates, the abstract plan acquired from the
set option show_abstract_plan can be passed to the optimizer at
query execution with the plan clause. Thus, the database administra-
tor can modify the abstract query plan, where appropriate, and
resubmit it to the ASE server.
Note: It is possible the DBA-modified abstract query plan may not per-
form as efficiently as the optimizer-generated query plan.
Below, the same query is submitted with the abstract plan that was
captured by show_abstract_plan. As an example, one of the join
methods is changed from merge join to hash join in the abstract plan.
Note: The quotes around the abstract plan text in the proceeding query
are required in order to submit an abstract query plan.
select d.Name
from Distribution d,
Extension e
where d.distributionID = de.distributionID
and d.market = (select max(d2.market)
from Distribution d2
where d2.distributionID = d.distributionID)
PLAN '( nested
( h_join
( i_scan Distribution_1CUP
( table ( d Distribution ) ) )
( i_scan Extension_1NUP ( table (e Extension ) ) ) )
( subq
( scalar_agg
( i_scan Distribution_1CUP
( table ( d2 Distribution ) ) ) ) ) )
( prop ( table ( d Distribution ) )
( parallel 1 )( prefetch 16 ) ( lru ) )
( prop ( table ( e Extension ) )
( parallel 1 ) ( prefetch 16 ) ( lru ) )
( prop ( table ( d2 Distribution ) )
( parallel 1 ) ( prefetch 2 ) ( lru ) )'
go
( i_scan Event_1CUP
( table ( e2 Event ) ) ) ) ) ) )
( sort
( i_scan Event_7NNX
( table ( le Event ) ) ) ) )
( prop ( table ( el EventList ) )
( parallel 1 ) ( prefetch 2 ) ( lru ) )
( prop ( table ( e2 Event ) )
( parallel 1 ) ( prefetch 16 ) ( lru ) )
( prop ( table ( e Event ) )
( parallel 1 ) ( prefetch 16 ) ( lru ) )"
query plan from the first example has no optimization timeout limit
while the query in the second example does have an optimization
timeout limit.
The query with opttimeoutlimit set to 1 chose a table scan over an
index scan and does not take advantage of partition elimination on
the second table in this example. With the optimization timeout left at
the default value of 10, the optimizer selects a more efficient query
plan since the optimizer had more time to consider additional query
plans.
No opttimeoutlimit:
QUERY PLAN FOR STATEMENT 1 (at line 1).
15 operator(s) under root
The type of query is SELECT.
ROOT:EMIT Operator
|SQFILTER Operator has 2 children.
|
| |N-ARY NESTED LOOP JOIN Operator has 5 children.
| |
| | |MERGE JOIN Operator (Join Type: Inner Join)
| | | Using Worktable1 for internal storage.
| | | Key Count: 1
| | | Key Ordering: ASC
| | |
| | | |SCAN Operator
| | | | FROM TABLE
| | | | customers
| | | | c1
| | | | [ Eliminated Partitions : 2 3 4 ]
| | | | Index : customers_idx3
| | | | Forward Scan.
| | | | Positioning by key.
| | | | Keys are:
| | | | code ASC
| | | | Using I/O Size 2 Kbytes for index leaf pages.
| | | | With LRU Buffer Replacement Strategy for index leaf
pages.
| | | | Using I/O Size 2 Kbytes for data pages.
| | | | With LRU Buffer Replacement Strategy for data pages.
| | |
| | | |SCAN Operator
| | | | FROM TABLE
| | | | authors
| | | | a1
214 | Chapter 6: Detection and Resolution of Query Performance Issues
Set opttimeoutlimit to 1:
QUERY PLAN FOR STATEMENT 1 (at line 1).
16 operator(s) under root
The type of query is SELECT.
ROOT:EMIT Operator
|SQFILTER Operator has 2 children.
|
| |N-ARY NESTED LOOP JOIN Operator has 5 children.
| |
| | |MERGE JOIN Operator (Join Type: Inner Join)
| | | Using Worktable2 for internal storage.
| | | Key Count: 1
| | | Key Ordering: ASC
| | |
| | | |SCAN Operator
| | | | FROM TABLE
| | | | customers
| | | | c1
| | | | [ Eliminated Partitions : 2 3 4 ]
| | | | Index : customers_idx3
| | | | Forward Scan.
| | | | Positioning by key.
| | | | Keys are:
| | | | code ASC
| | | | Using I/O Size 2 Kbytes for index leaf pages.
| | | | With LRU Buffer Replacement Strategy for index leaf
pages.
| | | | Using I/O Size 2 Kbytes for data pages.
| | | | With LRU Buffer Replacement Strategy for data pages.
| | |
| | | |SORT Operator
| | | | Using Worktable1 for internal storage.
Chapter 6: Detection and Resolution of Query Performance Issues | 215
| | | |
| | | | |SCAN Operator
| | | | | FROM TABLE
| | | | | authors
| | | | | a1
| | | | | Table Scan.
| | | | | Forward Scan.
| | | | | Positioning at start of table.
| | | | | Using I/O Size 16 Kbytes for data pages.
| | | | | With LRU Buffer Replacement Strategy for data pages.
Customers Table
Partition p1 Partition p2 Partition p3 Partition p4
15000
rows
115000
rows
155000 165000
rows rows
Figure 6-1
Chapter 6: Detection and Resolution of Query Performance Issues | 219
Obviously, for any query that accesses data mapped to partition p4,
query performance will exceed the performance of a query accessing
partitions p1, p2, or p3. However, since partition p4 represents only a
small percentage of the data, and likely a small percentage of any
data access operations, most queries will perform less optimally. The
partition strategy results in data skew, which should be avoided in
most situations with partitioned data. To remedy any query perfor-
mance issues due to partition imbalance, consider altering the
partition key or modification of the partition type. One option is to
consider a replacement partition key. A possible replacement is the
effectiveDate column of the table. Here, activity would be directed to
a partition based on the date of activity, and not the customer ID. To
remedy query performance issues here, a hash-based partition is
employed to better balance the data across partitions.
To change the partition strategy to hash, first the table partitions
must be combined. This is done by altering the partition type to
round-robin with partition degree of 1:
alter table customers partition by roundrobin 1
Then alter the table to hash partition with a partition degree of 4. The
hashkey of the code column is acceptable to achieve a partition bal-
ance due to the uniqueness of the data in this column:
alter table customers partition by hash(code)
(p1,p2,p3,p4)
After the alter table is complete, the partitions are more balanced as
depicted in Figure 6-2:
Customers Table (hash)
Partition p1 Partition p2 Partition p3 Partition p4
112000 110000
115000 rows 113000
rows rows
rows
Figure 6-2
220 | Chapter 6: Detection and Resolution of Query Performance Issues
Diagnostic output:
==================== Lava Operator Tree ====================
Emit
(VA = 4)
1 rows est: 12
cpu: 1600
/
SQFilter
(VA = 3)
1 rows est: 12
/ \
IndexScan ScalarAgg
brian_idx3 (a1) Max
(VA = 0) (VA = 2)
100001 rows est: 12 1 rows est: 1
lio: 6999 est: 9 cpu: 600
pio: 0 est: 9
/
IndexScan
brian_idx3 (a2)
(VA = 1)
Chapter 6: Detection and Resolution of Query Performance Issues | 221
For this example, the number of expected, scanned rows with the use
of index brian_idx3 is 12, while the actual rows scanned were
100,001. Similarly, the logical I/O (lio) for the scan of brian_idx3
was estimated at 9, while the actual I/O measurement was 6,999.
Since the optimizer relies upon statistics to make assumptions
about data, invalid or old statistics can cause the optimizer to make
poor query plan selections.
After the statistics were updated on the tables in the above exam-
ple, observe the estimated rowcounts and I/O estimates are more
inline with the actual counts. Additionally, the optimizer chose a dif-
ferent, and more efficient, plan. Note the change to the table scan
below where the optimizer recognized a greater efficiency to perform
the table scan with improved statistics information. Finally, the total
query execution time decreased by 12.5% in this example.
==================== Lava Operator Tree ====================
Emit
(VA = 4)
1 rows est: 100002
cpu: 1400
/
SQFilter
(VA = 3)
1 rows est: 100002
/ \
TableScan ScalarAgg
brian (a1) Max
(VA = 0) (VA = 2)
100001 rows est: 100002 1 rows est: 1
lio: 4693 est: 11847 cpu: 600
pio: 0 est: 1366
/
IndexScan
brian_idx3 (a2)
(VA = 1)
222 | Chapter 6: Detection and Resolution of Query Performance Issues
Summary
The detection and resolution of query-level problems in any rela-
tional database system can often be considered an art and not an
exact science. The steps to detect and resolve problems in this chap-
ter are the steps the authors have utilized to detect and resolve
query-level problems with ASE on version 15 and prior. Many data-
base administrators utilize their own methodology to detect and
resolve problems within ASE. This chapter’s purpose is to help the
database administrator become more aware of the tools available in
the ASE 15 release, and build an awareness of the performance issues
that can be caused with the improper application of some of the new
optimization tools. The chapter also helps to build familiarity through
application of the new ASE diagnostic utilities set options and statis-
tics plancost.
This page intentionally left blank.
Chapter 7: Computed Columns | 225
Chapter 7
Computed Columns
Introduction
Computed columns are columns that are defined by an expression.
This expression can be built by combining regular columns in the
same row and may contain functions, arithmetic operators, case
expressions, global variables, Java objects, and path names.
For example:
create table parts_table
(part_no int,
name char(30),
list_price money,
quantity int,
total_cost compute quantity*list_price
)
226 | Chapter 7: Computed Columns
Key Concepts
Materialization and deterministic characteristics are important con-
cepts to understand. These concepts affect the behavior of the
computed columns.
Materialization
Materialized columns are preevaluated and stored in the table when
base columns are inserted or updated. The values associated with the
computed columns are stored in both the data row and the index row.
Any subsequent access to a materialized column does not require
reevaluation; its preevaluated result is accessed.
Columns that are not materialized are also called virtual col-
umns; virtual columns become materialized when they are accessed.
If a column is virtual, or not materialized, its result value must be
evaluated each time the column is accessed. This means that if the
virtual computed column expression is based on, or calls, a
nondeterministic expression, it may return different values each time
you access it. You may also encounter run-time exceptions, such as
domain errors, when you access virtual computed columns. The con-
cept of nonmaterialized columns is similar to “views,” where the
definition of the view is evaluated each time the view is called.
A materialized column is reevaluated only when one of its base
columns is updated. A nonmaterialized, or virtual, computed column
becomes a materialized computed column once it is used as an index
key.
Chapter 7: Computed Columns | 227
Deterministic Property
A deterministic algorithm will always produce the same output for a
given set of inputs. Expressions and functions using deterministic
algorithms exhibit a deterministic property. On the other hand,
nondeterministic expressions may return different results each time
they are evaluated, even when they are called with the same set of
input values.
A good example of a nondeterministic function is the getdate()
function. It always returns the current date, which is different each
time the function is executed. Any expression built on a nondeter-
ministic function will also be nondeterministic. For example, age
(getdate() minus date of birth) will also be nondeterministic. Also, if
a function’s return value depends on factors other than input values,
the function is probably nondeterministic. A nondeterministic func-
tion need not always return a different value for the same set of
inputs. It just cannot guarantee the same result each time.
The following example illustrates the deterministic property:
create table Employee
(emp_id int,
emp_name varchar(30),
formatted_name compute upper(emp_name),
date_of_birth datetime,
emp_age compute datediff(year,
date_of_birth, getdate()))
Deterministic Nondeterministic
Materialized Deterministic and Nondeterministic and
materialized materialized
Nonmaterialized Deterministic and Nondeterministic and
nonmaterialized nonmaterialized
This statement always returns the same result if the data in the table
does not change.
230 | Chapter 7: Computed Columns
When a row is selected from the above table, the value of start_date
will be the datetime when the row was inserted and not the datetime
of the select statement.
Each time you insert a new XML document into the table, the docu-
ment’s relational elements are automatically extracted into the
materialized columns. Or, to present the relational data in each row as
an XML document, specify mapping the relational data to an XML
document using a computed column in the table definition. For
example, define a table:
create table order
(order_no int,
part_no int,
quantity smallint,
customer varchar(50))
The following query then returns the result in the customized format:
select name, part_no, listPrice from parts_table order by
name_in_myorder
(1 row affected)
Column_name Type Length Prec Scale Nulls Default_name Rule_name
Access_Rule_name Computed_Column_object Identity
-------------- -------- ----------- ---- ----- ----- ------------ ---------
formatted_name varchar 30 NULL NULL 1 NULL NULL
NULL Employee_format_832002964 (virtual) 0
date_of_birth datetime 8 NULL NULL 0 NULL NULL
NULL NULL 0
emp_age int 4 NULL NULL 1 NULL NULL
NULL Employee_emp_ag_848003021 (virtual) 0
Column_Name Property
-------------- --------
formatted_name virtual
Text
-------------------
AS upper(emp_name)
Column_Name Property
----------- --------
emp_age virtual
Text
--------------------------------------------
AS datediff(year, date_of_birth, getdate())
Column_Name Property
-------------- --------
formatted_name virtual
Text
-------------------
AS upper(emp_name)
Column_Name Property
----------- --------
emp_age virtual
Text
--------------------------------------------
AS datediff(year, date_of_birth, getdate())
Summary
Computed columns make it easier and faster to access and manipu-
late data, and they help improve performance by providing the ability
to index an expression. They can be used to add clarity to the applica-
tion code because of their ability to compose and decompose
complex datatypes and to transform data into different formats.
Materialization and deterministic properties are important con-
cepts for computed columns. A materialized column is evaluated and
stored in the table when the base column is inserted or modified,
whereas the nonmaterialized column is evaluated at the time of data
retrieval.
A function has a deterministic property if it produces the same
output every time for a given set of inputs; otherwise, it is a
nondeterministic function. The date function is an example of a
nondeterministic function.
The computed column feature of ASE 15 not only helps reduce
the complexity of the system but also increases performance. When
this feature is used in conjunction with XML in the database, it opens
up new application designs.
This page intentionally left blank.
Chapter 8: Functional Indexes | 241
Chapter 8
Functional Indexes
Both examples contain join predicates on either side of the “=” oper-
and. In the case of a computed column index, the join predicate
TableB.ColumnB * 4 would be replaced by its computed column
(i.e., TableB.ComputedColumnB is the same as TableB.ColumnB *
4), and this computed column would also have an index defined
using the computed column.
Because these types of indexes contain predetermined join predi-
cates, the optimizer does not have to include the costs associated with
resolving the join during execution.
Materialized and nonmaterialized data have to be of concern
when considering the use of either type of index. As will be noted
later in the chapter, the materialization state of the data that is being
considered for the index may determine the type of index and the
behavior of the index. The reader should pay close attention to the
materialization requirements of each type of index when deciding to
use either computed column indexes or function-based indexes.
Purpose
A computed column index is an index created on a computed col-
umn. This type of index is useful for derived data columns that are
frequently used in where conditions. In cases where the value of the
search argument has to be derived before the query can be resolved,
this type of index uses preresolved data for the search argument.
Unlike computed columns where the data can be evaluated at access
time, the index on a computed column is evaluated when the row is
inserted into the table. This allows the optimizer to utilize an index
instead of creating a temporary table to resolve the query. The end
result is faster data access.
The syntax for creating a computed column index is the same as
any other index created using an earlier version of Sybase ASE.
What is different is the use of a computed column to be listed as a
column-name on which the index can be built.
Chapter 8: Functional Indexes | 243
Syntax:
create [unique] [clustered | nonclustered]
index index_name
on [[database.]owner.]table_name
(column_name [asc | desc]
[, column_name [asc | desc]]...}
(column_expression [asc | desc]
[, column_expression [asc | desc]]...)
with { fillfactor = percent
, max_rows_per_page = num_rows
, reservepagegap = num_pages
, consumers = x
, ignore_dup_key
, sorted_data
, [ignore_dup_row | allow_dup_row]
, statistics using num_steps values }]
[on segment_name]
[local index [partition_name [on segment_name]
[,[partition_name [on segment_name]...]
the data pages. set showplan on and set statistics io on were used for
these examples.
Exhibit 1:
=======================================================
select count(*) from Rental where datediff(dd, RentalDate, getdate()) > 15
<== Without Index
=======================================================
QUERY PLAN FOR STATEMENT 1 (at line 1).
ROOT:EMIT Operator
-----------
2400
Table: Rental scan count 1, logical reads: (regular=90 apf=0 total=90),
physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Total writes for this command: 0
(1 row affected)
Exhibit 2:
create clustered index rental_idx
on dbo.rental (DaysOfRental)
with allow_dup_row
Chapter 8: Functional Indexes | 245
Exhibit 3:
==================================================================
select count(*) from Rental where DaysOfRental > 15 <== With Index
==================================================================
STEP 1
The type of query is SET STATISTICS ON.
ROOT:EMIT Operator
-----------
2400
Table: Rental scan count 1, logical reads: (regular=76 apf=0 total=76),
physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Total writes for this command: 0
(1 row affected)
246 | Chapter 8: Functional Indexes
Feature Benefits
Computed column indexes are most beneficial in cases where the
value of a search argument must be resolved prior to the query results
being returned to the request. By resolving the value prior to query
optimization, the optimizer has the ability to evaluate query access
paths and costing options that utilize indexes. If the computed
Chapter 8: Functional Indexes | 247
column index did not exist, the only option available to the optimizer
is to create a worktable where the search criteria must be resolved
prior to the full resolution of the where clause.
Computed column indexes offer the database administrator a
method for indexing derived data that was previously unavailable. In
cases where the derived data would normally be in the selection crite-
ria, the optimizer would be able to determine that an index exists.
Ultimately, this would reduce the amount of I/O, disk, and memory
required to resolve the query. Since the selection can be executed
using the index, physical I/O necessary to read the data page into
memory would be replaced by physical I/O for index pages contain-
ing more information per page. In the case where the index was also
a covering index (an index where all of the columns specified in the
select and where clauses for a particular table are found in the index
definition), the data page would not be read into memory. As data is
read into memory and interrogated to determine if it meets the selec-
tion criteria, accepted data is stored in worktables. Since the data for
a computed column is on the index page, no worktable would be
required. With the reduction of physical and logical I/O, the direct
result of using a computed column index is a decrease in response
time, which is seen as an improvement in performance.
Example:
create table Rental
(cust_id int,
RentalDate as getdate() materialized,
PropertyID int,
DaysOfRental compute datediff(dd,RentalDate,getdate()) materialized)
select cust_id
from Rental
where cust_id > 100
and DaysOfRental > 30
ROOT:EMIT Operator
|SCAN Operator
| FROM TABLE
248 | Chapter 8: Functional Indexes
| Rental
| Index : CoveringIndex
| Forward Scan.
| Positioning by key.
| Index contains all needed columns. Base table will not be read.
| Keys are:
| cust_id ASC
| DaysOfRental ASC
| Using I/O Size 16 Kbytes for index leaf pages.
| With LRU Buffer Replacement Strategy for index leaf pages.
(0 rows affected)
Feature Limitations
For a computed column index, there is a restriction that the data of
the computed column must be materialized at the time of the index
row creation. This is true even if the computed column was not
defined as materialized. This implies that if the value of the indexed
computed column changes, the index will also change. This, how-
ever, is not the case. The index row is created at the time of the
materialization of the data. When an update occurs to the computed
column, the materialized data in the index does not change.
Impacts to tempdb
Computed column indexes have no additional impact on the use of
tempdb during the index’s normal use. However, utilization of a
computed column index can decrease the tempdb space used for join
resolution. Computed column indexes would reduce the number and
size of temporary worktables.
Chapter 8: Functional Indexes | 249
Once the candidate code has been identified and the computed col-
umn index created, the where criteria must be modified to include the
computed column in order for the index to be utilized. If the com-
puted column is not specifically referenced, the index will not be
used simply because you created an index on the expression. In order
to utilize an expression, see the following section called “Function-
based Index.”
Example:
create table Rental
(cust_id int,
RentalDate as getdate() materialized,
PropertyID int,
DaysOfRental compute datediff(dd,RentalDate,getdate()) materialized)
The first select statement is not aware that an index exists on the cri-
teria specified in the where clause. The second statement specifies
the computed column on which the index had been built. In the
Chapter 8: Functional Indexes | 251
Optimizer Statistics
Just as any other column that comprises an index, computed columns
that are used to create an index need to have update statistics per-
formed on them on a regular basis. However, since a computed
column index is based on materialized data, update statistics needs to
be executed when certain criteria are met: 1) a large number of rows
affecting the computed column change, or 2) a large number of
inserts have occurred since the previous update statistics. It is up to
the database administrator to know when the update statistics needs
to be executed.
Function-based Index
Purpose
The function-based index has been an industry feature for several
years in other vendors’ products. The concept of a function-based
index was first introduced in 1994 as a performance optimization for
object-oriented databases. The concept was based on the utilization
of a function in order to improve join performance. In ASE 15, the
feature is implemented to compete with other products on the market
that currently have this feature.
A function-based index should be used where preresolved search
criteria can benefit a slow or long-running query. The function-based
index is an index based on a function of the search criteria. The
optimizer would be able to utilize an index instead of resolving the
search criteria at execution time.
Syntax:
create [unique] [clustered | nonclustered]
index index_name
on [[database.]owner.]table_name
(column_name [asc | desc]
[, column_name [asc | desc]]...}
(column_expression [asc | desc]
252 | Chapter 8: Functional Indexes
Feature Benefits
Function-based indexes, like computed column indexes, are
preresolved data. Given the following search criteria:
where customerID > 100
and DaysOfRental > 90
a function-based index can be created that can be utilized by the
optimizer as if the search criteria were based simply upon another
column in the table.
The following example creates a function-based index:
create table Rental
(cust_id int
, RentalDate datetime
, PropertyID int
, RentalRate int
, DaysOfRental compute datediff(dd,RentalDate,getdate()) materialized
, StartOfRental as getdate() materialized
)
index. Exhibit 7 is the resulting showplan that indicates the index was
selected to resolve the query. The number of I/Os in this showplan
was 25. The difference in the number of reads is the result of scan-
ning only the index pages vs. scanning all of the data pages. It should
be noted that this index was considered a covering index because the
columns defined in the function, and the subsequent index, were the
only columns specified in the SQL. Since the index was considered a
covered index, the resulting data was read from the index pages
instead of index and data pages. set showplan on and set statistics io
on were used for these examples.
Exhibit 5:
===========================================================================
select count(*) from Rental where PropertyID*RentalRate/3 > 180 <== Without
Index
===========================================================================
ROOT:EMIT Operator
-----------
2800
Chapter 8: Functional Indexes | 255
Exhibit 6:
====================================================================
create index rental_fbi_idx on dbo.rental (PropertyID*RentalRate/3)
====================================================================
Exhibit 7:
========================================================================
select count(*) from Rental where PropertyID*RentalRate/3 > 180 <== With
Index
========================================================================
ROOT:EMIT Operator
-----------
3000
256 | Chapter 8: Functional Indexes
(1 row affected)
Feature Limitations
For a function-based index there is a restriction that the functions that
are used to create the index must return the same result whenever it is
referenced. This property is also called deterministic. For example,
the expression “UnitPrice * QuantityOrdered” will always provide
the same answer when queried. However, getdate() returns a differ-
ent result every time it is referenced. This implies that if the
underlying data value of the function-based index changes, the results
may be inconsistent.
Function-based indexes cannot contain subqueries, local vari-
ables, or aggregate functions. Each of these criteria is considered to
be nondeterministic.
Probably the most important limitation or concern you might
think that you will have involves index maintenance. This is because
the values on which the index is created are stored in the index pages
at index creation. Sybase has addressed this concern for you and
therefore it is not an issue. If the values of the base components on
which the index is based change, the index will be updated to reflect
the base data change. For all insert, delete, and update operations,
ASE automatically updates the function-based index without any user
intervention. This behavior is new to ASE 15.
Function-based indexes cannot be clustered. Although this may
be considered for a future release of ASE, it is a limitation in the cur-
rent release.
Impacts to tempdb
Function-based indexes have a beneficial effect on tempdb usage.
Since the search criteria are predetermined, worktables are not neces-
sary for data evaluation in complex queries. The worktables were
previously used to hold temporary result sets while other data was
being read. The data would then be compared, sorted, and/or merged
to return the final result set. The function-based index avoids the
Chapter 8: Functional Indexes | 257
Optimizer Statistics
As with any other type of index, the statistics for a function-based
index need to be initialized following the creation of the index. The
database administrator will be responsible for determining the
requirements for updating the statistics.
t sysindexes — The table will now contain one row for each com-
puted column index or function-based index associated with the
base table. An internal status of hex: 0x8000, decimal 32768 has
been added to the domain for the status2 field to indicate that the
index is a function-based index.
Summary
The main objective of functional indexes is to provide the optimizer
with pre-processed data that can be used in where clauses. Both com-
puted column and function-based indexes are created by the database
administrator after determining that certain long-running queries can
benefit from one or both types of indexes. Although there are several
restrictions when defining and maintaining these types of indexes,
their benefit to DSS application and batch processing can quickly
compensate for the minimal overhead required to support them.
This page intentionally left blank.
Chapter 9: Capturing Query Processing Metrics | 261
Chapter 9
Contents of sysquerymetrics
As mentioned earlier, sysquerymetrics is a view, not a table. This
view is comprised of two instances of the sysqueryplans table from
within the same database, joined via a self join. For those of us who
enjoy complex view syntax, below is the view creation syntax, fol-
lowed by a column-level description of the sysquerymetrics view:
create view sysquerymetrics
(uid, gid, hashkey, id, sequence, exec_min, exec_max, exec_avg, elap_min,
elap_max, elap_avg, lio_min, lio_max, lio_avg, pio_min, pio_max,
pio_avg, cnt, abort_cnt, qtext)
as select a.uid, -a.gid, a.hashkey, a.id, a.sequence,
convert(int, substring(b.text, charindex('e1', b.text) + 3,
charindex('e2', b.text) - charindex('e1', b.text) - 4)),
convert(int, substring(b.text, charindex('e2', b.text) + 3,
charindex('e3', b.text) - charindex('e2', b.text) - 4)),
convert(int, substring(b.text, charindex('e3', b.text) + 3,
charindex('t1', b.text) - charindex('e3', b.text) - 4)),
convert(int, substring(b.text, charindex('t1', b.text) + 3,
charindex('t2', b.text) - charindex('t1', b.text) - 4)),
convert(int, substring(b.text, charindex('t2', b.text) + 3,
charindex('t3', b.text) - charindex('t2', b.text) - 4)),
convert(int, substring(b.text, charindex('t3', b.text) + 3,
charindex('l1', b.text) - charindex('t3', b.text) - 4)),
convert(int, substring(b.text, charindex('l1', b.text) + 3,
charindex('l2', b.text) - charindex('l1', b.text) - 4))
convert(int, substring(b.text, charindex('l2', b.text) + 3,
charindex('l3', b.text) - charindex('l2', b.text) - 4)),
convert(int, substring(b.text, charindex('l3', b.text) + 3,
charindex('p1', b.text) - charindex('l3', b.text) - 4)),
convert(int, substring(b.text, charindex('p1', b.text) + 3,
charindex('p2', b.text) - charindex('p1', b.text) - 4)),
convert(int, substring(b.text, charindex('p2', b.text) + 3,
charindex('p3', b.text) - charindex('p2', b.text) - 4)),
convert(int, substring(b.text, charindex('p3', b.text) + 3,
charindex('c', b.text) - charindex('p3', b.text) - 4)),
convert(int, substring(b.text, charindex('c', b.text) + 2,
charindex('ac', b.text) - charindex('c', b.text) - 3)),
264 | Chapter 9: Capturing Query Processing Metrics
Stored Procedures
Unlike the SQL generated by batch SQL statements, the SQL gener-
ated by stored procedures is not automatically flushed from memory
by the QP Metrics process. In order to flush the QP Metrics informa-
tion from stored procedures, it is necessary to manually flush the
plans and metric information from memory into the tables that under-
lie the sysquerymetrics view. To flush the QP Metrics data relevant
to stored procedure execution, execute the sp_metrics system proce-
dure with the flush command:
sp_metrics "flush"
After the sp_metrics are flushed, the stored procedure syntax cap-
tured into the sysquerymetrics view will not contain the exec
statement nor the values passed into the parameters for the stored
procedure. Rather, the SQL statement from within the stored proce-
dure will be present within the sysquerymetrics view. For the
parameters, you will see a local variable within the “qtext” section of
the sysquerymetrics view.
Here is a quick example of what to expect in the qtext column of
the sysquerymetrics view for a stored procedure where parameters
are utilized:
select qtext from sysquerymetrics
go
qtext
-------
update Rental set tenant_name = @new_name where tenant_name =
@old_name
select @tenant_name = @new_name from Rental where tenant_name =
@new_name
Chapter 9: Capturing Query Processing Metrics | 267
go
268 | Chapter 9: Capturing Query Processing Metrics
Text Captured
create procedure querymetrics_demo @authors int N
as N
/************************************************************************ N
** Name: querymetrics_demo N
** N
** Purpose: Stored Procedure to demonstrate how stored procedure N
** text is captured by QP Metrics. N
** N
** Parameters: Input: @authors - unique authorID N
** N
** Output Params: NONE. N
** N
** Example Use: exec @return = querymetrics_demo 10000 N
** N
** Residing Database: userDatabase N
** N
**********************************************************************************/ N
declare @error int, N
@message varchar(255), N
@procedure varchar(30), N
@return int N
N
select identification, code, status, effectiveDate Y
from authors Y
where code = @authors Y
N
select @error = @@error N
if (@error != 0) N
begin N
select @message = @procedure + ": returned error " + N
convert(varchar(6),@error) + ", selecting author information." N
raiserror 99999 @message N
select @return = 2 N
return @return N
end N
N
go N
Chapter 9: Capturing Query Processing Metrics | 269
As demonstrated, only the query text from the portion of the stored
procedure that is executed and that references a table is captured.
Neither the comments nor the variable assignments are captured.
Additionally, if the error checking portion of the code were executed,
the text from the error checking section would not be captured as the
error checking in this example does not reference a table or view.
Now consider the same stored procedure, but hide the stored pro-
cedure text with the sp_hidetext command.
sp_hidetext "querymetrics_demo"
go
set metrics_capture on
go
exec querymetrics_demo 30000
go
sp_metrics "flush"
go
Text Captured
create procedure querymetrics_demo @authors int N
as N
/************************************************************************ N
** Name: querymetrics_demo N
** N
** Purpose: Stored Procedure to demonstrate how stored procedure N
** text is captured by QP Metrics. N
** N
** Parameters: Input: @authors - unique authorID N
** N
** Output Params: NONE. N
** N
** Example Use: exec @return = querymetrics_demo 10000 N
** N
** Residing Database: userDatabase N
** N
**********************************************************************************/ N
declare @error int, N
@message varchar(255), N
@procedure varchar(30), N
@return int N
N
select identification, code, status, effectiveDate Y
from authors Y
where code = @authors Y
N
select @error = @@error N
if (@error != 0) N
begin N
select @message = @procedure + ": returned error " + N
convert(varchar(6),@error) + ", selecting author information." N
raiserror 99999 @message N
select @return = 2 N
270 | Chapter 9: Capturing Query Processing Metrics
Text Captured
return @return N
end N
N
go N
Execute Immediate
Earlier we indicated that for stored procedures, parameters and vari-
ables utilized within the procedure will not be displayed. We also
mentioned that all SQL generated within a stored procedure must be
flushed with the sp_metrics system procedure before the data will
appear in the sysquerymetrics view. There is one exception, however,
in that SQL generated within a stored procedure with the “execute
immediate” command will materialize into the QP Metrics data with
the values for the parameters displayed. Additionally, stored proce-
dures with the “execute immediate” command will not need to
“flush” the SQL from memory in order to materialize the data into
the sysquerymetrics view. The following stored procedure example
has embedded comments to demonstrate which SQL statements will
automatically materialize into the sysquerymetrics view and which
will require the sp_metrics flush command:
Chapter 9: Capturing Query Processing Metrics | 271
-- Flush Required:
select "hello non immediate" from Rental where 1 = 2
Results:
Total
8848
Cnt qtext
Tempdb 1 select "Total" = count(*) from Properties..Rental
cnt qtext
properties 1 delete from sysqueryplans where gid = - @gid
Note from the results above, the qtext column in the tempdb database
contains the query text issued against the Rental table in the Prop-
erties database. It is important to note how ASE 15 stores the SQL
call against a table in the Properties database into the calling data-
base’s sysquerymetrics view.
Chapter 9: Capturing Query Processing Metrics | 273
Output:
qtext pio_max
select count(*) from PaymentHistory 1371305
Output:
qtext
cnt
---------------------------------------------------------------
select marketID, count(*) from Properties..Geography group by marketID
order by 2 desc
3798
274 | Chapter 9: Capturing Query Processing Metrics
Similar statement as above, but restrict the output to only the query
with the maximum departure from the average elapsed time:
select id,
elap_max,
elap_avg,
"Percent Over Average" =
(convert(numeric(7,2),elap_max) -
convert(numeric(7,2),elap_avg)) /
convert(numeric(7,2),elap_avg )
Chapter 9: Capturing Query Processing Metrics | 275
Output:
id elap_max elap_avg Percent Over Average
--- ----------- ----------- ---------------------------
1958298036 5173 32 16065.6250000000
Output:
cnt pio_avg total_pio qtext
--- ---------- -------------- -----------------------------------
9 13685 123165 select count(*) from Rental
Display metric group and associated counts for each group from
sysquerymetrics:
select gid 'Group ID', count(*) '#Metrics'
from sysquerymetrics
group by gid
order by gid
Output:
Group ID #Metrics
1 290
2 353
3 759
4 253
5 986
276 | Chapter 9: Capturing Query Processing Metrics
Note: The sp_metrics command in the above example will assign the
current running group’s metric information the gid of 2; however, new
metric information will continue to be stored with a gid of 1.
A few rules to note with the assignment of a new gid for a batch of
QP Metrics entries:
t While the gid is a quoted identifier, it must be an integer.
t The QP Metrics cannot be backed up to the same gid more than
once within the same database.
t If the metrics for a gid are dropped with sp_metrics "drop" com-
mand, the gid can be reused.
t A new gid does not need to be sequential.
t You cannot back up to gid of 1, since this is the active gid.
Example:
select q2.pio_avg, q2.gid,q1.qtext
from sysquerymetrics q1,
sysquerymetrics q2
where q1.hashkey=q2.hashkey
and q1.gid=1
and q1.sequence <= 1
and q2.sequence <= 1
and q1.hashkey=742334506
and q1.qtext='select count(*) from Rental where petFlag = "Y"'
Results:
pio_avg gid qtext
204165 4 select count(*) from Rental where petFlag = "Y"
183639 1 select count(*) from Rental where petFlag = "Y"
Interpreting the above results, we observe the same query has experi-
enced a change of approximately 20,000 physical I/Os from the point
in time associated with gid of 1, in comparison to the point in time
associated with gid of 4. Performance degradation is hereby identi-
fied, and may need investigation by the database administrator.
Results:
lio_avg lio_avg gid qtext
36 36 4 select count(*) from Tenants
1478 1471 4 select min(leaseStartDate) from Contracts
982 978 4 select tenantName, tenantID from Tenants
where tenantID = 5001
95336 205332 4 select count(*) from Contracts where
petDeposit = "Y"
In the above example, the SQL has identified four identical queries
between the first and fourth running groups (gid). Additionally, per-
formance degradation in logical I/O of over 100% is identified for the
fourth query. For this example database, investigation found there
was no index on the petDeposit column in the Contracts table. Addi-
tionally, the number of rows in this table more than doubled. The
analysis and QP Metrics data suggest an index may be useful for the
petDeposit column in the Contracts table.
280 | Chapter 9: Capturing Query Processing Metrics
Recommendation: For large queries, the SQL syntax will span more
than one row in the sysquerymetrics view. This will be represented with
an escalating sequence number combined with the same hashkey. For
large SQL, search on the hashkey and not the qtext column, since trun-
cation and wrapping will occur within the qtext field. Additionally, add the
sequence column to the search in order to limit the QP Metrics rows
retrieved, where sequence number is either 0 or 1. The metrics displayed
for escalating sequence numbers for the same query will be redundant.
Output:
elap_avg pio_avg cnt qtext
123033 204165 20512 select count(*) from Contracts where
petDeposit = "Y"
Note the high number of executions for this SQL statement. Since the
number of executions is over 20,000 over a period of six months, the
current metric data will not skew the calculations very far since the
old metric data is so heavily weighted in this example. Of course,
degradation in performance could also be detected by paying close
attention to the “max” columns in the QP Metrics view, such as the
pio_max and elap_max fields. Observe, in the following output,
where the pio_max and elap_max fields are used to identify a
Chapter 9: Capturing Query Processing Metrics | 281
Output:
elap_avg elap_max pio_avg pio_max cnt qtext
123033 398033 204165 487165 20513 select count(*) from Contracts
where petDeposit = "Y"
Output:
hashkey cnt qtext
185085529 3 select count(*) from Rental where tenantID >= 5000
724053625 1 SELECT COUNT(*) from Rental where tenantID >= 5000
Note: The previous examples were executed on a server with the iso_1
character set with sort order bin_iso_1. Case sensitivity is not disabled
with these character sets and sort orders.
It should also be noted that SQL statements that are identical other
than the inclusion of embedded comments will hash to different keys.
This is evident in the next example.
Example with no comments:
select count(*)
from Rental
where tenantID >= 5000
go
hashkey cnt
qtext
----------- -----------
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
1567762236 1
select count(*) from Rental where tenantID >= 5000
2131636074 1
select count(*) -- comment from /* comment */ Rental where /*
comment * / tenantID >= 5000 /* comment */
Note: The comments in this case resulted in different hashkeys for what
is, essentially, two functionally exact queries that are only different due to
the presence or absence of comments. Some third-party applications or
administrative tools will remove comments from SQL submitted to ASE.
In this scenario, the query with the comments and the query without the
comments will hash to the same key with the comments removed. In
other words, ASE will look at what it receives, and not necessarily what is
sent by some tools, when determining the hashkey value and storing the
metric information.
With the sp_metrics "drop" parameter, the metrics for a database can
be dropped at the query level, group level, or database level, depend-
ing on the parameters passed to the system procedure. To illustrate,
consider the following examples.
To drop specific metrics for one query in a database:
sp_metrics "drop", "2", "610817238"
-- This command drops the metrics for the query belonging to running
group “2”, with the specific id of 61081723.
Note the lio_avg and pio_avg from the sysquerymetrics data exactly
match the statistics I/O total physical and logical reads.
Chapter 9: Capturing Query Processing Metrics | 285
Tip: To prevent filling the system segment for databases with the QP
Metrics capture enabled, do not isolate the system segment for these
databases to a small device fragment.
286 | Chapter 9: Capturing Query Processing Metrics
Limitations
The QP Metrics data and capture process has a few limitations. First,
the metrics do not track the latest time a given SQL statement was
executed. To work around this limitation, periodically back up your
sysquerymetrics data to a different running group or gid and note the
date and time range of data for the noted gid.
The second limitation is identification. The QP Metrics process
offers no security features. The process does not track who executed
a given SQL statement or a certain stored procedure. If this is impor-
tant for your installation, please consider the Sybase auditing
functionality. Another alternative to consider where accountability
is important is the MDA tables, where tables such as monProcess-
Activity, monProcessSQLText, and monSysSQLtext contain the
ServerUserID column to provide accountability by suid.
Summary
The QP Metrics capture process appears to be a very useful tool for
the ASE 15 database administrator. An element of risk is apparent
when the employment of QP Metrics is not carefully set up or moni-
tored as the repository for QP Metrics resides on the system segment.
The risk can be minimized, provided the system segment for each
user database where the QP Metrics process is utilized is not limited
to a very small fragment of disk. The process is simple to set up and
maintain. QP Metrics provides an online history of your database’s
SQL usage. This SQL can be queried and analyzed. The QP Metrics
process operates without the installation of third-party applications or
the initiation of other Sybase ASE features that can carry additional
overhead, such as the Sybase audit process. Finally, the QP Metrics
process lays the groundwork for on-the-fly comparison of current
execution metrics with the saved baseline. This is a future enhance-
ment that may evolve from this new feature of ASE 15.
Chapter 10: Graphical Plan Viewer | 287
Chapter 10
When the dbisql is called from Unix, it opens the window shown in
Figure 10-1. Fill in the required information and press OK.
288 | Chapter 10: Graphical Plan Viewer
Figure 10-1
Figure 10-2
Figure 10-3
Chapter 10: Graphical Plan Viewer | 289
ROOT:EMIT Operator
|RESTRICT Operator
|
| |SCALAR AGGREGATE Operator
| | Evaluate Ungrouped COUNT AGGREGATE.
| | Evaluate Ungrouped SUM OR AVERAGE AGGREGATE.
| |
| | |MERGE JOIN Operator (Join Type: Inner Join)
| | | Using Worktable3 for internal storage.
| | | Key Count: 1
| | | Key Ordering: ASC
| | |
| | | |SORT Operator
| | | | Using Worktable1 for internal storage.
| | | |
| | | | |SCAN Operator
| | | | | FROM TABLE
| | | | | orders_range_partitioned
| | | | | [ Eliminated Partitions : 1 3 ]
| | | | | Table Scan.
| | | | | Forward Scan.
| | | | | Positioning at start of table.
| | | | | Using I/O Size 16 Kbytes for data pages.
| | | | | With LRU Buffer Replacement Strategy for data pages.
| | |
| | | |SORT Operator
| | | | Using Worktable2 for internal storage.
| | | |
290 | Chapter 10: Graphical Plan Viewer
| | | | |SCAN Operator
| | | | | FROM TABLE
| | | | | customer_range_partitioned
| | | | | [ Eliminated Partitions : 1 3 ]
| | | | | Table Scan.
| | | | | Forward Scan.
| | | | | Positioning at start of table.
| | | | | Using I/O Size 16 Kbytes for data pages.
| | | | | With LRU Buffer Replacement Strategy for data pages.
The above query plan is displayed graphically on the Plan tab below
the SQL Statements pane (see Figure 10-3). Each operator from the
above query plan is represented as a node in the plan viewer. The
cost of each operator is displayed as the percentage of the total cost.
In Figure 10-3, the cost of TableScan for orders_range_partitioned is
31.89% of the total cost. At 62.9%, the maximum resources are used
by the sorting operation on this table. The text query plan shown
above doesn’t provide the relative costing of each operator but the
GPV does. This feature of GPV makes it easier to find the bottleneck
of the query.
The tree can be expanded or collapsed by clicking on the – or +
symbols on the plan. You can collapse either the trunk of the tree
(Figure 10-4a) or a single branch (Figure 10-4b). This feature is par-
ticularly useful while analyzing large query plan trees.
Figure 10-4a
Chapter 10: Graphical Plan Viewer | 291
Figure 10-4b
Double-clicking on any node (box) on the plan will populate the sta-
tistics relevant for that node in the bottom half of the pane. The
statistics include row count, logical I/O, and physical I/O. If the node
is at the lowest level of the tree, the statistics for only that particular
node will be displayed (see Figure 10-5). If the node has subtrees
underneath, the statistics will be shown for both the highlighted node
and the subtree (see Figure 10-6).
When the mouse is moved over any node, a small window called
a tooltip appears. The tooltip text provides details about that particu-
lar node without actually selecting that node. This feature is helpful
when comparing the statistics between the nodes. The tooltip text is
the small window within the Plan tab in Figures 10-5 and 10-6.
292 | Chapter 10: Graphical Plan Viewer
Figure 10-5
Figure 10-6
Figure 10-7
The Plan tab has three subtabs: Details, XML, and Text. The Details
tab shows the graphical tree and the statistics. The XML tab shows
the query plan in an XML format (see Figure 10-8). The Text tab
shows the traditional query plan (see Figure 10-9).
Figure 10-8
294 | Chapter 10: Graphical Plan Viewer
Figure 10-9
Figure 10-10
The above tree looks very similar to the one generated by the GPV.
Even though this tree does not provide the percentages like the plan
viewer, it shows all the statistics at the same time. From the statistics
in the above tree, logical and physical I/Os for the orders_range_
partioned table are 581 and 0 respectively. The values for the logical
and physical I/Os for the sort operation on the same table are 96 and
84 respectively. Since the physical I/Os are more expensive than the
logical reads, it can be concluded that the sort operation on the
orders_range_partitioned table is the most expensive operation in this
query. This conclusion is the same as the one from the GPV.
296 | Chapter 10: Graphical Plan Viewer
Summary
With ASE 15, Sybase not only improved the performance of the
queries but also provided additional tools to easily identify the per-
formance issues. A traditional query plan shows what indexes are
being used and which tables are undergoing table scans. The DBA
still has to find the statistics from a different source and use them to
analyze each operation identified by the query plan. This is a cumber-
some process, especially when troubleshooting a long query with a
large number of table joins. Although there are some dbcc commands
that generate detailed statistics for the query and explain the rationale
for choosing a particular query plan, the output from these commands
can easily run into hundreds of pages and be difficult to decipher.
It usually takes more time to identify the problem query or query
operation than to fix it. Both the GPV and the new set option provide
a very easy way of identifying the bottlenecks in the query execution.
These new features should greatly improve the efficiency of DBAs
and thus reduce the total cost of ownership.
Chapter 11: Sybase Software Asset Management (SySAM) 2.0 | 297
Chapter 11
Introduction
Although concerns over software piracy have driven vendors to
develop methods to ensure compliancy, many software companies
still do not enforce their own licensing agreements. In part, this is due
to the lack of tools that provide the necessary information about their
customers’ noncompliance. This has also been true for the Sybase
product set. With ASE 15, Sybase is addressing software license
compliance.
Sybase has partnered with Macrovision’s FLEXnet product set to
provide tools for establishing, monitoring, and reporting product
compliance for Sybase products. In early 2005, Macrovision was
named to the Software Development Times magazine’s top 100 com-
panies for its FLEXnet Software Value Management platform.
298 | Chapter 11: Sybase Software Asset Management (SySAM) 2.0
Prior to ASE 15
SySAM was first introduced with ASE 12.0 to provide a method to
manage optional licensed features of ASE. For a feature to be made
available to the client, a certificate (provided with the purchase) had
to be registered with SySAM. Once the feature was registered and
ASE recycled, the feature could be activated.
In ASE 12.0 the following features were available after register-
ing the license with SySAM:
t ASE_HA — ASE High Availability System
t ASE_DTM — Distributed Transaction Management
t ASE_JAVA — Java in the Database
t ASE_ASM — Advanced Security Mechanisms (SSL, FGAC,
etc.)
With ASE 12.5, six additional features were made available after reg-
istering the license:
t ASE_EFTS — Enhanced Full Text Search
t ASE_EJB — Enterprise Java Bean Server
t ASE_SXP — SQL Expert
t ASE_XFS — External File System Access through proxy tables
t ASE_XRAY — DBXray
t ASE_DIRS — LDAP Option
In most cases, since these options were not being used, the database
administrator never implemented SySAM. ASE would still come up,
but a message would be written to the errorlog, indicating that no
licensing information was available and that ASE was being brought
up with no additional features:
00:00000:00000:2005/02/26 06:00:54.90 kernel Warning:
There is no valid license for ASE server product. Server is boot-
ing with all the option features disabled.
Chapter 11: Sybase Software Asset Management (SySAM) 2.0 | 299
With ASE 15
With ASE 15, Sybase is adapting.
With the proliferation of regulatory requirements such as
Sarbanes-Oxley (SOX), companies are being required to account for
the products that they utilize. This includes software products. For
most companies, the issue is not what to monitor or account for, but
how to account for it. Companies like Macrovision are addressing the
issue by providing tools for the deployment of software product
licenses, for monitoring the usage of those products, and for reporting
of compliance or noncompliance of each product.
Although Sybase could have developed their own product to
address the issues related to compliance, they realized that other ven-
dors had already developed quality products that could be
incorporated into Sybase’s product set. Macrovision was the vendor
of choice — not only because of their product but also because of
their company stability and market position within the product licens-
ing industry.
For compliance monitoring to be effective, it has to be real time.
SySAM 2.0 addresses this issue by using a “heartbeat.” The heartbeat
of SySAM periodically checks the compliance of the product to
determine if the license is still effective and if the number of
deployed licenses provides for the number of active sessions request-
ing the product or service.
SySAM Server
The SySAM server is also referred to as the license server. It can be
either local to the current machine where the Sybase product is
installed or on a networked server where all Sybase licenses are man-
aged. Redundant license servers can be utilized by those companies
concerned about disaster recovery.
The license management agent or daemon process is lmgrd. It is a
process started in Unix or a service within Microsoft Windows.
300 | Chapter 11: Sybase Software Asset Management (SySAM) 2.0
Figure 11-1
License File
In a standalone licensed environment, the license file contains an
entry for license server location and the registered feature licenses. In
pre-ASE 15 servers, the file was named license.dat. With ASE 15,
the files are suffixed with “.lic” (i.e., ASE150_EE_Beta.lic) and are
found in the $SYBASE/SYSAM-2_0/licenses directory. The follow-
ing example shows a sample license — $SYBASE/$SYBASE_
SYSAM/licenses/ASE150_EE_Beta.lic. Detailed information about
the components of the license file can be found in the FLEXnet
Licensing End User Guide.
Example:
SERVER dublin 94059f65 1700
VENDOR SYBASE
# Package definition for ASE Enterprise Edition.
PACKAGE ASE_EE SYBASE 2005.0910 COMPONENTS=ASE_CORE OPTIONS=SUITE \
ISSUED=30-mar-2005 SIGN2="0557 5FCE CDFC 7502 B5E8 23E0 46A2 \
A26C ADA0 97FB D0C7 352B 2456 EB53 97CA 18A2 BA17 76B0 A951 \
6C26 26F8 2029 5D1E B4AC 4302 4C96 5008 7F0E 465F F49E"
# ASE EE with SR license type
INCREMENT ASE_EE SYBASE 2005.0910 10-sep-2005 uncounted \
VENDOR_STRING=SORT=100;PE=EE;LT=SR HOSTID=ANY \
ISSUER="CO=Sybase, Inc.;V=15.0;AS=A;MP=T" ISSUED=30-mar-2005 \
NOTICE="ASE 15.0 Beta Test License" SN=123456-1 SIGN2="0FEF \
3CC4 AE10 025B 365D 4213 8127 88C0 7FD9 1330 8DDC 70F2 2262 \
B30B E6CB 1751 39BA FD75 EC42 052E 2509 94E8 611F 1E5B 18C5 \
2998 F76B 7A8C 5DCD 4588"
Example:
SERVER dublin 94059f65 1700
SERVER newyork 8750a3d4 1700
VENDOR SYBASE
Options File
The options file contains entries for controlling the operating parame-
ters of the licensing environment. With ASE 15, the file is named
SYBASE.opt. The name of the options file corresponds to the name
specified in the VENDOR option in the licensing file. The following
example shows a sample license — $SYBASE/$SYBASE_SYSAM/
SYBASE.opt. Detailed information about the components of the
options file can be found in the FLEXnet Licensing End User Guide.
Example:
DEBUGLOG +/sybase/sybase15_beta/SYSAM-2_0/bin/SYBASE.log
REPORTLOG +/sybase/sybase15_beta/SYSAM-2_0/bin/SYBASE.rl
Properties File
The properties file contains user-defined parameters that optionally
define information about the licensed environment. This file is found
on each ASE 15 server in the $SYBASE/ASE-15_0/sysam directory.
A template file (sysam.properties.template) is provided as an exam-
ple for you to use to set up the environment. When you build an ASE
server, a server-name.properties file is automatically created. You
can modify the resulting file for your environment.
$SYBASE/ASE-15_0/sysam/ sysam.properties.template
2634B4D789DBB871E52B2C29807368E097FCC89088005C479F
email.smtp.host=smtp
email.smtp.port=25
[email protected]
[email protected]
304 | Chapter 11: Sybase Software Asset Management (SySAM) 2.0
email.severity=NONE
PE=EE
LT=SR
On Windows:
set SYBASE_LICENSE_FILE 700@dublin;1700@london;1700@toyko
The grace period also has a secondary purpose. If for some reason the
license server is unavailable and the product or option is known by
ASE to have utilized a valid license recently, the product will revert
to a grace period and allow ASE and other options to be active. The
grace period assumes that you will take necessary steps to quickly
resolve the issue with the license server.
A grace period is also activated as a license approaches its expi-
ration date. The goal of this grace period is to allow the customer to
continue business as usual until their license(s) can be renewed. The
notification system will inform the user (via the errorlog, or email if
configured) in a half-life fashion; e.g., install grace period of 30 days
gets initial message, then after 15 days, then 7.5 days, etc., down to
the last couple of hours. ASE will shut down when a license expires.
Each license contains the following information about the prod-
uct or option:
t Type of license — Server (Server - SR, Standby Server - SV,
etc.) or CPU (CPU - CP, Standby CPU - SF, etc.)
t Period of time for which the license is valid
t Entitlement quantity — The number of licenses that have been
purchased for the product or feature. In the case of site licenses,
this number can be increased as the quantity of licenses required
increases at the customer site. The customer will need to acquire
the additional entitlements from the Sybase Product Download
Center (SPDC). The license key will always contain a specific
number of licenses, whereas the download center has a record of
the entitlements purchased by the customer.
t License key
t License local host or host/port number for networked license
server
308 | Chapter 11: Sybase Software Asset Management (SySAM) 2.0
How do you acquire a license key? License keys are not provided
with the software release package. Once the product has been pur-
chased, a license authorization code will be provided to the customer
that will allow the customer to retrieve a license key. All license keys
are acquired by accessing the SPDC website (https://sybase.sub-
scribenet.com). The website walks you through the process of setting
up and downloading the license key. Once the SPDC generates a
license, the license will need to be saved to your local machine and
then it can be registered with SySAM.
What if I want to perform a trial evaluation of a product that I may or
may not purchase? In the event that you want to evaluate a product,
Sybase will provide a license authorization code that will allow a
temporary or short-term license key to be generated from the SPDC.
At the end of the evaluation period, the product will no longer func-
tion. If a permanent license is acquired prior to the end of the
evaluation period, as long as the license is installed prior to the termi-
nation of the trial period, the product will continue to work with no
interruption of service.
What if I have a licensed server on my laptop and I disconnect it from
the network for an extended period of time. Will the product continue
to work? SySAM 2.0 supports the concept of “borrowing” a license.
Chapter 11: Sybase Software Asset Management (SySAM) 2.0 | 309
In this case, the SySAM utility lmutil lmborrow will be used to check
out a license for a specified period of time. Once the machine is reat-
tached to the network, you would need to “return” the license using
lmborrow again.
Product Licenses
With the initial release of ASE 15, the only product utilizing SySAM
2.0 will be ASE 15. SySAM 2.0 will be able to manage licenses for
Sybase products that are not utilizing 2.0 features, such as grace peri-
ods. Eventually, all Sybase products (EAServer, Replication Server,
PowerDesigner, etc.) will adopt SySAM 2.0 licensing. When they do,
they will implement grace periods. The length of time for each grace
period may vary across products, but the principles will not. The
products will implement the same types of grace periods as men-
tioned above.
License Activation
No new restrictions have been placed on license activation with
SySAM 2.0. For licensed options (i.e., HA), the license activation is
dependent on whether the option is dynamic or static. If the option is
dynamic, once the option has been activated by sp_configure, the
license will be acquired automatically without the need for ASE to be
recycled. Licenses that are graced may be acquired at the next heart-
beat if they are now available. The heartbeat is a predefined interval
used by SySAM to verify the legitimacy of a license. The interval of
310 | Chapter 11: Sybase Software Asset Management (SySAM) 2.0
SySAM Administration
The administration of the SySAM environment can be handled in one
of three ways: manually, via utilities, or via Sybase Central. A new
plug-in has been developed for Sybase Central for managing the
SySAM environment. In order to utilize the plug-in, the SySAM
Agent has to be running either on the license server or the local
server in a networked licensed environment. The FLEXnet Licensing
End User Guide provided with ASE 15 contains detailed information
and instructions on administering the licenses. The SySAM Agent
can be started by using the $SYBASE/$SYBASE_SYSAM/bin/
sysam script. $SYBASE/$SYBASE_SYSAM/bin/sysam utilizes
$SYBASE/$SYBASE_SYSAM/licenses to specify the location of
the license directory. The SySAM script can be used to start and stop
the server and perform some monitoring and diagnostics. The script
is simply a wrapper around the FLEX utilities. But since it also sets
the license path to the SYSAM-2_0/licenses directory, it ensures a
standard operating model.
sp_lmconfig
A new stored procedure is available to be used in the SySAM envi-
ronment. sp_lmconfig uses the license manager to gather information
about the licensed environment and display it within the isql session.
The example below is of a licensed network server.
1> sp_lmconfig
2> go
(return status = 0)
When the server is shut down, the license will be checked back in.
SySAM: Checked in license for 1 ASE_CORE (2005.1231/31-dec-2005/0E7A
5668 9856 4ABF).
If you are running SySAM 1.0, you will have several options based
on the SySAM environment that you are currently using. The follow-
ing upgrade scenarios assume that you are upgrading to ASE 15.
If you are in a standalone environment, you will need to define
the environment variables and the SySAM options, acquire a license
key for ASE, and add the license key to the license file. This is the
same process as if you had never implemented SySAM 1.0.
Note: If you have other pre-ASE 15 servers on this machine, they can
coexist with the ASE 15 server. The pre-ASE 15 servers will continue to
check out their licenses from SYSAM_1_0/licenses/license.dat while the
ASE 15 server will use the SYSAM_2_0/licenses/*.lic file(s).
Chapter 11: Sybase Software Asset Management (SySAM) 2.0 | 313
SySAM Reporting
There are several canned reports that are available with SySAM 2.0.
Each report belongs to one of three groups of reports: summary,
server usage, or raw data.
Summary Reports
t Usage Over Time — Shows the maximum number of licenses
that have been used over the specified time period. The default
time period is one second. A granularity of hour will provide the
same report as the High Water Mark report.
314 | Chapter 11: Sybase Software Asset Management (SySAM) 2.0
Figure 11-2
Figure 11-3
Chapter 11: Sybase Software Asset Management (SySAM) 2.0 | 315
Figure 11-4
Figure 11-5
316 | Chapter 11: Sybase Software Asset Management (SySAM) 2.0
Figure 11-6
Figure 11-7
Chapter 11: Sybase Software Asset Management (SySAM) 2.0 | 317
Figure 11-8
Figure 11-9
318 | Chapter 11: Sybase Software Asset Management (SySAM) 2.0
Figure 11-10
Figure 11-11
Chapter 11: Sybase Software Asset Management (SySAM) 2.0 | 319
Figure 11-12
Figure 11-13
320 | Chapter 11: Sybase Software Asset Management (SySAM) 2.0
Figure 11-14
Figure 11-15
Chapter 11: Sybase Software Asset Management (SySAM) 2.0 | 321
Figure 11-16
Summary
Software license compliance has become a major issue for both the
vendor and the client. The vendor has several reasons for wanting the
client to be compliant. First, the vendor wants to get paid appropri-
ately for the use of the product. Second, the vendor wants to ensure
that their product is being used. Although people may think the ven-
dor does not care if the product sits on the shelf or not, in reality a
product sitting on the shelf means that the product is of no use to the
client. Third, for planning purposes, a vendor wants to know the
usage growth pattern. If the product usage is growing, they may be
able to work with the client to come up with pricing options for addi-
tional licenses, identify potential product weaknesses and strengths,
and recommend additional complementary products.
For the client, the knowledge that they are paying for what they
are using alleviates any concern about over- or underutilization of the
product that has been purchased for the company. The client also
wants to know when to plan for additional licenses.
322 | Chapter 11: Sybase Software Asset Management (SySAM) 2.0
Chapter 12
The authors of this book have installed countless ASE servers, using
all of the mentioned installation methods in this chapter. Installing
ASE through the GUI and launching with srvbuild for Unix environ-
ments or syconfig.exe for Windows environments is the simplest
method for beginners. This method offers a step-by-step question/
answer interface, which also reminds the database administrator of all
installation options available.
324 | Chapter 12: Installation of ASE Servers
Unix:
$SYBASE/$SYBASE_ASE/*.res
#
sqlsrv.do_create_sybsystemprocs_device: yes
sqlsrv.sybsystemprocs_device_physical_name: C:\sybase\data\sysprocs2.dat
sqlsrv.sybsystemprocs_device_size: 200
sqlsrv.sybsystemprocs_db_size: 200
sqlsrv.sybsystemprocs_device_logical_name: sysprocsdev
#
# --- Set up sybsystemdb ----
#
sqlsrv.do_create_sybsystemdb: yes
sqlsrv.do_create_sybsystemdb_db_device: yes
sqlsrv.sybsystemdb_db_device_physical_name: C:\sybase\data\sybsysdb2.dat
sqlsrv.sybsystemdb_db_device_physical_size: 3
sqlsrv.sybsystemdb_db_size: 3
sqlsrv.sybsystemdb_db_device_logical_name: sybsystemdb
#
sqlsrv.errorlog: C:\sybase\ASE-15_0\install\
SYBASE_BRIAN.log
sqlsrv.sort_order: binary
sqlsrv.default_characterset: cp850
sqlsrv.default_language: us_english
#
sqlsrv.preupgrade_succeeded: no
sqlsrv.network_name_alias_list:
sqlsrv.resword_conflict: 0
sqlsrv.resword_done: no
sqlsrv.do_upgrade: no
sqlsrv.characterset_install_list:
sqlsrv.characterset_remove_list:
sqlsrv.language_install_list:
sqlsrv.language_remove_list:
sqlsrv.shared_memory_directory:
sqlsrv.addl_cmdline_parameters:
sqlsrv.eventlog: yes
sqlsrv.atr_name_shutdown_required: yes
sqlsrv.atr_name_qinstall: no
#
sybinit.charset: cp850
sybinit.language: us_english
sybinit.resource_file:
sybinit.log_file:
sybinit.product: sqlsrv
#
sqlsrv.default_backup_server: SYBASE_BRIAN_BS
330 | Chapter 12: Installation of ASE Servers
C:\sybase\ASE-15_0\jobscheduler\Templates\xml\en\SybReconfUsrConnsTemplate.xml
.Done
C:\sybase\ASE-15_0\jobscheduler\Templates\xml\en\SybUpdateStatsTemplate.xml
.Done
C:\sybase\ASE-15_0\jobscheduler\Templates\xml\en\SybSvrUpdateStatsTemplate.xml
.Done
Task succeeded: Install Job Scheduler XML templates.
Running task: Set Job Scheduler Agent name.
Task succeeded: Set Job Scheduler Agent name.
Running task: Enable Job Scheduler.
Exiting.
The log file for this session is 'C:\sybase\ASE-15_0\init\logs\log1107.006'.
Figure 12-1
Figure 12-2
Step 1: For Windows, run the setup.exe executable from the direc-
tory containing the Sybase ASE 15 software. Click OK once the path
and executable are designated.
Figure 12-3
334 | Chapter 12: Installation of ASE Servers
Figure 12-4
Figure 12-5
For Unix:
Similar to the setup.exe executable in Windows environments, the
Unix installation executable will launch a GUI-based Installer appli-
cation. The prompt to launch the Unix installer is as follows:
$SYBASE/$SYBASE_ASE/bin/srvbuild
Figure 12-6
Step 3: Select your country of origin, and accept the license agree-
ment by clicking on the “I agree” radio button. Click Next.
Figure 12-7
336 | Chapter 12: Installation of ASE Servers
Step 4: Pick the appropriate location for the unpacked Sybase bina-
ries, and the $SYBASE or %SYBASE% directory, then click Next.
Figure 12-8
If the chosen Sybase directory does not exist, click Yes, and the
Sybase installer will create the designated directory.
Figure 12-9
Figure 12-10
Step 6: Since this installation is custom, the GUI will direct the data-
base administrator to a preselected list of installation options. Check
items to designate products for installation. After products are
selected, click Next. For this installation, the Job Scheduler Tem-
plates and Utilities are added to the installation.
Figure 12-11
338 | Chapter 12: Installation of ASE Servers
Figure 12-12
Figure 12-13
Chapter 12: Installation of ASE Servers | 339
Step 9: On the same screen, scroll to the bottom to verify how much
physical disk will be utilized by the unpacked Sybase ASE software.
For this installation example, the Installer program indicates 929.6
MB of disk will be utilized by the Sybase software alone. Click Next
to confirm the installed items.
Figure 12-14
Step 10: The GUI Installer will then begin the process of extracting
the Sybase software.
Figure 12-15
340 | Chapter 12: Installation of ASE Servers
Figure 12-16
Step 12: Next, the installation asks for information on how to obtain
ASE licenses. On this screen, the host name and port number of the
Sybase Software Asset Management is placed into the GUI by the
Installer. SySAM was covered in Chapter 11, so at this point we will
not make any license manager selections. This will be an example of
the “Try and Buy” installation.
For reference, if “Yes” is selected, have the host name and port
number available for the host of the Sybase Software Asset
Management.
Chapter 12: Installation of ASE Servers | 341
Figure 12-17
If you choose “No,” this screen will gray out the host and port num-
ber selections. Click Next to proceed.
Figure 12-18
342 | Chapter 12: Installation of ASE Servers
Figure 12-19
Step 14: The next screen will allow the configuration of the email
alert mechanism. This is for the publication of license information to
a designated email address. Enter the SMTP email host name along
with the SMTP server’s port number, the sender’s and recipient’s
email addresses, and the severity level for messages generated by
SySAM. Click Next when complete.
Figure 12-20
Chapter 12: Installation of ASE Servers | 343
Step 15: Select the license type to install, and click Next.
Figure 12-21
Step 16: With the ASE 15 Installer, the database administrator can
configure ASE and other ASE-related products through the installa-
tion process. Check any products that need to be configured during
the installation process and click Next.
Figure 12-22
344 | Chapter 12: Installation of ASE Servers
Step 17: The next screen asks for which items need to be configured
during the installation process. Click any items to be configured
where the default values are not acceptable, and then click Next.
Figure 12-23
Step 18: Next, select configuration options for ASE, including the
server name, page size, errorlog location, and master device size.
Remember, the server’s page size cannot be changed after the server
is built. Choose a value for the server’s page size carefully. As a gen-
eral guideline, a page size of 2 K is ideal for OLTP-based systems,
while larger page sizes are preferable for DSS-based systems. The
page size of 2 K is the default, and is recommended to be selected if
the system’s usage type is unknown. Click Next when complete.
Chapter 12: Installation of ASE Servers | 345
Figure 12-24
Step 19: At this stage, the entries for the ASE server are complete.
This exercise continues with the installation steps for ASE’s Backup
Server. On this screen, accept or modify entries for the ASE Backup
Server. Click Next when complete.
Figure 12-25
346 | Chapter 12: Installation of ASE Servers
Step 20: Accept or modify entries for the Sybase Monitor Server,
and click Next when complete.
Figure 12-26
Step 21: At this stage, the entries for the Backup Server are com-
plete. This example continues with the installation selections for the
XP Server. Select a port number for the XP Server or accept the
default and click Next.
Chapter 12: Installation of ASE Servers | 347
Figure 12-27
Step 22: At this stage, the installation selections for ASE, Backup
Server, and XP Server are complete. This example continues with the
option selections for installing the Job Scheduler Agent. On the next
screen, accept the default entries for the Job Scheduler Agent, or
modify the defaults and then click Next.
Figure 12-28
348 | Chapter 12: Installation of ASE Servers
Step 23: Enter the login ID to be used for Self Management of ASE.
Click Next to select the default of sa, or enter a different login and
click Next.
Figure 12-29
Step 24: For the installation of the Sybase Unified Agent, select the
appropriate adapter type and configuration settings for the Sybase
Unified Agent interface. Click Next when complete.
Chapter 12: Installation of ASE Servers | 349
Figure 12-30
Step 25: Select the Security Login Modules for the Unified Agent,
then click Next when complete.
Figure 12-31
350 | Chapter 12: Installation of ASE Servers
Step 26: At this stage, all entries for ASE, ASE Backup Server, XP
Server, Job Scheduler, and the Unified Agent are complete. Take a
moment to review the settings from the options selected through the
GUI screens. If the entries presented by the New Servers Summary
screen are correct, click Next to proceed with the server specifica-
tions selected.
Figure 12-32
Step 27: The Installer will then proceed to build the master device
and commence the installation of all selected products.
Chapter 12: Installation of ASE Servers | 351
Figure 12-33
Step 28: Upon success, the message in Figure 12-34 will display.
Figure 12-34
352 | Chapter 12: Installation of ASE Servers
Figure 12-35
If no errors occurred, click the radio button to restart the computer for
Windows environments and click OK. For Unix-based environments,
it is not necessary to reboot the host server.
/sybase/sybase15/ASE-15_0/bin/dataserver \
-sBRIAN_TEST \
-d/sybase/master.dat \
-e/sybase/logs/BRIAN_TEST.log \
-c/sybase/sybase15/ASE-15_0/BRIAN_TEST.cfg \
-M/sybase/sybase15/ASE-15_0 \
Windows:
Add an entry to the C:%SYBASE%ini\sql.ini (interfaces) file.
Assign a port number that is not already in use.
[SYBASE]
master=NLWNSCK,BRIAN,2500
query=NLWNSCK,BRIAN,2500
Chapter 12: Installation of ASE Servers | 355
4. Start ASE.
Unix:
$SYBASE/$SYBASE_ASE/install ./startserver -f RUN_SYBASE
Windows:
C:%SYBASE%\%SYBASE_ASE%\install>startsrv.exe -f RUN_SYBASE.bat
5. When the errorlog is reviewed at this stage, errors will likely be
present. The errors are mostly attributed to the absence of one
important device and database that will be missing: the
sybsystemprocs device and database. Create them as follows:
Unix:
disk init name="sysprocsdev",
physname = "/dev/vx/rdsk/rootdg/sysprocsdev",
size=128000
go
create database sybsystemprocs on sysprocsdev = 250
go
Windows:
disk init name = "sysprocsdev",
Physname = "C:\sybase\sysprocsdev.dat",
Size = 128000
go
create database sybsystemprocs on sysprocsdev = 250
go
6. At this stage, a server is built and can be accessed. However, the
installation scripts will need to be executed to fully build the
server and make it usable.
From the $SYBASE/$SYBASE_ASE/scripts directory,
install system procedures with the following installation scripts.
Unix:
host:~/Sybase/ASE-15_0/scripts > isql -Usa -SBRIAN_TEST
-i./installmaster -o./installmaster.out
host:~/Sybase/ASE-15_0/scripts > isql -Usa -SBRIAN_TEST
-i./installmodel -o./installmodel.out
host:~/Sybase/ASE-15_0/scripts > isql -Usa -SBRIAN_TEST
-i./installupgrade -o./installupgrade.out
host:~/Sybase/ASE-15_0/scripts > isql -Usa -SBRIAN_TEST
-i./instmsgs.ebf -o./instmsgs.ebf.out
356 | Chapter 12: Installation of ASE Servers
Windows:
C:\sybase\ASE-15_0\scripts>isql -Usa -SSYBASE -iinstmstr
-oinstmstr.out
C:\sybase\ASE-15_0\scripts>isql -Usa -SSYBASE -iinstmodl
-oinstmodl.out
C:\sybase\ASE-15_0\scripts>isql -Usa -SSYBASE -iinsupgrd
-oinsupgrd.out
C:\sybase\ASE-15_0\scripts>isql -Usa -SSYBASE -iinstmsgs.ebf
-oinstmsgs.out
Summary
This chapter has touched upon three different yet common installa-
tion methods for ASE and the supporting components. Each of the
installation methods has advantages and disadvantages that depend
upon the level of expertise and confidence of the database adminis-
trator. Additionally, each installation method has appropriate areas of
application that can be selected based upon the needs of the individ-
ual server installation requirements. As indicated in the beginning of
this chapter, a general trend toward resource file installations is
expected as experience level and the number of servers supported by
a database administrator or DBA team increase.
Part II
Pre-15 Improvements
357
This page intentionally left blank.
Chapter 13: Multiple Temporary Databases | 359
Chapter 13
Multiple Temporary
Databases
Introduction
Whether you are doing ad-hoc queries or full applications in ASE,
the tempdb is an integral component of your environment. ASE-gen-
erated temporary worktables used for resolving order by and group
by clauses are always created in tempdb. In addition, your application
might create temporary tables in order to provide a facility to manage
and make subsets of data available for improved application perfor-
mance. Multiple temporary databases allow the DBA to separate the
application workloads by assigning each application to a specific
temporary database. The temporary database(s) to which the applica-
tion is assigned may be shared by several applications. Even if no
application is assigned to a particular temporary database or tempo-
rary database group, if multiple temporary databases do exist, users
will be delegated to only one temporary database for their current
session.
360 | Chapter 13: Multiple Temporary Databases
Prior to ASE 15
The tempdb database has been an essential component of ASE since
it was first developed in 1984. The purpose of the database is to man-
age temporary subsets of data that only need to persist for the SQL
statement, a portion of the statement, the entire user session, or across
user sessions. Any data that is stored in tempdb is considered to be
discardable in the event ASE is shut down for any reason. As you
may know, this is the only database that is refreshed each time ASE
is started.
Each time the ASE server is restarted, the model database is cop-
ied and used to create tempdb just like any other database is initially
created. This behavior has existed since version 3 of Sybase. The
tempdb database is created prior to any user-defined databases being
recovered during system startup.
Chapter 13: Multiple Temporary Databases | 361
With ASE 15
In ASE 15, all temporary databases are rebuilt at ASE startup just
like the default temporary database — tempdb. Unless the recovery
order is modified using sp_dbrecovery_order, all user-defined tem-
porary databases are created in the order of their database ID, just as
if they were going through the normal server recovery process. If a
user-defined database has a lower database ID, it will be recovered
prior to the temporary database being recovered. Temporary data-
bases are not necessarily recovered before a user-defined database.
There is a limit of 512 temporary databases that can be created in
each ASE server environment.
directio Support
The directio parameter is used to bypass writing updated pages to the
operating system’s buffer cache, thereby giving you raw partition
performance even though the temporary database devices are defined
in the file system. The directio option is only effective in those oper-
ating systems (OS) where direct I/O is supported and has been
activated by the OS administrator. Currently, it is supported only in
Unix and Linux operating systems. directio is a static option and
requires a server reboot in order for it to take effect. It can be set at
the device level with disk init, disk reinit, or sp_deviceattr. If you have
defined your devices for tempdb or other temporary databases with
362 | Chapter 13: Multiple Temporary Databases
dsync=false, the use of the directio option is available since these two
options are mutually exclusive (both of these options cannot be set to
true). With directio=true, the write to buffer cache is bypassed and the
write to disk for the page is forced. For temporary database devices,
this is not the behavior that is most efficient. With temporary data-
bases, the need to guarantee the write to disk is unnecessary as
recoverability is not an issue. Therefore, you will want to set
directio=false. Using the directio=false option and dsync=false will
provide improved performance for those databases where
recoverability is not an issue and where the server has I/O contention
at the disk level. You can tell if directio is active once the device
option has been set to true or false by the message written in the ASE
errorlog at startup when the device is initialized. The following
example indicates that dsync was set to false and directio was set to
true.
1> sp_deviceattr tempdb_d1, directio, true
2> go
'directio' attribute of device 'tempdb_d1' turned 'on'. Restart Adaptive
Server for the change to take effect.
(return status = 0)
The next example is the errorlog after the device’s directio option has
been set to false with sp_deviceattr.
1> sp_deviceattr tempdb_d1, directio, false
2> go
'directio' attribute of device 'tempdb_d1' turned 'off'. Restart
Adaptive Server for the change to take effect.
(return status = 0)
As you can see, there is no way to tell, just by looking at the errorlog,
that the device has directio set to false. Only by looking at the output
from sp_helpdevice can you be sure of the settings.
1> sp_helpdevice tempdb_d1
2> go
Chapter 13: Multiple Temporary Databases | 363
(1 row affected)
(return status = 0)
Even if sp_helpdevice shows that directio has been set to false, only
the OS administrator can determine if direct I/O is available at the
physical device level.
Therefore, for temporary databases, it is recommended that you
set both dsync=false and directio=false for the devices on which the
databases are allocated. These devices should only be used for their
assigned databases and for only temporary databases. As with any
recommendation, you should run a performance baseline, make your
changes, rerun your performance tests, and then compare the results
to those of your baseline.
Note that with ASE 15, temporary databases no longer write log
pages to disk unless the pages are flushed out of cache, thereby hav-
ing the effect of reducing the impact on the write load.
For more detail on the directio and dsync options, see the chapter
on initializing databases devices in Sybase’s System Administration
Guide.
update statistics
In ASE 15, the update statistics command creates a worktable in
tempdb. The worktable is used to store the statistics for each data par-
tition of a table. Since all tables are now created with a minimum of
one partition, this worktable creation should be accounted for when
resizing tempdb for ASE 15. Although the impact on size is minimal,
if you are running multiple update statistics concurrently against sev-
eral databases, you might want to consider adding additional space
— especially if you are updating the indexes and all column statis-
tics. With the update index or update all statistics options, it is
possible for the temporary worktables to be quite large. The amount
364 | Chapter 13: Multiple Temporary Databases
of additional space will depend on the size of the largest table in each
database.
Strategies
With the initial introduction of this feature, the strategies provided
allow for limited flexibility. As the functionality matures, additional
strategies need to be available for use.
A basic strategy for using multiple temporary databases is to
provide the system administrator (“sa” login) with the ability to log
into the ASE server and run system stored procedures — like
sysprocesses and syslogshold against virtual tables — when the main
tempdb database is full. This is probably the first reason a DBA will
use to justify adding a temporary database. When the main tempdb is
full, the “sa” may not be able to determine what process is filling up
tempdb. Without knowing which process to “kill,” the usual correc-
tive measure is to recycle the ASE server, which has further and
perhaps detrimental implications. Once the ASE server is recycled,
there may be limited or no information about what caused the tempdb
to fill up. By creating a tempdb database for “sa” usage only, the
database administrator will be assured of being able to log into the
ASE server and determine the cause of tempdb filling up. This will
allow the database administrator the ability to better determine the
cause of a problem that has affected tempdb and evaluate alternative
solutions other than recycling the ASE server. As a side note, the
MDA tables as discussed in Chapter 9 may be able to provide infor-
mation as to the culprit process that filled up tempdb. Also, with ASE
12.5.2, if the number of user connections has been exceeded and no
additional users can log into the server, a special reserved connection
is kept available by the server for the “sa” to use to log into the
server.
A second strategy deals with having multiple temporary data-
bases for all users to share. This strategy performs some load
balancing by assigning each new user who logs in the next available
temporary database in the group of multiple temporary databases
using a round-robin methodology. In the case where a temporary
366 | Chapter 13: Multiple Temporary Databases
database in the group is full, that database will be bypassed and will
not be used until space has been freed up.
A third strategy addresses separating applications onto different
temporary databases or temporary database groups. The purpose of
this strategy is to provide temporary databases that are not shared
across applications. (i.e., OLTP application users would not share
their temporary database with ad-hoc users). In this manner, search-
intensive applications that heavily exploit temporary space can be
segregated from normal applications. Furthermore, different storage
systems can be used for different purposes. For example, a high-
speed SAN might be used for OLTP users, while ad-hoc temporary
databases could be placed on slower, less expensive storage.
By choosing the proper mix of strategies, a flexible environment
can be created whereby the resources are maximized for the applica-
tions and users utilizing the ASE server.
Implementation Steps
The following steps are intended to ensure that you have properly
installed the feature. These steps are generalized to allow for leeway
in your implementation.
1. Determine whether the temporary databases need to have sepa-
rate data and log segments.
2. Determine the amount of space necessary for each temporary
database that will be created.
3. Define file systems with usable space equivalent to the space
requirements. The use of file systems over raw partitions is
selected since the databases are temporary databases and you will
want the extra performance from the file system buffering. Be
sure to specify the dsync=false ASE option on the disk init
command.
4. Define devices within ASE for each of the database devices.
5. Create the temporary databases using the temporary option of the
create database command (e.g., create temporary database
uc_tempdb_01 …).
6. Using the sp_dbrecovery_order system stored procedure, change
the recovery order of the databases so that the temporary data-
bases are recovered before the application databases.
7. Create temporary database groups and assign the new temporary
databases to the proper groups. If one of the databases is for “sa”
use, do not assign it to any group.
8. If one of the temporary databases is for “sa” use, use the
sp_tempdb system stored procedure to associate the “sa” login to
this database.
9. If desired, use sp_tempdb to associate an application to a tempo-
rary database group.
You are now ready to use multiple temporary databases.
368 | Chapter 13: Multiple Temporary Databases
For more details on each of the parameters, consult the Sybase prod-
uct manuals.
The third method uses a new dbcc function that allows a login
with sa role to get a list of available temporary databases. The new
command is dbcc pravailabletempdbs. Since this is a dbcc command,
you will need to specify the traceflag that is appropriate for viewing
the output. If you want the output to display at your terminal, specify
dbcc traceon (3604). Otherwise, the output will be written to the ASE
errorlog. See the example below for a sample of the output from this
new command. Be sure to note that only the database ID is displayed.
Example:
use master
go
dbcc traceon (3604)
go
dbcc pravailabletempdbs
go
Chapter 13: Multiple Temporary Databases | 369
Output:
Available temporary databases are:
Dbid: 2
DBCC execution completed. If DBCC printed error messages, contact
a user with System Administrator (SA) role.
go
disk init
name='sa_tempdb_log',
physname='/sybase/log/sa_tempdb_log',
size="10m",
dsync=false
go
t Create the temporary databases using the create temporary data-
base command. This is a full command in itself and should not
be confused with the create database command.
use master
go
create temporary database sa_tempdb
on sa_tempdb_data = 100
log on sa_tempdb_log = 10
go
t Create temporary database groups and assign the new temporary
databases to the various groups that each needs to be defined to.
The goal of temporary database groups is to provide a method
whereby the DBA can allocate temporary databases based on the
varying needs of different applications that share data on a
server. If one of the temporary databases is for “sa” use only, it
should not be assigned to any groups.
The group “default” is a system-generated group and the data-
base tempdb is automatically a member of the group. Normally
at this point, the DBA would use the sp_tempdb system stored
procedure to define a new temporary database group and assign
the new temporary database to one or more groups. Since the
newly created temporary database — sa_tempdb — is not for use
by all users, it is not added to the “default” group or any other
group. Using the who option of sp_tempdb will display a list of
active sessions that have been assigned to a temporary database.
use master
go
sp_tempdb 'who', 'tempdb'
go
sp_tempdb 'who', 'sa_tempdb'
go
Chapter 13: Multiple Temporary Databases | 371
Other Issues
@@tempdb
A new system variable has been defined for use in determining which
temporary database has been assigned to a user’s connection.
@@tempdb returns the name of the temporary database to which the
user’s connection is associated.
Summary
The multiple temporary databases feature existed prior to ASE 15 but
has been underutilized. The use of this feature should be considered
for applications where contention exists for tempdb. The utilization
of multiple temporary databases allows the DBA to segregate appli-
cations from each other and from the “sa” to allow for tempdb space
and resources to not be overused by any one individual or
application.
When deciding to use additional temporary databases, the DBA
needs to determine the needs of the business and consider the positive
performance impacts additional temporary databases can have on a
database application environment.
Chapter 14: The MDA Tables | 373
Chapter 14
The MDA tables were first introduced with the Sybase ASE 12.5.0.3
release. So why, then, do we include this topic in a book designed to
highlight the new features of ASE 15? There are several reasons.
First, the MDA tables are relatively new to Sybase ASE, so new in
fact, that despite their years of existence, few database administrators
use them due to lack of experience. Second, with the release of ASE
15, the opportunity exists to track the usage of semantic partitions
from the MDA tables. And lastly, of course, with any migration from
one release to another, spotting performance regression as well as
tuning the new release optimally are common exercises; MDA tables
provide the utilities to accomplish this.
information at the server level, the MDA tables report data at the
query and table level in addition to the server level. Further, the
MDA tables provide information on current activity at the table, pro-
cedure, query, and process levels.
Past Solutions
Prior to the introduction of the MDA tables, much of the information
that can now be extracted from the MDA tables was either impossi-
ble to obtain or difficult to sift through once obtained. Perhaps the
first real detailed performance analysis capabilities for ASE were
implemented using Monitor Server and Historical Server. For exam-
ple, to capture the top 10 worst performing queries, or top n stored
procedures that execute longer than three seconds, the DBA had to
construct Historical Server views similar to the following:
hs_create_view top10_spid_io,
"Process ID", "Value for Sample",
"Login Name", "Value for Sample",
"Current Stmt Start Time", "Value for Sample",
"Current Stmt CPU Time", "Value for Sample",
"Current Stmt Elapsed Time", "Value for Sample",
"Current Stmt Page I/O", "Value for Sample",
"Current Stmt Logical Reads", "Value for Sample",
"Current Stmt Page Writes", "Value for Sample",
"Current Stmt Batch Text", "Value for Sample"
go
One of the problems with this approach was that the Monitor Server
sometimes inflicted a substantial load on the ASE server with the
near continuous polling. Secondly, the amount of SQL captured in
the batch was often limited by the parameter max SQL text moni-
tored, which for complicated queries was insufficient unless set so
high that the overhead per connection made it inadvisable. Another
detractor was the configuration required event buffers per engine,
which often could require 100 MB or more of memory to prevent
substantial loss. And the lost events were often some of the more
recent events vs. older events, which was not exactly desirable.
A common solution to facilitate the collection of diagnostic and
monitoring information was the introduction of a third-party tool to
capture SQL and other low-level information. Typically, many tools
required the introduction of packet “sniffing,” or the routing of SQL
commands through an additional “monitoring” server. Most of these
tools existed as a “black box,” with the actual overhead and impact
unknown to the database administrator. In addition, each of these
solutions comes with trade-offs, various limitations, and additional
licensing fees.
376 | Chapter 14: The MDA Tables
Note: For this text, we will concentrate on installing the remote server as
a “loopback” to the originating ASE server. It is possible to configure the
MDA tables as proxy tables on the local server. In this manner, a central-
ized MDA server can be created. Also, the name “loopback” is not
required and, in SYBASE HA configurations, it must be changed as only
one of the servers can use the “loopback” alias. However, changing the
name requires altering the installmontable script appropriately, as would
installing on a central monitoring repository.
Finally, grant the mon_role to any administrative user who will need
access to the MDA tables:
exec sp_role 'grant','mon_role','sa'
go
exec sp_role 'grant','mon_role','mda_viewer'
go
To list all the MDA configuration options within Sybase ASE, run
sp_configure with monitoring as an argument:
exec sp_configure monitoring
go
Group: Monitoring
(Note that the format of your output may differ from what is shown
here.)
(return status = 0)
At this point in the installation process the MDA tables are still not
collecting data. The configuration parameters need to instruct Sybase
ASE to begin MDA data collection. What happens if you run SQL
against the MDA tables before the necessary configuration variables
are enabled? The bad news is that the query will fail. The good news
is ASE will instruct the database administrator, or user with the
sa_role, to specifically enable the correct configuration parameters
that are necessary to support the MDA table-based SQL statement.
Consider the following code example discussed later in this chapter:
select SQLText from monSysSQLText
where SQLText like "%Rental%"
TableName Description
monTables Provides a description of all of the available monitoring tables
monTableParameters Provides a description of all of the optional parameters for each
monitoring table
monTableColumns Provides a description of all of the columns for each monitoring table
monState Provides information regarding the overall state of the ASE
monEngine Provides statistics regarding ASE engines
monDataCache Provides statistics relating to data cache usage
monProcedureCache Provides server-wide information related to cached procedures
monOpenDatabases Provides state and statistical information for databases that are currently
in use (i.e., open databases)
monSysWorkerThread Provides server-wide statistics about worker threads
monNetworkIO Provides server-wide statistics about network I/O
monErrorLog Provides the most recent error messages raised by ASE. The maximum
number of messages returned can be tuned by use of the “errorlog pipe
max messages” configuration option.
monLocks Provides information for all locks that are being held and those that have
been requested by any process for every object
monDeadLock Provides information about the most recent deadlocks that have
occurred. The maximum number of messages returned can be tuned by
use of the “deadlock pipe max messages” configuration option.
monWaitClassInfo Provides a textual description for all of the wait classes, e.g., “waiting for
a disk read to complete.” All wait events (see the monWaitEventInfo
table) have been grouped into the appropriate wait class.
monWaitEventInfo Provides a textual description for every possible situation where a
process is forced to wait for an event, e.g., “wait for buffer read to
complete”
Chapter 14: The MDA Tables | 381
TableName Description
monCachedObject Provides statistics for all objects and indexes that currently have pages
cached within a data cache
monCachePool Provides statistics for all pools allocated for all caches
monOpenObjectActivity Provides statistics for all open objects
monIOQueue Provides device I/O statistics, broken down into data and log I/O, for
normal and temporary databases on each device
monDeviceIO Provides statistical information about devices
monSysWaits Provides a server-wide view of events that processes are waiting for
monProcess Provides information about processes that are currently executing or
waiting
monProcessLookup Provides information enabling processes to be tracked to an application,
user, client machine, etc.
monProcessActivity Provides statistics about process activity
monProcessWorkerThread Provides information about process use of worker threads
monProcessNetIO Provides statistics about process network I/O activity
monProcessObject Provides statistical information about process object access
monProcessWaits Provides information about each event that a process has waited for or is
currently waiting for
monProcessStatement Provides statistics for currently executing statements
monSysStatement Provides statistics for the most recently executed statements. The
maximum number of statement statistics returned can be tuned by use of
the “statement pipe max messages” configuration option.
monProcessSQLText Provides the SQL text that is currently being executed. The maximum
size of the SQLtext returned can be tuned by use of the “max SQL text
monitored” configuration option.
monSysSQLText Provides the most recently executed SQL text. The maximum number of
messages returned can be tuned by use of the “sql text pipe max
messages” configuration option.
monCachedProcedures Provides statistics about all procedures currently stored in the procedure
cache
monProcessProcedures Provides information about procedures that are being executed
monSysPlanText Provides the most recently generated plan text. The maximum number of
messages returned can be tuned by use of the “plan text pipe max
messages” configuration option.
monOpenPartitionActivity Provides statistics for all open partitions
382 | Chapter 14: The MDA Tables
Output:
DBName ObjectName PartitionName PartitionSize
master monProcessObject monProcessObject_604526156 2
Accounts Rental_RP Rental_RP_543990874 411588
Accounts Rental_RP Rental_RP_589245154 133814
Output:
PartitionID CacheName ObjectName PartitionName
589245154 default data cache Rental_RP Rental_RP_589245154
464004684 default data cache Rental_RP Rental_RP_543990874
Chapter 14: The MDA Tables | 383
Output:
PartitionName LogicalReads PhysicalWrites PagesWritten RowsInserted
Rental_RP_589245154 2584932 101559 101559 2298667
Rental_RP_605245211 8 2 2 0
Rental_RP_621245268 8 2 2 0
Note: The monOpenObjectActivity table has not changed and will pro-
vide the same information as previous releases. For partitioned objects,
the monitoring information is aggregated to provide monitoring informa-
tion for the object as a whole.
Output:
Time ErrorMessage
4/7/2005 11:56:19.576 PM 1 task(s) are sleeping waiting for space to
become available in the log segment for
database Accounts.
4/7/2005 11:57:19.576 PM 1 task(s) are sleeping waiting for space to
become available in the log segment for
database Accounts.
4/7/2005 11:58:19.576 PM 1 task(s) are sleeping waiting for space to
become available in the log segment for
database Accounts.
4/7/2005 11:59:19.583 PM 1 task(s) are sleeping waiting for space to
become available in the log segment for
database Accounts.
Output:
Time ErrorMessage
4/8/2005 12:00:53.213 AM Cannot read, host process disconnected:
2200 spid: 24
4/8/2005 12:01:19.563 AM 1 task(s) are sleeping waiting for space to
become available in the log segment for
database Accounts.
4/8/2005 12:02:19.563 AM 1 task(s) are sleeping waiting for space to
become available in the log segment for
database Accounts.
4/8/2005 12:03:19.573 AM 1 task(s) are sleeping waiting for space to
become available in the log segment for
database Accounts.
It is confirmed in the above example that only the data that has not
been reported since the last read is reported to the process belonging
to the mda_viewer login. But what if our requirements dictate we
capture the stateful table data and need to allow the same process(es)
to continually scan the same MDA data? The next section discusses a
framework to retain MDA table data in this manner.
Chapter 14: The MDA Tables | 385
Note these stateful tables are also considered “historical” tables; after
one login queries the table, subsequent queries from the same login
do not display the data. However, the data persists. The data persists
up to the maximum value specified in the controlling memory param-
eter. In the case of the MDA table monErrorLog, this parameter
would be errorlog pipe max messages. With errorlog pipe max mes-
sages set to 1000, on the 1001st write to the monErrorLog MDA
table, new inserts will “circle back” to replace the least recently
added record in the stateful table. Think of a cache structure that acts
as a ring or a doughnut to visualize this scenario.
The complete list of stateful historical tables is:
t monDeadLock
t monErrorLog
t monSysPlanText
t monSysSQLText
t monSysStatement
comments section of this shell script. The values provided in the shell
script could act as a starting point for MDA parameters for an initial
installation on a low-volume server.
#!/bin/ksh
#set -uvx
#
#---------------------------------------------------------------------
#
# Name -- MDA_Stateful_Extract.sh
#
# Purpose -- Extract data from MDA Stateful Historical Tables.
#
# By -- Brian Taylor
#
# Date -- 04/07/2005
#
#
# Server configuration dependancies:
#
# -- Support for monErrorLog
# sp_configure "errorlog pipe active", 1
# go
# sp_configure "errorlog pipe max messages", 1000
# go
# --Support for monDeadLock
# sp_configure "deadlock pipe active", 1
# go
# sp_configure "deadlock pipe max messages", 1000
# go
# --Support for monSysStatement
# sp_configure "statement pipe active", 1
# go
# sp_configure "statement statistics active", 1
# go
# sp_configure "statement pipe max messages", 10000
# go
# --Support for monSysSQLText
# sp_configure "sql text pipe active", 1
# go
# sp_configure "sql text pipe max messages", 10000
# go
# --Support for monSysPlanText
# sp_configure "plan text pipe active", 1
# go
# sp_configure "plan text pipe max messages", 10000
Chapter 14: The MDA Tables | 387
# go
#
# MDA_Database Table creation SQL:
#
# select * into MDA_database..monErrorLog
# from master..monErrorLog
# go
# select * into MDA_database..monDeadLock
# from master..monDeadLock
# go
# select * into MDA_database..monSysStatement
# from master..monSysStatement
# go
# select * into MDA_database..monSysSQLText
# from master..monSysSQLText
# go
# select * into MDA_database..monSysPlanText
# from master..monSysPlanText
# go
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Set script parameters
#---------------------------------------------------------------------
SERVER=$1
SERVER_NO=$2
DATABASE="MDA_database"
if [ $# -lt 2 ]; then
echo "Usage: $0 <SERVER> <SERVER NO>"
exit 1
fi
LOAD_USER="mda_viewer"
RECIPIENTS="[email protected]"
RUNDATE='date "+%m%d%y_%H:%M:%S"'
#---------------------------------------------------------------------
# Get Sybase Directory
#---------------------------------------------------------------------
if [ $SERVER_NO = "1" ]
then
SYBMAIN=/sybase
else
SYBMAIN=/sybase$SERVER_NO
fi
388 | Chapter 14: The MDA Tables
SYBASE=$SYBMAIN
OUTPUT_FILE=$SYBMAIN/scripts/MDA_Stateful_extract.out
#---------------------------------------------------------------------
# Get Sybase login password for server.
# NOTE: For simplicity and demonstration, the password is hard-coded
# into this script. Please protect your password in
# accordance with your company's security policy.
#---------------------------------------------------------------------
PWD=password
EOF
Chapter 14: The MDA Tables | 389
To get an idea of how much data is collected from the stateful tables,
the following snapshot of an MDA configured server is provided.
The counts are from a two-day examination of a development server
with minimal activity. Note the high counts for the monSysSQLtext,
monSysPlanText, and monSysStatement tables in relation to the
counts associated with the monErrorLog and monDeadlock tables:
monErrorLog
7479
monDeadlock
0
monSysStatement
275062
monSysSQLText
129321
monSysPlanText
227283
390 | Chapter 14: The MDA Tables
delete MDA_database..monDeadLock
where ResolveTime <= dateadd(dd,-30,getdate())
delete MDA_database..monSysPlanText
from MDA_database..monSysPlanText T,
MDA_database..monSysStatement S
where S.StartTime <= dateadd(dd,-3,getdate())
and S.KPID = T.KPID
go
delete MDA_database..monSysSQLText
from MDA_database..monSysSQLText T,
MDA_database..monSysStatement S
where S.StartTime <= dateadd(dd,-3,getdate())
and S.KPID = T.KPID
go
delete MDA_database..monSysStatement
where StartTime <= dateadd(dd,-3,getdate())
go
SQL Use
A primary benefit of the MDA tables is they allow the DBA to exe-
cute SQL against the tables in order to extract server information that
is otherwise unavailable through SQL. While the MDA tables can be
accessed with SQL, avoidance of certain SQL syntax is
recommended.
Avoid subqueries and joins on the MDA tables. Use the construct
of the “permanent” MDA table database mentioned earlier in this
chapter, or copy the targeted MDA rows to tempdb as the first step of
any query against the MDA data.
The MDA tables are memory resident. A join executed between
MDA tables will result in performance degradation for the target
instance of ASE. Additionally, two references to the same table in
one query, as provided in a self join, will likely result in the compari-
son of result sets that are not identical.
Output:
Sybase ASE Start Date
4/11/2005 2:47:19.956 PM
Output:
SQLText
select count(*) from Rental
Is the Rental table in cache, and if so, how much cache is taken up by
the table?
select ObjectName, CacheName, CachedKB from monCachedObject
where ObjectName = "Rental"
go
Output:
ObjectName CacheName CachedKB
Code default data cache 43
Output:
PhysicalName Writes
/dev/vx/rdsk/mdadg/dbspace9 21575
Chapter 14: The MDA Tables | 393
MDA Alternatives
An obvious alternative to MDA tables is sp_sysmon. In fact,
sp_sysmon and MDA tables share access to some of the same coun-
ters (as indicated by monTableColumns.indicators & 2=2). However,
because of the level of aggregation and lack of details, the
sp_sysmon procedure is appropriate for monitoring performance and
metrics at the server level. Some database administrators regularly
run sp_sysmon and capture the results to a file system in order to
monitor server-level performance over a period of time. This method
of system info extraction can be taken further with the addition of
scripting logic that harvests the sysmon information from files and
pushes this information back into the database. While this has not
been officially deprecated by Sybase, with little exception, the data
that can be collected by sp_sysmon can also be collected by MDA
tables — with the notable difference in the ease of extracting the
information as well as the additional details. One exception to this is
the Replication Agent counters, which are currently still visible from
sp_sysmon with no corresponding MDA table.
In Chapter 9, we presented information on how to capture Query
Processing Metrics. While the information is not as rich as that con-
tained in the MDA tables, Query Processing Metrics contains SQL
text information, as well as the tracking of information related to
statistics time and I/O.
Summary
The MDA tables provide low-level information DBAs can utilize to
track server, session, and database characteristics over time or in a
snapshot. In this text, we have provided a basic understanding of the
MDA tables and outlined some of the issues involved in the support
and setup of the MDA tables. Additionally, in maintaining the Sybase
ASE 15 flavor of this text, we have identified the limited MDA table
changes between ASE 15 and previous releases of ASE. Finally, we
suggest a set of alternatives to the MDA tables. Between the MDA
tables, the sp_sysmon system procedure, the QP Metrics process, and
many of the diagnostic tools available to the DBA, Sybase has pro-
vided a fairly robust and diverse set of “out-of-the-box” monitoring
capabilities.
This page intentionally left blank.
Chapter 15: Java, XML, and Web Services in ASE | 395
Chapter 15
Introduction
Java and XML in the database provide the ability to execute Java
code from within ASE. Additionally, XML can be stored within ASE
without having to break up the XML into relational tables. Sybase
has built on these features to allow Web Services to be defined within
the database. This chapter covers these three areas:
t Java in the database
t XML in the database
t Web Services
classes that are not appropriate inside a database engine. Sybase does
not support these classes. This includes the GUI Java API classes and
most network classes. See the Sybase documentation for more
information.
Performance Considerations
The above example defines the Java class column as being in-row.
An in-row object can occupy up to approximately 16 KB, depending
on the page size of the database server and other variables. This
includes its entire serialization, not just the values in its fields. If the
server cannot fit the object within the database row, an exception is
generated. The default value is off-row. An off-row object is stored in
the same manner as text and image data items and therefore will be
stored on separate data pages from the row itself. Therefore, for
better performance, it is recommended to have in-row Java objects,
but ensure the objects will fit within 16 KB. Use the following with a
Java class object to help you make this decision:
select datalength (new class_name(...))
Note that if you plan on using Java method calls within the where
clause of queries, a huge performance gain could be realized by cre-
ating a function-based index using the Java method call.
The main options to consider when storing XML data into ASE are
the following:
t Store the XML document into a text datatype.
t Store the XML document into an image datatype using the
xmlparse function.
Chapter 15: Java, XML, and Web Services in ASE | 403
The main benefits with this option are the storage requirement
within the database is much smaller, the speed of storing and retriev-
ing the XML documents is much faster, and the memory requirement
for storing the XML documents (i.e., "procedure cache size") is
much less. These benefits are obtained mainly because XML data is
highly compressible (typically greater than 90%) since, by its nature,
it contains repeatable text. Any compression utility will work. This
author used the zip classes within Java to create zip files as follows.
These zip files were then streamed into the image datatypes.
FileOutputStream fileOutputStream = new FileOutputStream(zipFilename +
".zip");
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
ZipEntry zipEntry = new ZipEntry(filename + ".txt");
zipOutputStream.putNextEntry(zipEntry);
xmlString.writeTo(zipOutputStream);
zipOutputStream.closeEntry();
zipOutputStream.close();
The proxy table that is created maps the XML document (the field
content above) into a logical image datatype. Except for the column
being an image datatype, users can access an element, attribute, or
sub-document within these documents using XPath the same way
they would if the XML document was stored in a text datatype. The
performance considerations are the same as if users were accessing
an XML document stored within a text datatype. There is no addi-
tional procedure cache requirement for inserting the document since
database insertion does not take place.
The "enable file access" and "enable cis" options have to be set
for this option. If the xmlextract function is used, the "enable xml"
option also needs to be set.
responses are relatively large and usually processed as one big chunk
of data, you should compress the responses.
In other words, evaluate the advantages and disadvantages for
each option and determine which option or combination of options
fits your application.
All Java Services have been turned off. None of the “XML in the
Database” features are dependent on the Java Services.
sp_configure "enable xml", 1
Conclusions
Some key conclusions from this test data that is referred to by the
various XML options are:
t Storing text XML documents in the database takes only a little
more storage than storing these same XML documents into a file
system.
t Indexing (parsing) the XML documents more than doubles the
database storage requirements.
t Compressing the XML documents before storing greatly
decreases the database storage requirements.
410 | Chapter 15: Java, XML, and Web Services in ASE
Web Services
Web Services in ASE give you the ability to execute SQL and stored
procedures with a web service interface. You also have the ability to
access external web services from within ASE. You do not, however,
have the ability to create web services. The following gives an over-
view. For more information, see the Web Services User’s Guide.
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<m:execute xmlns:m="urn:genwsdl.ws.ase.sybase.com"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<service xsi:type="xsd:string">server_name</service>
<userName xsi:type="xsd:string">user_name</userName>
<password xsi:type="xsd:string">password</password>
<sqlxOptions xsi:type="xsd:string">format=no,root=no</sqlxOptions>
<sql xsi:type="xsd:string">select ID, data from db..testTable</sql>
</m:execute>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The following is the resulting output response with the ID field hav-
ing the row number as its value and the data field having the string
value of “row x” where x corresponds to the row number:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<ns1:sessionID soapenv:actor="" soapenv:mustUnderstand="0"
xsi:type="xsd:long" xmlns:ns1="http://xml.apache.org/axis/session">
7987313730286340973</ns1:sessionID>
</soapenv:Header>
<soapenv:Body>
<ns2:executeResponse soapenv:encodingStyle="http://
schemas.xmlsoap.org/soap/encoding/"
xmlns:ns2="urn:genwsdl.ws.ase.sybase.com">
<executeReturn xsi:type="soapenc:Array"
soapenc:arrayType="ns3:DataReturn[1]"
xmlns:ns3="http://producer.ws.ase.sybase.com"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<item href="#id0"/>
</executeReturn>
</ns2:executeResponse>
<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://
schemas.xmlsoap.org/soap/encoding/" xsi:type="ns4:DataReturn"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns4="http://producer.ws.ase.sybase.com">
<XML xsi:type="xsd:string"><row><ID>1<
/ID><data>row 1</data></row><row>
<ID>2</ID><data>row 2</data><
/row><row><ID>3</ID><data>row 3
Chapter 15: Java, XML, and Web Services in ASE | 413
</data></row></XML>
<updateCount xsi:type="xsd:int">3</updateCount>
<DTD xsi:type="xsd:string"><!-- Cannot generate a DTD for the
rootless XML forest specified by the 'root=no' option
--> </DTD>
<schema xsi:type="xsd:string"><xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><
xsd:complexType name="RowType.resultset"><
xsd:sequence><xsd:element name="ID"type="
INTEGER"/><xsd:element name="data"
type="CHAR_10"/></xsd:sequence></
xsd:complexType><xsd:complexType name="
TableType.resultset"><xsd:sequence><
xsd:element name="row" type="
RowType.resultset"minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence></xsd:complexType><xsd:simpleType
name="INTEGER"><xsd:restriction
base="xsd:integer"><xsd:maxInclusive
value="2147483647"/><xsd:minInclusive
value="-2147483648"/></xsd:restriction>
</xsd:simpleType><xsd:simpleType name="
CHAR_10"><xsd:restriction base="xsd:string"
><xsd:length value="10"/><
/xsd:restriction></xsd:simpleType></xsd:schema>
</schema>
</multiRef>
</soapenv:Body>
</soapenv:Envelope>
This will take every operation name found within the WSDL and cre-
ate a proxy table to represent the inputs and outputs of the operation.
The proxy table name will be the same as the operation name (trun-
cated to 28 characters) unless the proxy table name for an operation
is overridden in the sp_webservices system procedure. Therefore, if
there are five operations with the WSDL, five proxy tables will be
created corresponding to those operations. For RPC/encoded opera-
tions, the proxy table will contain a column for each input and output
parameter where each input column name starts with an underscore
“_”. For document literal operations, the proxy table will contain two
columns: _inxml and outxml.
To invoke the web service operation, execute a select statement
against the proxy table supplying a value for all the input parame-
ter/columns. For example, the following executes a document literal
operation:
select outxml from getReportingInformation
where _inxml =
'<m:getReportingInformationRequest
xmlns:m="local:company:business:standard:reference">
<m:reportingID>
<m:rowID>501</m:rowID>
</m:reportingID>
<m:effectiveDate>2005-02-03</m:effectiveDate>
</m:getReportingInformationRequest>'
Chapter 15: Java, XML, and Web Services in ASE | 415
Appendix A
go
select au_id from pubs2..authors where au_id = "427-17-2319"
go
D. dbcc lstavailabletempdbs
E. None of the above
17. When creating Sybase devices for temporary databases, which of
the following are true?
A. The devices can be created on raw partitions.
B. The devices can be created as file system devices.
C. The dsync option of disk init should be set to false.
D. Two of the above
E. One of the above
F. All of the above
18. Given the following sequence of commands:
use master
go
sp_dbrecovery_order database_1, 1
go
sp_dbrecovery_order database_2, 2
go
sp_dbrecovery_order database_1, -1
go
sp_dbrecovery_order database_2, -1
go
sp_dbrecovery_order database_1, 3
go
sp_dbrecovery_order database_3, 1
go
32. In the following example, what is going to be the datatype for the
column total_cost?
create table parts_table
(part_no int,
name char(30),
list_price money,
quantity int,
total_cost compute quantity*list_price
)
A. int
B. money
C. numeric
D. None of the above
The next three questions are based on the following code scenario:
create table rental_materialized
(cust_id int, start_dt as getdate()materialized, last_change_dt
datetime)
39. If the above piece of code is executed within the same session in
the given order, the create procedure statement for inv_proc will:
A. Fail because it can’t find the #tempstores
B. Be created with some warning messages
C. Fail because insert_inv_proc doesn’t exist
D. None of the above
40. If the above piece of code is executed within the same session in
the given order, the create procedure statement for
insert_inv_proc will:
A. Be created with some warning messages
B. Fail because it can’t find the #tempstores
C. Be created with no warning messages
D. None of the above
41. Which of the following statements is true about the truncate table
command?
A. It is a non-logged operation.
B. It will fire the delete trigger.
C. It will fire the delete trigger if the table has a clustered index.
D. None of the above
42. Which one or more of the following events happen when a table
is dropped?
A. All the views associated with the table are also dropped.
B. All the triggers on this table are also dropped.
C. All the indexes on this table are also dropped.
D. None of the above
43. Which of the following is true about the tempdb:
A. A user needs to be aliased to guest ID in tempdb in order to
create objects as “guest.”
B. A table created in the tempdb with # prefix can be accessed
by multiple sessions.
C. A table created in the tempdb by the tempdb.. prefix can be
accessed by multiple sessions.
D. All of the above
428 | Appendix A: Sybase ASE 15 Certification Sample Questions and Answers
44. If copying the data into a table using bcp command fails, some of
the possible causes could be that:
A. The database has a transaction dump scheduled for every 15
minutes
B. The table has an insert trigger
C. The “select into/bulk copy” option for the database was
turned off
D. A database dump was not taken just prior to issuing the bcp
command
45. Which one or more of the following statements is true about
copying data into a table using the bcp command?
A. bcp observes any defaults defined for the column.
B. bcp observes any rules defined for the column.
C. bcp fires the insert trigger on the table.
D. None of the above
46. What does the flag “-e” do in an isql command?
A. It writes the errors into the errorlog.
B. It echoes the input commands.
C. It echoes the output.
D. It is an invalid flag for the isql command.
For questions 47 and 48, consider the following code sample:
declare CSR1 semi_sensitive scroll cursor
for select property_id, owned_date
from Rental..Properties
where property_id < 300
open CSR1
D. 1
E. None of the above
48. Which of the following are true about the cursor after fetch last is
executed?
A. The cursor must be closed after the last row is obtained.
B. All cursor rows are present in the cursor’s worktable after the
fetch last statement.
C. To resume processing the scrollable cursor, fetch first must
be issued to reposition the cursor’s pointer back to the first
row before fetching additional rows from the cursor.
D. Two of the above
E. None of the above
49. Update statistics can be performed at the following levels of
granularity:
A. Column
B. Partition
C. Index
D. Table
E. Three of the above
F. All of the above
50. Which of the following executions of the datachange function
will measure the data changed for the identification column of
the authors table, but only for the authors_part4 partition:
A. select datachange("identification","authors","authors_part4")
B. select datachange("authors_part4","authors","identification")
C. select datachange("authors","identification","authors_part4")
D. select datachange("authors","authors_part4","identification")
E. None of the above
51. Which of the following statements are true about datarows
locking?
A. It is the only lock granularity permitted on system tables.
B. It is the default locking strategy for ASE upon installation.
C. It can help eliminate contention for index pages.
D. None of the above
E. All of the above
430 | Appendix A: Sybase ASE 15 Certification Sample Questions and Answers
D. The bcp command will succeed, but only if the Rental table
is not a partitioned table.
E. None of the above
66. What set command will provide information similar to the
Graphical Plan Viewer but at the command-line level?
A. set showplan on
B. set statistics io on
C. set option show_best_plan long
D. set statistics plancost on
E. None of the above
67. Which of the following statements are true?
1) directio is a feature that is managed by ASE, not the operat-
ing system.
2) dysnc should be set to false for file system devices used by
temporary databases.
3) If dsync is set to true, directio can be set to either true or
false.
4) directio should be used with raw partitions.
A. 1, 2
B. 2, 4
C. 1, 3
D. 2 only
E. 3 only
68. Which databases are required by any ASE server?
1) master
2) model
3) tempdb
4) sybsystemdb
5) sybsystemprocs
6) sybsecurity
7) sybsyntax
A. 1, 2, 3, 4
B. 1, 2, 3, 5
C. 1, 2, 3, 5, 6
434 | Appendix A: Sybase ASE 15 Certification Sample Questions and Answers
D. 1, 2, 3, 4, 7
E. 1, 2, 3, 4, 5
F. All of them
69. Which of the following are valid SySAM reports?
1) Raw
2) Raw Data
3) Summary Barchart
4) Server Usage
5) Usage Summary
A. 2, 4
B. 1, 4, 5
C. 1, 3, 4
D. 2, 3, 5
E. 1, 3, 5
70. Which of the following are valid grace period activation
scenarios?
1) At server startup
2) Prior to the license expiration date
3) When a license feature is activated via sp_configure
4) When the license server is down
A. Three of the above
B. Two of the above
C. One of the above
D. All of the above
E. None of the above
71. Which of the following statements is true about
LM_LICENSE_SERVER?
A. It is required for a local license server environment.
B. It contains the name(s) of the redundant remote license
servers.
C. It has to be defined at the time that an ASE server is brought
up if that server is participating in a networked licensed
environment.
D. It contains the host and port number for network license
servers.
Appendix A: Sybase ASE 15 Certification Sample Questions and Answers | 435
72. When you create a table and do not specify the number of parti-
tions, how many partitions are created and of which partitioning
strategy?
A. One partition using round-robin partitioning
B. One partition using hash partitioning
C. Two partitions using range partitioning
D. Two partitions using round-robin partitioning.
73. Which of the following is not true about table/index partitioning?
A. A table can only be partitioned using one of the four parti-
tioning schemes.
B. A partitioned index can be either global or local.
C. A table partition can be dropped if it is no longer necessary.
D. A table can be altered to increase the number of partitions.
74. Which of the following is true about temporary worktables?
A. order by creates a temporary worktable.
B. group by creates a temporary worktable.
C. select distinct creates a temporary worktable.
D. Temporary worktables can only be created in tempdb.
E. The name of the user-defined temporary worktable can be
found in sysobjects.
75. Which is the lowest granularity of access that can be granted?
A. Database
B. Table
C. Column
D. Row
E. Data value
76. Given the following events, what is the correct order of events
for creating a user database?
A. Define the database
B. Define the devices
C. Define the stored procedures
D. Define the tables
E. Define the triggers
436 | Appendix A: Sybase ASE 15 Certification Sample Questions and Answers
22. B. system
The QP Metrics process uses a view called sysquerymetrics,
which is based on the sysqueryplans table. The sysqueryplans
table resides on the system segment for all databases
23. C. Load the Java source and compile the source within the
database.
Java source code cannot be compiled within the database. To
install a Java class from Java source code, the source code has to
be compiled using a Java compiler outside of ASE to create Java
byte code (in .class files). Those .class files are then saved into an
uncompressed JAR file (for example, using jar cf0), and then the
JAR file is loaded to an ASE database using the installjava
(Unix) or the instjava (Windows) Sybase utility.
24. B. "enable xml"
These XML query functions are not dependent on having Java
Services ("enable java") installed. Only the XML Services
("enable xml") need to be installed.
25. C. "enable cis" and "enable file access"
The create proxy_table command uses Component Integration
Services (CIS). By specifying mapping to an external directory,
the "enable file access" option also needs to be turned on. XML
Services "enable xml" only needs to be turned on if Sybase-spe-
cific XML capabilities are being used like the XML query
functions. If the XML document is just going to be retrieved in
whole, then XML Services are not needed.
26. D. "procedure cache size"
27. A. "heap memory per user"
Heap memory is an internal memory structure created at startup
that tasks utilize to dynamically allocate memory as needed. The
XML query function xmlparse uses this memory as work mem-
ory when creating the indexed or “parsed” XML document.
28. A and D
Currently the three optimization goals are allrows_mix,
allrows_dss, and allrows_oltp.
Appendix A: Sybase ASE 15 Certification Sample Questions and Answers | 441
29. A, C, and D
Optimization goals can be set at server level, session level, and
query level.
30. D
The parameter 10 is the amount of time ASE can spend optimiz-
ing a query as a percentage of the total time spent processing the
query.
31. C.
The query uses the best available plan and does not throw any
warning or an error message.
32. B
When the columns of different datatypes are used in a computed
column, the resultant column will have the datatype that has the
lowest hierarchy.
33. A
The getdate() value when the data was inserted
34. A
The keyword “materialized” means that the value of the column
is preevaluated and stored in the table as opposed to being evalu-
ated at the time of data retrieval.
35. B
The default characteristic of a computed column is
“materialized.”
36. D
Computed columns cannot have default values and they are
nullable by default.
37. B
SERVER_NAME.krg stores the information about the shared
memory segments used by the server.
38. B
System stored procedures are created in the sybsystemprocs data-
base and can be invoked from any database.
442 | Appendix A: Sybase ASE 15 Certification Sample Questions and Answers
39. B
The message you will get is “Number (2007) Severity (11) State
(1) Server (SYBASE) Procedure (inv_proc) Cannot add rows to
sysdepends for the current stored procedure because it depends
on the missing object 'insert_inv_proc'. The stored procedure will
still be created.”
40. B
The message you will get is “Number(208) Severity (16) State
(1) Server (SYBASE) Procedure (insert_inv_proc)#tempstores
not found. Specify owner.objectname or use sp_help to check
whether the object exists (sp_help may produce lots of output).”
41. A
truncate table is a non-logged operation.
42. B and C
When a table is dropped, the associated indexes and triggers are
also dropped. The associated views remain in the database but
generate an error when invoked.
43. C. A table created in the tempdb by the tempdb.. prefix can be
accessed by multiple sessions.
44. C
“select into/bulk copy” should be set to true for the database
before attempting to bcp in the data.
45. B and C
When data is copied into a table using the bcp command, the
insert trigger is fired and the rules defined for a column are
followed.
46. B
“-e” option echoes the input commands.
47. A. 2
The fetch next will execute, but no rows will be returned from
the cursor, as the cursor cannot fetch rows that are beyond the
end of the cursor. The @@SQLSTATUS value of 2 in this sce-
nario indicates the end of the cursor is obtained.
Appendix A: Sybase ASE 15 Certification Sample Questions and Answers | 443
48. B. All cursor rows are present in the cursor’s worktable after the
fetch last statement.
When the last row of a scrollable sensitive cursor is obtained, the
worktable is fully populated and cursor processing will no longer
lock the base table as rows are fetched, only pages/rows belong-
ing to the cursor’s worktable.
49. F. All of the above
With ASE 15, database administrators can update statistics to tar-
get data that is local to a single semantic partition. All other
partition update levels were already allowed on pre-ASE 15
servers.
50. D. select datachange ("authors","authors_part4","identification")
The other answers are all incorrect syntax and will generate an
error from ASE.
51. C. It can help eliminate contention for index pages.
On tables where datarows or datapages locking are employed,
locks on index pages are held as “latches,” which are
transactional locks on index pages. These locks are not held for
the duration of a transaction, thus the reduction in contention for
index pages with datarows locking.
52. A. XML in the database
For ASE 15, XML is available with the base installation of ASE,
and is not dependent upon Java in the database to operate.
53. A, B, D
ASE supports row-, page-, and table-level locking.
54. A, C
For ASE 15, it is possible to perform reorgs at the partition level
on datarows and datapages locked tables.
55. A, B, D
A semantic partition cannot be bound by itself to named cache,
while the other listed objects can be separately bound to a named
cache.
444 | Appendix A: Sybase ASE 15 Certification Sample Questions and Answers
56. D. Eight
Eight pages is equal to one extent. One extent is the minimum
size for the nonclustered index in this question.
57. B. U.S. Social Security numbers
U.S. Social Security numbers are unique, and the likelihood of
the partitions being equally balanced with unique keys is higher
than the likelihood without. The repetitive key values that are
likely with the incorrect answers will hash to the same partition,
likely resulting in partition skew.
58. A. Hide virtual computed columns.
The hide-vcc bcp option instructs the bcp command to not copy
virtual computed columns. This option can be used for bcp in and
out.
59. E. 4 terabytes
60. A. where order_number > 12345
B is not a SARG since the search contains a like statement. C is
not a SARG since it contains a not equal comparison operator. D
is not a SARG since the search is based on a computation.
61. C. Is only used during the upgrade process
It is a copy of the syspartitions system table used on pre-ASE 15
servers. After an upgrade to ASE 15, this table will not contain
any data.
62. A. Fail, since a table cannot have more than one clustered index
It is not possible to have a clustered global and clustered local
index on the same table.
63. C. sybmgmtdb
The sybmgmtdb is an optional database as it is installed as part of
the Job Scheduler, which is an optional product.
64. C. Nulls
count(*) counts all rows in the table, regardless of duplicate data
or nulls. count does not count null data.
Appendix A: Sybase ASE 15 Certification Sample Questions and Answers | 445
Appendix B
Use Cases
• Semantic partitions
• Computed columns
t Case 2:
• XML
• Computed columns
• Functional indexes
t Case 3:
• Scrollable cursors
448 | Appendix B: Use Cases
Business Case 1
For business reasons, Company X must maintain a large amount of
historical data within ASE’s databases available to the user base. As
the volume of data expands over time into hundreds of gigabytes of
space utilization, the maintenance windows continue to increase and
performance degradation is apparent. Additionally, the business has
evaluated several possible scenarios on how to manage this data
explosion, while balancing data availability, maintenance windows,
and complexity of implementation.
For Company X four basic options are proposed, each with its
own inherent advantages and some limitations. The options presented
assume the company cannot simply delete old data or take historical
data into an offline state. The options also assume all data will be
retained in one ASE server in order to avoid additional infrastructure
and to control license costs.
t Option 1: One VLDB with large tables self contained
t Option 2: Primary database and an archive database for the larg-
est tables
t Option 3: Several small databases, each holding a portion (none
overlapping) of the data from the very large tables
t Option 4: One VLDB with a large table, partitioned semantically
Advantages
t No special programming logic to access the one large table
t No need to create a view to span multiple databases or tables to
simplify application development
t Initially the simplest solution to implement
Limitations
t Maintenance performed on the large tables and databases as a
whole
t dbccs, reorgs, index maintenance, and update statistics operations
must address full tables and/or databases
t Optimizer must consider table as a whole when useful index is
not present
t Must carry overhead of extra free space within the database to
perform reorg/index rebuilds for largest table
t Must physically delete old data from the production database
t Cannot make older data read-only
t Recovery operations can be more time consuming than other pro-
posed solutions as Backup Server must load database as a whole,
including allocated but not used database pages when performing
a full restore
Appendix B: Use Cases | 451
With this solution, two databases are created. One database contains
a table that holds the data that is used to provide results for a period
of time that is considered “current.” In this use case the contents of
that table provide results for 85% of the application queries. The sec-
ond database contains a large table — potentially very large —
containing data that is maintained for historical purposes, such as
contract requirement, government requirement, etc. Database admin-
istrators perform maintenance on the two databases and the two
tables as a whole. For the smaller database/table, the response time of
the application is of major concern as is any impact by database
maintenance activities.
For a very large APL locked table in the larger database, reorga-
nization of the table must be performed with a drop and recreate of
the clustered index. In order to accomplish a drop and recreate of the
clustered index on the large table, upward of 200% of the table’s size
must be available as free space within the database to recreate the
clustered index and thus eliminate any fragmentation. Even though
the smaller database/table requires the same amount of extra space
for recreating the clustered index, the fact that the entire table is
locked during the index rebuild will affect the uptime of the
application.
452 | Appendix B: Use Cases
For DOL locked tables, reorg rebuild operations must also main-
tain up to 200% of large table size to complete. dbccs must be
performed on both databases and tables as a whole. Update statistics
must be performed targeting the specific indexes or columns, table
wide. In many instances, the update statistics operations and the reor-
ganization of fragmented data is often not possible with large
amounts of data due to the maintenance window requirements to per-
form these operations.
The performance on the current data database will be affected
while the data is copied to the historical database and then dropped
from the current database/table.
For queries that need to access data from both the current and the
historical tables, the data can be unioned. For those queries where the
data is from either one or the other database, a mechanism has to be
developed and maintained that tracks where the date ranges occur.
This mechanism has to be accessed to determine the database to use
to resolve the query each time data is requested. In some rare cases,
the request may have to be broken down into two queries to be
resolved, particular if the data is being archived at the time of the
request.
Advantages
t Maintenance can be performed on current data, as current data is
contained in only the primary database.
t Application development could be simplified with the creation of
a view of the “same” table across the current and history
databases.
t The archive database can be placed into a read-only mode.
t Maintenance of the archive database will decline dramatically
when in read-only mode as changes are not permitted, except for
when data is archived on a periodic basis from the primary
database.
Limitations
t Must carry out joins across two databases if a query needs simul-
taneous access to current and history data
t Cannot update history data with database in read-only mode
Appendix B: Use Cases | 453
Advantages
t Ability to backup/restore at a more granular level
t Ability to make databases with older data read-only
t May be feasible to create a view to join together the same tables
that are fragmented across multiple databases
Limitations
t Introduces fragmentation at the table level into the system design
t Need for special logic to access data that scans horizontally parti-
tioned tables that physically span multiple tables in multiple
databases
t Overhead must be carried out in each individual database to
accomplish reorgs and index maintenance
t More overhead for database administrators to maintain additional
databases
Appendix B: Use Cases | 455
With ASE 15, this option is now possible. Although the data will be
stored in one large table, partitioning allows for maintenance to be
performed on only the necessary partitions. Also, the application does
not need to be aware of where the data is located — on which data-
base and in which table. The optimizer can eliminate unnecessary
access to partitions where the data is not needed to satisfy the request.
Since the partition key only needs to know which month is being
stored, a materialized computed column can be created that uses only
the month part.
Advantages
t No special programming logic to access segregated data
t Only one table/database to access
t Maintenance operations, such as reorgs, dbccs, index mainte-
nance operations, and update statistics, can be targeted to very
specific subsets of data
t Partition-aware optimization. Optimizer will eliminate from con-
sideration the partitions not needed to satisfy a query
456 | Appendix B: Use Cases
Limitations
t Backups/restores of database can be time consuming
t Cannot drop old partitions (old data), only truncate
t Cannot make portions of the data read-only
t Database administrator should monitor for partition balance with
some partition types
Business Case 2
Company Y’s system must now consider the integration of XML
document storage within their relational database. The company
needs the ability to quickly scan for keywords within the XML docu-
ments in order to determine which documents to retrieve.
How can ASE 15 help this organization? With consideration to
XML storage methods (internal vs. external) to the database, com-
puted (materialized) columns, and functional indexes.
Option 1
If database storage isn’t an issue and only a few elements within the
XML documents are needed to retrieve the documents, then the easi-
est way to accomplish the above goal is to create a table with a text
datatype to store the XML documents and computed columns based
on elements within the XML documents. For example:
create table xml (xml text,
ID int compute xmlextract('//ns0:geographyID/text()', xml)
materialized)
Advantages
t Fast access to data within the XML documents where a func-
tional index is employed
t Storage requirement requires little more than the actual raw size
of the actual XML document
Limitations
t Slow access to data within the XML documents for large docu-
ments and the data is not contained within a materialized column
t Extended time to load the XML data into ASE for large docu-
ments materializing a number of columns
Option 2
If the number of elements needed to find the XML documents
becomes great, the number of materialized columns can be limited to
one or two. Then the xmlextract function can be used within the
where clause to find the XML documents. For example:
where ID = 100 and
xmlextract('//ns0:geographyID/text(), xml) = 200
This might create a performance issue if the XML documents are too
large. To increase performance, the XML documents would need to
be indexed or “parsed” using the xmlparse function.
Advantages
t Fast access to data within the XML documents
t More flexibility in changing the columns being used in the where
clause without causing performance issues
Limitations
t The storage requirements are more than double those of Option
1.
t The memory requirement and the time needed to load the
indexed XML documents increases exponentially with the size of
the documents.
458 | Appendix B: Use Cases
Option 3
If database storage becomes an issue, an option would be to store the
XML documents in a compressed form in an image datatype. This
can only be done if the needed elements can be extracted from the
XML documents outside of the database and then inserted into sepa-
rated columns within the table. This gives the same ability to retrieve
the XML documents as Option 1, but places the work to extract the
elements within the XML documents on the application outside of
the database. It also forces the application to compress and
uncompress the XML documents.
Advantages
t Considerably less storage requirements within ASE
t XML in the database license not required
Limitations
t Cannot use the xmlextract function within the where clause for
data with the XML documents
t Additional logic needed in application logic to store and retrieve
XML documents
Option 4
Another way to solve a database sizing issue is to store the XML
documents into a file system directory and map the XML documents
to a logical proxy table. A view can then be created to eliminate the
unnecessary columns from the proxy table and to add additional col-
umns based on the XML document file name and/or data within the
XML document.
With this option, users cannot simultaneously insert additional
columns for data not contained within the XML document. All the
other options would allow descriptive data to be added within the
same row as the XML document. This data could then be used to
query for the XML document. Within this option, there is no physical
table within the database containing the XML document; therefore,
descriptive data would have to be contained within its own table and
related to the XML document via some ID common to both. The
Appendix B: Use Cases | 459
appearance of the XML document through the proxy table and the
inserting of this descriptive data cannot be wrapped within a database
transaction.
The following is an example of creating a proxy table and view:
create proxy_table _xmlDirectory external directory at
"/remotebu/disk_backups/xmlDirectory"
create view xmlDirectory
(ID, code, xml) as
select convert(integer, substring(filename, 6, 3)),
convert(varchar(10), xmlextract('//ns0:geographyID/text()',
content)), content
from _xmlDirectory
Advantages
t No need to store XML into ASE
t No memory requirements for storing XML into ASE
Limitations
t Users cannot simultaneously insert additional columns for data
not contained within the XML document
t Slow access to data within the XML documents for large
documents
t The "enable file access" and "enable cis" options have to be set
for this option
Business Case 3
facility will begin to slow as the new orders cannot begin to process
due to the future dated start date associated with the order.
Proposed Solutions
The IT developer assigned to this project at Company Z considers
three alternatives in order to accommodate this request. The first is
the use of #temp tables in order to isolate the 50 rows that need their
order dates updated. With this method, rows are extracted from one
or more user tables and from one or more databases into a temporary
table in the tempdb database. Within the tempdb database, a user pro-
cess continues by isolating the 50th through 100th rows, with “set”
logic and “select into” along with the creation of additional #tempo-
rary tables. Once the 50th through the 100th rows are isolated,
updates are applied to the base table(s).
In the second example, the IT developer considers the use of
standard pre-ASE 15 cursors. Using this methodology, a process
reads 1,000 or more rows into the nonscrollable cursor. Since the
developer is only interested in the 50th through the 100th rows of the
cursor, additional processing is necessary. In order to target the 50th
row, the cursor must fetch and discard the 1st through the 49th cursor
rows before obtaining the needed 50th row. Once the 50th row of the
cursor is obtained, processing proceeds by updating the base table
where the current cursor row relates to the rows in the base table(s).
The third option is only possible with ASE 15.0 and greater. The
third option employs the use of a scrollable cursor to directly position
the cursor pointer at the 50th row in the cursor. From the 50th row
forward, the cursor can traverse forward until all necessary rows are
accessed and the corresponding base table is updated.
Note: While the scenario presented in this business case is fictional and
may not be realistic, the message the authors convey is the simplicity
and elegance presented with the scrollable cursor in comparison to the
complexity associated with the options where a more traditional cursor or
temporary table are employed.
Appendix B: Use Cases | 461
Option 1
To facilitate this scenario, a temporary table called #order_temp is
generated from a select into statement:
-- build the temp table with all orders that have not started
processing.
select * into #orders_temp
from orders
where order_date > (select max(order_date)
from orders
where processed = "Y")
and processed = "N"
Next, the first 50 rows would need to be deleted from the temporary
table:
set rowcount 50
delete #orders_temp
go
Using the same interim set, update the 50th to 100th rows in the
orders table:
update Accounts..orders
set order_date = "12/31/3000"
from orders c,
#order_temp2 t
where t.order_id = c.order_id
462 | Appendix B: Use Cases
Advantages
t Can be performed on any supported version of ASE
t The temporary table could be made to persist beyond the scope
of the user session if necessary.
t Can take multiple passes at each row in the #temporary table if
needed
Limitations
t Moderate complexity
t Must complete multiple steps to isolate the target rows
t Locks briefly held on tempdb’s system tables
Option 2
For Options 2 and 3, the following diagram represents the rows
needed by the cursor.
Cursor CSR1
Appendix B: Use Cases | 463
open CSR1
Set the cursor rows to 50 in order to fetch the first 50 rows, and dis-
card them:
set cursor rows 50 for CSR1
fetch CSR1
Fetch the cursor rows into local variables, then use the variables to
update the base table within a while loop to perform the update 50
times:
declare @order_id int,
@order_date datetime,
@counter int
select @counter = 50
fetch CSR1
into @order_id, @order_date
update Accounts..orders
set order_date = "12/31/3000"
where order_id = @order_id
Advantages
t Can be performed on any supported version of ASE
Limitations
t Additional steps to fetch and discard the unneeded rows
t Can only take one pass at each row if multiple passes per row
were necessary
t Moderate to low complexity
t Must complete multiple steps to isolate the target rows
Option 3
Use a scrollable cursor to set the cursor position directly at the 50th
row in the result set.
Declare and open the cursor to process the rows:
declare CSR1 scroll cursor for
select order_id, order_date
from orders
where order_date > (select max(order_date)
from orders
where processed = "Y")
and processed = "N"
open CSR1
Fetch the cursor rows into local variables, then use the variables to
update the base table within a while loop to perform the update 50
times. Use the fetch orientation of absolute to skip to the 50th cursor
row and to control the cursor position.
declare @order_id int,
@order_date datetime,
Appendix B: Use Cases | 465
@counter int
select @counter = 50
update orders
set order_date = "12/31/3000"
where order_id = @order_id
Advantages
t Low complexity
t Most elegant solution; can directly access the rows needed in the
result set without special processing
t Can take multiple passes at each row if necessary
Limitations
t Can only create and manipulate scrollable cursors on ASE 15
and greater
t Will use tempdb to hold the scrollable cursor
This page intentionally left blank.
Index | 467
Index
@@cursor_rows, 52, 149 preinstallation process for Unix
@@fetch_status, 52, 149 environments, 332-333
@@optgoal, 170 using dataserver executable, 352-356
@@rowcount, 148-149 using GUI, 332-352
@@setrowcount, 52 using srvbuild executable, 332-352
@@tempdb, 372 with resource file, 325-329
@@textdataptnid, 52 audit_event_name() function, 48
@@textptnid, 52 automatic database expansion, 15-18
Automatic Update Statistics, 22
A
absolute extension, 151 B
abstract plans, 207 bcp utility, 39-43
evaluating, 195 using to alter table, 125
allrows_dss optimization goal, 169-170 bcp client, 42-43
allrows_mix optimization goal, 169 biginttohex() function, 48
allrows_oltp optimization goal, 168-169, business cases, 448-456, 456-459, 459-465
179-181, 208-209 by range keyword, using, 126-128
alter table command, 125-131, 235-236
ASE, C
configuring for semantic partitioning, certification exam, sample, 11, 417-446
62-63 clustered non-partitioned non-prefixed
Java and, 11 index,
pre-15 features, 10-11, 13-19 on hash partitioned table, 108-110
pre-15 SySAM features, 298 on list partitioned table, 101-103
using tempdb in pre-15, 360 on round-robin partitioned table,
XML and, 11 106-108
ASE 15, clustered non-partitioned prefixed index,
and computed columns, 235-239 on hash partitioned table, 110-112
implementing SySAM in, 312-313 on list partitioned table, 99-101
installing, 9 on round-robin partitioned table,
MDA tables in, 382-383 104-106
new configuration parameters, 51 clustered non-prefixed index, on range
new features, 4-9, 19-44 partitioned table, 97-99
new functions, 48-50 clustered prefixed index, on range
new global variables, 52 partitioned table, 95-97
optimizer, 124 computed column index, 8, 242
partition support in, 63-64 and optimizer statistics, 251
query processor improvements, benefits of using, 246-248
174-184 creating, 243
sample certification exam, 11, 417-446 guidelines for using, 246
using SySAM with, 299 impact on existing code, 249
using tempdb in, 361-364 restrictions on using, 248
ASE installation, 9, 323-324 showplan output, 244-245
of components, 330-332 using with tempdb, 248
preinstallation process, 324-325 when to use, 250-251
468 | Index
AutoCAD LT 2006 Embedded Systems Access 2003 Programming by Learn FileMaker Pro 7
The Definitive Guide Desktop Integration Example with VBA, XML, and ASP 1-55622-098-7 • $36.95
1-55622-858-9 • $36.95 1-55622-994-1 • $49.95 1-55622-223-8 • $39.95 6 x 9 • 544 pp.
6 x 9 • 496 pp. 6 x 9 • 496 pp. 6 x 9 • 704 pp.
SQL Anywhere Studio 9 Advanced SQL Functions in Macromedia Captivate 32/64-Bit 80x86 Assembly
Developer’s Guide Oracle 10g The Definitive Guide Language Architecture
1-55622-506-7 • $49.95 1-59822-021-7 • $36.95 1-55622-422-2 • $29.95 1-59822-002-0 • $49.95
6 x 9 • 488 pp. 6 x 9 • 416 pp. 6 x 9 • 368 pp. 6 x 9 • 568 pp.
Excel 2003 VBA Programming with Unlocking Microsoft C# v2.0 SQL for Microsoft Access Word 2003 Document Automation
XML and ASP Programming Secrets 1-55622-092-8 • $39.95 with VBA, XML, XSLT, and Smart
1-55622-225-4 • $36.95 1-55622-097-9 • $24.95 6 x 9 • 360 pp. Documents
6 x 9 • 700 pp. 6 x 9 • 400 pp. 1-55622-086-3 • $36.95
6 x 9 • 464 pp.
Programming Game AI by Game Design Theory & Practice Polygonal Modeling: Basic and Essential LightWave 3D [8]
Example (2nd Ed.) Advanced Techniques 1-55622-082-0 • $44.95
1-55622-078-2 • $49.95 1-55622-912-7 • $49.95 1-59822-007-1 • $39.95 6 x 9 • 624 pp.
6 x 9 • 520 pp. 6 x 9 • 728 pp. 6 x 9 • 424 pp.