DisCopy


Sunday, 22 July 2012

Sybase ASE Performance Tuning FAQ...

Understanding Query Processing
The query processor processes queries that you specify. The processor yields highly efficient query plans that execute using minimal resources and ensure that results are consistent and correct.
To process a query efficiently, the query processor uses:
·         The specified query
·         Statistics about the tables, indexes, and columns named in the query
·         Configurable variables
To successfully process a query, the query processor must execute several steps across several modules:
Query processor modules
Graphic showing the query process modules as stacked boxes, with the Parser, preparser, optimizer, code generator, procedural execution engine, and query execution engine as labled boxes.
·         The parser converts the text of the SQL statement to an internal representation called a query tree.
·         The preprocessor transforms the query tree for some types of SQL statements, such as SQL statements with subqueries and views, to a more efficient query tree.
·         The optimizer analyzes the possible combinations of operations (join ordering, access and join methods, parallelism) to execute the SQL statement, and selects an efficient one based on the cost estimates of the alternatives.
·         The code generator converts the query plan generated by the optimizer into a format more suitable for the query execution engine.
·         The procedural engine executes command statements such as create table, execute procedure, and declare cursor directly. For data manipulation language (DML) statements, such as select, insert, delete, and update, the engine sets up the execution environment for all query plans and calls the query execution engine.
·         The query execution engine executes the ordered steps specified in the query plan provided by the code generator.

How locking affects performance
Adaptive Server protects the tables, data pages, or data rows currently used by active transactions by locking them. Locking is a concurrency control mechanism: it ensures the consistency of data within and across transactions. Locking is needed in a multiuser environment, since several users may be working with the same data at the same time.
Locking affects performance when one process holds locks that prevent another process from accessing needed data. The process that is blocked by the lock sleeps until the lock is released. This is called lock contention.
A more serious locking impact on performance arises from deadlocks. A deadlock occurs when two user processes each have a lock on a separate page or table and each wants to acquire a lock on the same page or table held by the other process. The transaction with the least accumulated CPU time is killed and all of its work is rolled back.
Understanding the types of locks in Adaptive Server can help you reduce lock contention and avoid or minimize deadlocks.

To help reduce lock contention between update and select queries:
·         Use datarows or datapages locking for tables with lock contention due to updates and selects.
·         If tables have more than 32 columns, make the first 32 columns the columns that are most frequently used as search arguments and in other query clauses.
·         Select only needed columns. Avoid using select * when all columns are not needed by the application.
·         Use any available predicates for select queries. When a table uses datapages locking, the information about updated columns is kept for the entire page, so that if a transaction updates some columns in one row, and other columns in another row on the same page, any select query that needs to access that page must avoid using any of the updated columns.

Sybase P n T FAQ

1.    Define two ways of measuring performance.
Ans. Response time and throughput.

2.    What are the four (4) major phases of Adaptive Server Optimizer?
Ans.   Parse, normalize, preprocessing, and optimize.

3.    What is optdiag used for?
Ans. ASE utility used to read, write, and simulate statistics.

4.    What is the name of the GUI tool provided with the product that can capture abstract plans?
Ans. Planviewer

5.    What are the three ways that table data can be accessed?
Ans. A table scan, a nonclustered index scan, or a clustered index scan.

6.    How can you avoid last page contention on an APL heap table when many inserts and/or updates are made simultaneously?
Ans. Create a clustered index on the column that provides the most “randomness.”

7.    Which is usually faster — a nonclustered index that covers the query or a clustered index?
Ans. A nonclustered index or a DOL clustered index that covers the query is usually faster than an APL clustered index.

8.    In which system tables are optimizer statistics stored?
Ans. systabstats and sysstatistics

9.    What command do you use to flush statistics from memory?
Ans.  sp_flushstats <object_name>

10. What happens if housekeeper free write percent is set to zero?
Ans. The housekeeper does not run any of its tasks and so statistics are not flushed to systabstats.

11. When can the Query Optimizer use an index to provide results for a query?
Ans. The query optimizer can use an index only when a query references the indexed column(s) in the where clause.

12. What is the meaning of Join Transitive Closure (JTC)?
Ans. Join Transitive Closure (JTC) adds possible joins that are not explicitly stated in the where clause.

13. What is meant by the term "Index Covering"?
Ans. Only used with nonclustered indexes on APL tables and either clustered or nonclustered indexes on DOL tables (as DOL clustered indexes have a leaf level above the data level). It refers to the condition where the index pages contain all the necessary data to proved results of a query, therefore, Adaptive Server does not need to access the data pages.

14. Which of the three optimization goals is the default for ASE 15.0?
a.  allrows_oltp
b.   allrows_mix
c.  allrows_dss
Ans.   a.   allrows_mix

15. How can you display the details of missing statistics from join columns?
Ans.  set option show_missing_stats will display the details of missing statistics from join columns

16. During query plan optimization, what settings does the optimizer look at to determine the total number of worker processes During query plan optimization, what settings does the optimizer look at to determine the total number of worker processes available for the query?
Ans. When the optimizer compiles a query plan, it looks at max parallel degree, max scan parallel degree, and the parallel clause of the select statement to determine the total number of worker processes available for a query.


17.    When is an adjusted query plan created and how does it differ from the optimal query plan?
Ans. An adjusted query plan is created when the number of worker processes specified in the optimal query plan is not available at runtime. The adjusted query plan differs from the optimal query plan in that it contains a smaller number of worker processes and it may use serial access instead of parallel access for some or all of the tables in the query.

18.   What command would you use to run all queries in the current session in serial mode?
Ans. set parallel_degree 1

19. How can you see whether runtime adjustments are occurring?
Ans. Using the set process_limit_action command, showplan, or sp_sysmon.

20. What type of updates are available to the optimizer?
Ans. In-place, cheap, expensive and deferred

21.  With respect to data placement, how do APL clustered indexes function differently from DOL clustered indexes?
Ans. APL clustered indexes maintain the table in index key order. As new rows are inserted, they must be inserted in their correct index position. DOL Clustered indexes are placement indexes. If the row fits on in its appropriate location, it will insert in index key order, otherwise it will be inserted into the page with the next available space to hold the row. This cause the DOL table to end up out of index key order.

22.  Are APL data page deallocations handled differently from DOL data page deallocations? If so, how?
Ans. Yes, when the last row is deleted on an APL data page, the page is deallocated and returned to the list of available pages for the table. DOL deletes are logical therefore, when the last row is deleted from the page it is not physically removed and the page will not be deallocated until the housekeeper GC performs garbage collection or reorg is executed against the table.

23.  How can you avoid deferred updates?
Ans. You can avoid deferred updates by avoiding updates and deletes through joins, having an unique index somewhere on the table and using a different column in the where than the column being changed in the set clause.

24.    What is the meaning of the value in the Num_Reuse column of the sp_monitorconfig report for the ‘procedure cache size’ parameter?
Ans. The number of query plans that have been removed from the cache to make space.

25. In ASE 15.0, what is the option used to control Run Time Adjustment behavior?
Ans. set process_limit_action quite|warning|abort

26.  What is the difference between contents of monSysSQLText and monProcessSQLText MDA tables?
Ans. monSysSQLText provides a historical view of the most recently executed SQL text.  monProcessSQLText table display SQL text that is currently being executed.

27.    Conceptually, how does Adaptive Server maintain statistics – as an attribute of an index or an attribute of a column?
Ans. Statistics are maintained as an attribute of a column, not an index. Even though statistics are generated on the leading column of an index when an index is created, they are generated only once for the column. Thus, only one set of statistics exists for a column no matter how many indexes the column is part of. Statistics can also be generated for minor index attributes and non-indexed columns.

28.   What is the point in adding statistics on non-indexed columns - after all, they can’t make the optimizer use an index if none exists?
Ans. Adding statistics on non-indexed columns can help the optimizer cost joins more accurately. Without statistics the optimizer makes assumptions as to the number of qualifying rows.

29.    In what two situations could specifying additional histogram steps be useful?
Ans. Specifying additional histogram steps can be useful: - if the table is large, the search value falls between steps, and the optimizer is unable to determine an accurate selectivity estimate.

30.  When does the optimizer rely on default selectivity values? Are they accurate? If not, can they be made more accurate?
Ans. In some cases where statistics are not available or usable, the optimizer may rely on default selectivity values which may or may not reflect reality. Default selectivity values can be modified to make them more accurately reflect the underlying data.

Will post few more FAQ soon .... watch this blog ....

Wednesday, 29 February 2012

Sybase Certification - Many certificates are expiring on Mar 15, 2012.


AVAILABLE SYBASE CERTIFICATION EXAMS AND VERSIONS

  1. Adaptive Server Administrator Associate Version 15.0 | Version 12.5 (expires 3/15/2012) 
  2. Adaptive Server Administrator Professional Version 12.5.2 (expires 3/15/2012) 
  3. Adaptive Server Enterprise SQL Developer Associate Version 12.5.2 (expires 3/15/2012) 
  4. Adaptive Server Enterprise SQL Developer Professional Version 15.0
  5.  Sybase IQ Administrator Professional Version 15.2 | Version 12.6 (expires 3/15/2012)
  6. Replication Server Administrator Professional Version 15.0.1 | Version 12.5 (expires 3/15/2012) 
  7. SQL Anywhere Developer Professional Version 8.0 (expires 3/15/2012) 
  8. PowerBuilder Developer Professional Version 10.0 (expires 3/15/2012)| Version 9.0 (expires 3/15/2012) 
  9. PowerDesigner Data Modeling Professional Version 12.1 (expires 3/15/2012)| Version 15.1 (expires 3/15/2012) 

Sybase Certification
Preparation
Attaining a certification for Sybase Adaptive Server Enterprise (ASE) should not be taken lightly. I'd say you need significant practical experience with ASE in the first place; let's say at least 6 months of full-time ASE experience before taking the test. In addition, you'll need to spend time on studying the documentation: you'll find that there are many features you've never used, and you need to fill these gaps in your ASE knowledge.
In any case, you should check out the information about certification-related issues on Sybase's own web pages at http://www.sybase.com/education/profcert/, as this will answer many of your questions.
For preparation, make sure you have the ASE System Admin Guide and the Reference Manual handy, as well as the Performance & Tuning Guide for the Professional-level exams. You can download these manuals as PDF documents from the Sybase web site. 
REGISTER AND TAKE EXAM - Most of the Sybase Certified Professional Program exams are computer-delivered consisting of approximately 60 multiple choice questions. Candidates are not allowed to use books, notes, or reference materials. Each exam is designed to have sufficient time to answer and review all questions. Results are evaluated based on your choice of answer(s) and will contribute to your final score. Locate and register for an exam online at Prometric or by Phone at 800-792-EXAM or 612-820-5747. Orvisit Prometric, Inc. for the latest information regarding online and offline registration methods. Review in more detail our Exam Registration Information.
·         Arrive at the center at least 15 minutes prior to your scheduled appointment.
·         Sign the exam log and present two forms of identification. One must be a government-issued photo identification. Both forms of identification must contain your signature. When you register, ask a representative for a list of valid forms of identification. You will not be allowed to take the exam without valid identification.
·         The Exam Administrator will give you a brief orientation and escort you to a computer terminal where you will take the exam. You are not allowed to bring papers, books, bags, or calculators into the room.
·         A brief tutorial will precede the exam to give you an opportunity to familiarize yourself with the vendor's exam driver software. If you wish, the Exam Administrator will provide you with an orientation on system and equipment use, which consists of an introductory lesson, designed to familiarize the candidate with the exam procedure. This lesson includes directions on entering responses and reviewing questions. The Exam Administrator is responsible for the exam center operation, but are not subject matter experts and cannot counsel you on exam content.
·         Time allowed for completion of exams is 75 minutes (except non-English versions).
·         Because only correct answers contribute to your score, there is no penalty for incorrect answers. If you wish, you may mark questions for later review. When you complete the exam, you are required to sign out on the exam log. Be sure to get a copy of your exam score report. You are then free to leave.
The exam codes can be used when booking an exam with Prometric:
  • Certified Administrator for ASE 12.5 - Associate Level
    In any case, this certification requires one exam (exam code 510-020), irrespective of any certifications you already may have.
  • Note that this exam is based on the first version of ASE 12.5, i.e. 12.5 GA. It does not contain any questions about new or changed functionality in later 12.5 releases such as 12.5.0.1.
 Please check the cited URL for more info:
The exam questions fall into one of the following categories:
  • "choose the best answer" : some questions are particularly nasty as all possible replies are valid in one way or another; still, you must choose only one (I recall a particularly ridiculous question like "The client-server architecture in Sybase SQL Server is designed to ..." and then all possible replies make sense). In cases like these, my recommendation is to try to select the reply that seems "best" from a Sybase company viewpoint; this seems to have worked for me.
  • "choose N answers" : you must select the specified number of correct replies.
 ASE 12.5 Administrator
Recommended Courses/Modules:
  • Powering Up With ASE 12.5
  •  Fast Track to Adaptive Server Enterprise: 12.5
  •  System & Database Administration: ASE 12.5
 ASE 12.5 Administrator Associate Exam Questions Topic wise:
What do I Study ?
             1. ASE Overview (4 questions - 7%)
            2. ASE 12.5 New Features (3 questions - 5%)
            3. Configuration, Upgrade & Installation (2 questions - 4%)
            4. Resource Allocation (4 questions - 7%)
            5. Database & Logs (7 questions - 13%)
            6. Backup & Recovery (6 questions - 11%)
            7. Extensible New Limits (4 questions - 7%)
            8. Cache Management (4 questions - 7%)
            9. Security (5 questions - 9%)
           10. Transaction Management (4 questions - 7%)
            11. Dynamic Reconfiguration (4 questions - 7%)
            12. Parallel Performance Optimization (3 questions - 5%)
            13. Locking and Concurrency (3 questions - 5%)
            14. Object Resource Management (3 questions - 5%)

 It’s multiple choice exam of 56 Questions out of 37 to be answered correctly in 90mins to hit the target.

Wednesday, 11 January 2012

sp__deviceinfo

sp__deviceinfo
This procedure displays the information of devices.

Input Parameters:
  • min_space – lists all the devices with the specified size of minimum free space on the device in MBs.
  • dev_name - name of the device or devices matchs the pattern.

Usage Examples:
  • sp__freedevice - displays the information of all the devices.
  • sp__freedevice 100,’User_Data’ - displays all the devices like User_Data1, User_Data2  etc., with >= 100MB free space.

create procedure sp__deviceinfo @min_space int = null, @dev_name varchar(64) = null
as
begin
declare @numpgsmb integer /* Number of 'virtual' Pages in MegaBytes */
select @numpgsmb = (1048576 / @@maxpagesize)
select "phyname"=convert(varchar(64), d.phyname),
"name"=convert(varchar(32),d.name),
"d_size"=convert(varchar(6),(1 + d.high - d.low) / @numpgsmb),
"d_used"=convert(varchar(6), sum(u.size / @numpgsmb)) ,
"d_free"=((1 + d.high - d.low) / @numpgsmb) - sum(u.size / @numpgsmb),
vdevno=d.low/power(2,24) & 255
into #device_tbl
from master..sysusages u, master..sysdevices d
where u.vstart between d.low and d.high
and d.status & 2 = 2
group by d.name

select
vdevno=low/power(2,24) & 255,
"Physical Name"=convert(varchar(40), d.phyname),
"Device Name"=convert(varchar(28),d.name),
"Size"=convert(varchar(6),(1 + d.high - d.low) / @numpgsmb),
"Used"=convert(varchar(6),0),
"Free"=convert(varchar(6),(1 + d.high - d.low) / @numpgsmb)
from master..sysdevices d
where d.name not in (select tmp.name from # device _tbl tmp)
and d.status & 2 = 2
and ( @min_space is null or ((1 + d.high - d.low) / @numpgsmb) >= @min_space )
and ( @dev_name is null or d.phyname like @dev_name or d.name like @dev_name)
union
select vdevno , phyname , name , d_size , d_used , convert(varchar(6), d_free)
from # device_ tbl
where ( @min_space is null or d_free >= @min_space )
and ( @dev_name is null or phyname like @dev_name or name like @dev_name)
order by 1
end
go

More Info of sysdevices:

sysdevices contains one row for each tape dump device, disk dump device, disk for databases, and disk partition for databases. There are four entries in sysdevices in the Adaptive Server distribution media: one for the master device (for databases), one for a disk dump device, and two for tape dump devices.

The columns for sysdevices are:

NameDatatypeDescription
low int Not used for dump devices – block offset of virtual page in 2K bytes
high int Block offset of last virtual page in 2K bytes
status smallint Bitmap indicating type of device, default, and mirror status
cntrltype smallint Controller type:
  • Database device=0
  • Disk dump device or streaming tape=2
  • Tape dump device=3 – 8
name sysname Logical name of dump device or database device
phyname varchar(127)Name of physical device
mirrornamevarchar(127) nullName of mirror device
vdevnointDevice identification number
crdatedatetime nullDate on which the device was added
resizedatedatetime nullDate on which disk resize was most recently run for this device
status2intAdditional status bits for this device



Bit representations for the status column.
DecimalHex Status
10x01Default disk
20x02Physical disk
40x04Not used – logical disk
80x08Skip header
160x10Dump device
320x20Serial writes
640x40Device mirrored
1280x80Reads mirrored
2560x100Secondary mirror side only
5120x200Mirror enabled
10240x400Master device is mirrored
20480x800Used internally – mirror disabled
40960x1000Used internally – primary device must be unmirrored
81920x2000Used internally – secondary device must be unmirrored
163840x4000UNIX file device uses dsync setting (writes occur directly to physical media)


sysusages

sysusages contains one row for each disk allocation piece assigned to a database. Each database contains a specified number of database (logical) page numbers.  The create database command checks sysdevices and sysusages to find available disk allocation pieces. One or more contiguous disk allocation pieces are assigned to the database, and the mapping is recorded in sysusages.

The columns for sysusages are:

NameDatatypeDescription
dbidsmallintDatabase ID
segmapintBitmap of possible segment assignments
lstartintFirst database (logical) page number
sizeintNumber of contiguous database (logical) pages
vstartintStarting virtual page number
padsmallint nullUnused
unreservedpgsint nullFree space not part of an allocated extent
crdatedatetime nullCreation date
vdevnointDevice identification number