Understanding Indexes Concept -II-

April 21, 2014 Leave a comment

Indexes plays and crucial role in the performance tunning of a database . It is very important to know how the index  work i.e, how indexes fetches the data’s from a tables . There is a very good post by  rleishman on the working of indexes . Let’s have a look .
What is an Index ? 

An index is a schema object that contains an entry for each value that appears in the indexed column(s) of the table or cluster and provides direct, fast access to rows. It is just as the index in this manual helps us to locate information faster than if there were no index, an Oracle Database index provides a faster access path to table data .

 

Blocks 

First we need to understand a block. A block – or page for Microsoft boffins – is the smallest unit of disk that Oracle will read or write. All data in Oracle – tables, indexes, clusters – is stored in blocks. The block size is configurable for any given database but is usually one of 4Kb, 8Kb, 16Kb, or 32Kb. Rows in a table are usually much smaller than this, so many rows will generally fit into a single block. So we never read “just one row”; we will always read the entire block and ignore the rows we don’t need. Minimising this wastage is one of the fundamentals of Oracle Performance Tuning.
Oracle uses two different index architectures: b-Tree indexes and bitmap indexes. Cluster indexes, bitmap join indexes, function-based indexes, reverse key indexes and text indexes are all just variations on the two main types. b-Tree is the “normal” index .

The “-Tree” in b-Tree 

A b-Tree index is a data structure in the form of a tree – no surprises there – but it is a tree of database blocks, not rows. Imagine the leaf blocks of the index as the pages of a phone book .  Each page in the book (leaf block in the index) contains many entries, which consist of a name (indexed column value) and an address (ROWID) that tells us the physical location of the telephone (row in the table).

The names on each page are sorted, and the pages – when sorted correctly – contain a complete sorted list of every name and address

A sorted list in a phone book is fine for humans, beacuse we have mastered “the flick” – the ability to fan through the book looking for the page that will contain our target without reading the entire page. When we flick through the phone book, we are just reading the first name on each page, which is usually in a larger font in the page header. Oracle cannot read a single name (row) and ignore the reset of the page (block); it needs to read the entire block.

 

If we had no thumbs, we may find it convenient to create a separate ordered list containing the first name on each page of the phone book along with the page number. This is how the branch-blocks of an index work; a reduced list that contains the first row of each block plus the address of that block. In a large phone book, this reduced list containing one entry per page will still cover many pages, so the process is repeated, creating the next level up in the index, and so on until we are left with a single page: the root of the tree.

 

For example : 

To find the name Gallileo in this b-Tree phone book, we:

=> Read page 1. This tells us that page 6 starts with Fermat and that page 7 starts with Hawking.

=> Read page 6. This tells us that page 350 starts with Fyshe and that page 351 starts with Garibaldi.

=> Read page 350, which is a leaf block; we find Gallileo’s address and phone number.

=> That’s it; 3 blocks to find a specific row in a million row table. In reality, index blocks often fit 100 or more rows, so b-Trees are typically quite shallow. I have never seen an index with more than 5 levels. Curious? Try this:
SQL> select index_name,  blevel+1  from  user_indexes  order  by  2 ;

user_indexes.blevel is the number of branch levels. Always add 1 to include the leaf level; this tells us the number of blocks a unique index scan must read to reach the leaf-block. If we’re really, really, insatiably curious; try this in SQL*Plus:
SQL> accept   index_name  prompt   “Index Name: “
SQL> alter session set tracefile_identifier=’&index_name’ ;
SQL> column object_id new_value object_id
SQL> select  object_id  from user_objects where object_type = ‘INDEX’  and  object_name=upper(‘&index_name’);
SQL> alter session set events ‘Immediate trace name treedump level &object_id’;
SQL> alter session set tracefile identifier=”” ;
SQL> show parameter user_dump_dest
Give the name of an index on a smallish table (because this will create a BIG file). Now, on the Oracle server, go to the directory shown by the final SHOW PARAMETER user_dump_dest command and find the trace file – the file name will contain the index name. Here is a sample:
—- begin tree dump
branch: 0x68066c8 109078216 (0: nrow: 325, level: 1)
leaf: 0x68066c9 109078217 (-1: nrow: 694 rrow: 694)
leaf: 0x68066ca 109078218 (0: nrow: 693 rrow: 693)
leaf: 0x68066cb 109078219 (1: nrow: 693 rrow: 693)
leaf: 0x68066cc 109078220 (2: nrow: 693 rrow: 693)
leaf: 0x68066cd 109078221 (3: nrow: 693 rrow: 693)


leaf: 0x68069cf 109078991 (320: nrow: 763 rrow: 763)
leaf: 0x68069d0 109078992 (321: nrow: 761 rrow: 761)
leaf: 0x68069d1 109078993 (322: nrow: 798 rrow: 798)
leaf: 0x68069d2 109078994 (323: nrow: 807 rrow: 807)
—– end tree dump
This index has only a root branch with 323 leaf nodes. Each leaf node contains a variable number of index entries up to 807! A deeper index would be more interesting, but it would take a while to dump.

“B”  is  for…

Contrary to popular belief, b is not for binary; it’s balanced.

As we insert new rows into the table, new rows are inserted into index leaf blocks. When a leaf block is full, another insert will cause the block to be split into two blocks, which means an entry for the new block must be added to the parent branch-block. If the branch-block is also full, it too is split. The process propagates back up the tree until the parent of split has space for one more entry, or the root is reached. A new root is created if the root node splits. Staggeringly, this process ensures that every branch will be the same length.
How are Indexes used ?
Indexes have three main uses:

  • To quickly find specific rows by avoiding a Full Table Scan

 

We’ve already seen above how a Unique Scan works. Using the phone book metaphor, it’s not hard to understand how a Range Scan works in much the same way to find all people named “Gallileo”, or all of the names alphabetically between “Smith” and “Smythe”. Range Scans can occur when we use >, <, LIKE, or BETWEEN in a WHERE clause. A range scan will find the first row in the range using the same technique as the Unique Scan, but will then keep reading the index up to the end of the range. It is OK if the range covers many blocks.

  • To avoid a table access altogether

 

If all we wanted to do when looking up Gallileo in the phone book was to find his address or phone number, the job would be done. However if we wanted to know his date of birth, we’d have to phone and ask. This takes time. If it was something that we needed all the time, like an email address, we could save time by adding it to the phone book.

Oracle does the same thing. If the information is in the index, then it doesn’t bother to read the table. It is a reasonably common technique to add columns to an index, not because they will be used as part of the index scan, but because they save a table access. In fact, Oracle may even perform a Fast Full Scan of an index that it cannot use in a Range or Unique scan just to avoid a table access.

  • To avoid a sort

 

This one is not so well known, largely because it is so poorly documented (and in many cases, unpredicatably implemented by the Optimizer as well). Oracle performs a sort for many reasons: ORDER BY, GROUP BY, DISTINCT, Set operations (eg. UNION), Sort-Merge Joins, uncorrelated IN-subqueries, Analytic Functions). If a sort operation requires rows in the same order as the index, then Oracle may read the table rows via the index. A sort operation is not necessary since the rows are returned in sorted order.

 

Despite all of the instances listed above where a sort is performed, I have only seen three cases where a sort is actually avoided.
1. GROUP BY : 


SQL> select src_sys, sum(actl_expns_amt), count(*)  from ef_actl_expns
where src_sys = ‘CDW’   and actl_expns_amt > 0
group by src_sys ;
—————————————————————————————–
| Id   |      Operation                                               |     Name             |
—————————————————————————————-
|   0  | SELECT STATEMENT                                     |                           |
|   1  |  SORT GROUP BY NOSORT  <——-           |                           |
|*  2 |   TABLE ACCESS BY GLOBAL INDEX ROWID | EF_ACTL_EXPNS |
|*  3 |    INDEX RANGE SCAN                                 | EF_AEXP_PK       |
—————————————————————————————

Predicate Information (identified by operation id):
—————————————————————-
2 – filter(“ACTL_EXPNS_AMT”>0)
3 – access(“SRC_SYS”=’CDW’)
Note the NOSORT qualifier in Step 1.

2. ORDER BY : 


SQL> select *  from ef_actl_expns
where src_sys = ‘CDW’ and actl_expns_amt > 0
order by src_sys
—————————————————————————————-
| Id   | Operation                                                     |     Name            |
—————————————————————————————-
|   0  | SELECT STATEMENT                                     |                           |
|*  1 |  TABLE ACCESS BY GLOBAL INDEX ROWID   | EF_ACTL_EXPNS|
|*  2 |   INDEX RANGE SCAN                                   | EF_AEXP_PK      |
—————————————————————————————-

Predicate Information (identified by operation id):
—————————————————
1 – filter(“ACTL_EXPNS_AMT”>0)
2 – access(“SRC_SYS”=’CDW’)

Note that there is no SORT operation, despite the ORDER BY clause. Compare this to the following:
SQL>  select * from ef_actl_expns
where src_sys = ‘CDW’  and actl_expns_amt > 0
order by actl_expns_amt ;
———————————————————————————————
| Id  | Operation                                                      |         Name          |
———————————————————————————————
|   0 | SELECT STATEMENT                                       |                            |
|   1 |  SORT ORDER BY                                            |                            |
|*  2 |   TABLE ACCESS BY GLOBAL INDEX ROWID   | EF_ACTL_EXPNS |
|*  3 |    INDEX RANGE SCAN                                   | EF_AEXP_PK       |
—————————————————————————————-

Predicate Information (identified by operation id):
—————————————————
2 – filter(“ACTL_EXPNS_AMT”>0)
3 – access(“SRC_SYS”=’CDW’)

3. DISTINCT : 


SQL> select distinct src_sys  from ef_actl_expns
where src_sys = ‘CDW’  and actl_expns_amt > 0 ;
———————————————————————————————–
| Id  |          Operation                                             |         Name          |
———————————————————————————————–
|   0 | SELECT STATEMENT                                       |                            |
|   1 |  SORT UNIQUE NOSORT                                 |                            |
|*  2 |   TABLE ACCESS BY GLOBAL INDEX ROWID   | EF_ACTL_EXPNS |
|*  3 |    INDEX RANGE SCAN                                   | EF_AEXP_PK       |
————————————————————————————–

Predicate Information (identified by operation id):
—————————————————
2 – filter(“ACTL_EXPNS_AMT”>0)
3 – access(“SRC_SYS”=’CDW’)

Again, note the NOSORT qualifier.

This is an extraordinary tuning technique in OLTP systems like SQL*Forms that return one page of detail at a time to the screen. A SQL with a DISTINCT, GROUP BY, or ORDER BY that uses an index to sort can return just the first page of matching rows without having to fetch the entire result set for a sort. This can be the difference between sub-second response time and several minutes or hours.
Full table Scans are not bad : 

Up to now, we’ve seen how indexes can be good. It’s not always the case; sometimes indexes are no help at all, or worse: they make a query slower.

 

A b-Tree index will be no help at all in a reduced scan unless the WHERE clause compares indexed columns using >, <, LIKE, IN, or BETWEEN operators. A b-Tree index cannot be used to scan for any NOT style operators: eg. !=, NOT IN, NOT LIKE. There are lots of conditions, caveats, and complexities regarding joins, sub-queries, OR predicates, functions (inc. arithmetic and concatenation), and casting that are outside the scope of this article. Consult a good SQL tuning manual.

 

Much more interesting – and important – are the cases where an index makes a SQL slower. These are particularly common in batch systems that process large quantities of data.

 

To explain the problem, we need a new metaphor. Imagine a large deciduous tree in our front yard. It’s Autumn, and it’s our job to pick up all of the leaves on the lawn. Clearly, the fastest way to do this (without a rake, or a leaf-vac…) would be get down on hands and knees with a bag and work our way back and forth over the lawn, stuffing leaves in the bag as we go. This is a Full Table Scan, selecting rows in no particular order, except that they are nearest to hand. This metaphor works on a couple of levels: we would grab leaves in handfuls, not one by one. A Full Table Scan does the same thing: when a bock is read from disk, Oracle caches the next few blocks with the expectation that it will be asked for them very soon. Type this in SQL*Plus:

 

SQL> show parameter  db_file_multiblock_read_count

 

Just to shake things up a bit (and to feed an undiagnosed obsessive compulsive disorder), we decide to pick up the leaves in order of size. In support of this endeavour, we take a digital photograph of the lawn, write an image analysis program to identify and measure every leaf, then load the results into a Virtual Reality headset that will highlight the smallest leaf left on the lawn. Ingenious, yes; but this is clearly going to take a lot longer than a full table scan because we cover much more distance walking from leaf to leaf.

 

So obviously Full Table Scan is the faster way to pick up every leaf. But just as obvious is that the index (virtual reality headset) is the faster way to pick up just the smallest leaf, or even the 100 smallest leaves. As the number rises, we approach a break-even point; a number beyond which it is faster to just full table scan. This number varies depending on the table, the index, the database settings, the hardware, and the load on the server; generally it is somewhere between 1% and 10% of the table.
The main reasons for this are :

  • As implied above, reading a table in indexed order means more movement for the disk head.
  • Oracle cannot read single rows. To read a row via an index, the entire block must be read with all but one row discarded. So an index scan of 100 rows would read 100 blocks, but a FTS might read 100 rows in a single block.
  • The db_file_multiblock_read_count setting described earlier means FTS requires fewer visits to the physical disk.
  • Even if none of these things was true, accessing the entire index and the entire table is still more IO than just accessing the table.

 

So what’s the lesson here? Know our data! If our query needs 50% of the rows in the table to resolve our query, an index scan just won’t help. Not only should we not bother creating or investigating the existence of an index, we should check to make sure Oracle is not already using an index. There are a number of ways to influence index usage; once again, consult a tuning manual. The exception to this rule – there’s always one – is when all of the columns referenced in the SQL are contained in the index. If Oracle does not have to access the table then there is no break-even point; it is generally quicker to scan the index even for 100% of the rows.

 

Summary : 

Indexes are not a dark-art; they work in an entirely predictable and even intuitive way. Understanding how they work moves Performance Tuning from the realm of guesswork to that of science; so embrace the technology and read the manual.

 

Reference:    http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_5010.htm

http://www.orafaq.com/node/1403

 

Categories: Database, Oracle Tags: ,

Interpreting Raw Sql Trace File

April 21, 2014 Leave a comment

QL_TRACE is the main method for collecting SQL Execution information in Oracle. It records a wide range of information and statistics that can be used to tune SQL operations. The sql trace file contains a great deal of information . Each cursor that is opened after tracing has been enabled will be recorded in the trace file. 

The raw trace file mostly contains the cursor number . Eg, PARSING IN CURSOR #3 . EXECutes, FETCHes and WAITs are recorded against a cursor. The information applies to the most recently parsed statement within that cursor . Firstly,  let’s have a look on “Wait Events”  .

WAIT #6: nam=’db file sequential read’ ela= 8458 file#=110 block#=63682 blocks=1 obj#=221 tim=506028963546

WAIT = An event that we waited for.
nam    = What was being waited for .The wait events here are the same as are seen in view V$SESSION_WAIT .
ela  = Elapsed time for the operation.(microseconds)
p1 = P1 for the given wait event.
p2 = P2 for the given wait event.
p3 = P3 for the given wait event.

 

Example No. 1 : WAIT #6: nam=’db file sequential read’ ela= 8458 file#=110 block#=63682 blocks=1 obj#=221 tim=506028963546

The above line can be translated as  : Completed waiting under CURSOR no 6  for “db file sequential read” . We waited 8458 microseconds i.e. approx. 8.5 milliseconds .For a read of:  File 110, start block 63682, for 1 Oracle block of Object number 221. Timestamp was 506028963546 . 

 

Example no.2 : WAIT #1: nam=’library cache: mutex X’ ela= 814 idn=3606132107 value=3302829850624 where=4 obj#=-1 tim=995364327604

The above line can be translated as : Completed WAITing under CURSOR no 1 for “library cache: mutex X” .We waited 814 microseconds i.e. approx. 0.8 milliseconds .To get an eXclusive library cache latch with  Identifier 3606132107 value 3302829850624 location 4 . It was not associated with any particular object (obj#=-1) Timestamp 995364327604.

 

The trace file also show the processing of the sql statements . Oracle processes SQL statements as follow :
Stage 1: Create a Cursor
Stage 2: Parse the Statement
Stage 3: Describe Results
Stage 4: Defining Output
Stage 5: Bind Any Variables
Stage 6: Execute the Statement
Stage 7: Parallelize the Statement
Stage 8: Fetch Rows of a Query Result
Stage 9: Close the Cursor
Now let’s  move to another important term PARSING IN CURSOR #n . EXECutes, FETCHes and WAITs are recorded against a cursor. The information applies to the most recently parsed statement within that cursor.

PARSING IN CURSOR# : 

Cursor :  In order for Oracle to process an SQL statement, it needs to create an area of memory known as the context area; this will have the information needed to process the statement. This information includes the number of rows processed by the statement, a pointer to the parsed representa-tion of the statement (parsing an SQL statement is the process whereby information is transferred to the server, at which point the SQL statement is evaluated as being valid).

 

A cursor is a handle, or pointer, to the context area. Through the cursor, a PL/SQL program can control the context area and what happens to it as the statement is processed. Two important features about the cursor are

1.)  Cursors allow you to fetch and process rows returned by a SE-LECT statement, one row at a time.

2.)  A cursor is named so that it can be referenced.

 

Parsing : Oracle Parsing is the first step in processing of any database statement . PARSE record is accompanied by the cursor number. Let’s have a look on “Parsing in Cursor” of a particular trace file .

 

 PARSING IN CURSOR #2 len=92 dep=0 uid=0 oct=3 lid=0 tim=277930332201 hv=1039576264 ad=’15d51e60′ sqlid=’dsz47ssyzdb68′

select p.PID,p.SPID,s.SID from v$process p,v$session s where s.paddr = p.addr and s.sid = 12

END OF STMT

PARSE#2:c=31250,e=19173,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,plh=836746634,tim=27930332198

EXEC #2:c=0,e=86,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=836746634,tim=77930335666

WAIT #2: nam=’SQL*Net message to client’ ela= 10 driver id=1413697536 #bytes=1 p3=0 obj#=116 tim=77930335778

FETCH #2:c=0,e=805,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=1,plh=836746634,tim=77930336684

WAIT #2: nam=’SQL*Net message from client’ ela= 363 driver id=1413697536 #bytes=1 p3=0 obj#=116 tim=77930337227

FETCH #2:c=0,e=31,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=836746634,tim=77930337421

STAT #2 id=1 cnt=1 pid=0 pos=1 obj=0 op=’NESTED LOOPS  (cr=0 pr=0 pw=0 time=0 us cost=0 size=152 card=1)’

STAT #2 id=2 cnt=27 pid=1 pos=1 obj=0 op=’MERGE JOIN CARTESIAN (cr=0 pr=0 pw=0 time=156 us cost=0 size=96 card=1)’

STAT #2 id=3 cnt=1 pid=2 pos=1 obj=0 op=’NESTED LOOPS  (cr=0 pr=0 pw=0 time=0 us cost=0 size=39 card=1)’

STAT #2 id=4 cnt=1 pid=3 pos=1 obj=0 op=’FIXED TABLE FIXED INDEX X$KSLWT (ind:1) (cr=0 pr=0 pw=0 time=0 us cost=0 size=26 card=1)’

STAT #2 id=5 cnt=1 pid=3 pos=2 obj=0 op=’FIXED TABLE FIXED INDEX X$KSLED (ind:2) (cr=0 pr=0 pw=0 time=0 us cost=0 size=13 card=1)’

STAT #2 id=6 cnt=27 pid=2 pos=2 obj=0 op=’BUFFER SORT (cr=0 pr=0 pw=0 time=78 us cost=0 size=57 card=1)’

STAT #2 id=7 cnt=27 pid=6 pos=1 obj=0 op=’FIXED TABLE FULL X$KSUPR (cr=0 pr=0 pw=0 time=130 us cost=0 size=57 card=1)’

STAT #2 id=8 cnt=1 pid=1 pos=2 obj=0 op=’FIXED TABLE FIXED INDEX X$KSUSE (ind:1) (cr=0 pr=0 pw=0 time=0 us cost=0 size=56 card=1)’

WAIT #2: nam=’SQL*Net message to client’ ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=116 tim=77930338248

*** 2012-05-19 15:07:22.843

WAIT #2: nam=’SQL*Net message from client’ ela= 38291082 driver id=1413697536 #bytes=1 p3=0 obj#=116 tim=77968629417

CLOSE #2:c=0,e=30,dep=0,type=0,tim=77968629737

len     = the number of characters in the SQL statement
dep   = tells the application/trigger depth at which the SQL statement was executed. dep=0 indicates that it was executed by the client application. dep=1 indicates that the SQL statement was executed by a trigger, the Oracle optimizer, or a space management call. dep=2 indicates that the SQL statement was called from a trigger, dep=3 indicates that the SQL statement was called from a trigger that was called from a trigger.
uid     = Schema id under which SQL was parsed.
oct = Oracle command type.
lid = Privilege user id
tim    = Timestamp.
hv = Hash id.
ad = SQLTEXT address

PARSE #3:  c=15625,  e=177782,  p=2,  cr=3,  cu=0,  mis=1,  r=0,  dep=0,  og=1,  plh=272002086, tim=276565143470

c      = CPU time (microseconds rounded to centiseconds granularity on 9i & above)
e  = Elapsed time (centiseconds prior to 9i, microseconds thereafter)
p  = Number of physical reads.
cr  = Number of buffers retrieved for CR reads.(Consistent reads)
cu    =Number of buffers retrieved in current mode.
mis  = Cursor missed in the cache.
r  = Number of rows processed.
dep = Recursive call depth (0 = user SQL, >0 = recursive).
og = Optimizer goal: 1=All_Rows, 2=First_Rows, 3=Rule, 4=Choose

From the above Parse line it is very clear that the total time taken in parsing the statement is  0.177 sec and the no. of physical reads done are 2 .

Bind Variables : If the SQL statement does reference bind variables, then the following  SQL statement shown in the cursor can locate a section of text associated with each bind variable. For each bind variable there are a number of attributes listed.  The following are the ones we are interested in here:

mxl      =  the maximum length – ie. the maximum number of bytes occupied by the variable. Eg. dty=2 and mxl=22 denotes a NUMBER(22) column.
scl       = the scale (for NUMBER columns)
pre      = the precision (for NUMBER columns)
value  = the value of the bind variable
dty      = the datatype.  Typical values are:
1       VARCHAR2 or NVARCHAR2
2       NUMBER
8       LONG
11     ROWID
12     DATE
23     RAW
24     LONG RAW
96     CHAR
112   CLOB or NCLOB
113   BLOB
114   BFILE

EXEC :  Execute a pre-parsed statement. At this point, Oracle has all necessary information and resources, so the statement is executed. For example

EXEC #2:c=0,e=225,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,plh=3684871272,tim=282618239403

Fetch : Fetch rows from a cursor . For example
FETCH #4:c=0,e=8864,p=1,cr=26,cu=0,mis=0,r=1,dep=0,og=1,plh=3564694750,tim=282618267037

STAT :  Lines report explain plan statistics for the numbered [CURSOR]. These let us know the ‘run time’ explain plan. For example
STAT #1 id=1 cnt=7 pid=0 pos=1 obj=0 op=’SORT ORDER BY (cr=0 pr=0 pw=0 time=0 us cost=2 size=2128 card=1)’

id       = Line of the explain plan which the row count applies to (starts at line 1).  This is effectively the row source row count for all row sources in the execution tree
cnt =  Number of rows for this row source.
pid =  Parent id of this row source.
pos  =  Position in explain plan.
obj     =  Object id of row source (if this is a base object).
op=’…’   The row source access operation

XCTEND  A transaction end marker. For example  XCTEND rlbk=0, rd_only=1, tim=282636050491
rlbk           =1   if a rollback was performed, 0 if no rollback (commit).
rd_only      =1   if transaction was read only, 0 if changes occurred.

CLOSE  cursor is closed .for example CLOSE #4:c=0,e=32,dep=0,type=0,tim=282636050688
c            = CPU time (microseconds rounded to centiseconds granularity on 9i and above)
e           = Elapsed time (centiseconds prior to 9i, microseconds thereafter)
dep       = Recursive depth of the cursor
type     = Type of close operation

Note : Timestamp are used to determine the time between any 2 operations.
Reference : Metalink [ID 39817.1]

Categories: Database, Oracle Tags: ,

Generating Data to UI mappings in Siebel

April 20, 2014 Leave a comment

This is one of those tasks which is fairly simple to do. However, can be very time consuming considering you have to generate a mapping for an entire/multiple repositories. We’ve all have had to do this at some point, not enjoying it one bit!

Well, here is a code that will save you some time and your sanity :).

The below code generates a screen to Applet, and an Applet to BC mapping which can be then exported to excel.

Screen to Applet - 

select scr.name “Screen Name”
,nvl(nvl(ptabi.tab_text, scri.viewbar_text), scr.viewbar_text) “Screen”
,scrv.sequence “View Seq”
,vw.name “View Name”
,vwi.title “View”
,vw.busobj_name “Business Object”
,vwti.item_num “Item Num”
,ap.name “Applet Name”
,api.title “Applet”
,ap.buscomp_name “Business Component”
from   siebel.s_repository rep
inner join siebel.s_screen scr on scr.repository_id = rep.row_id
left outer join siebel.s_screen_intl scri on scri.screen_id = scr.row_id and scri.repository_id = rep.row_id and scri.name = ‘ENU-STD’
inner join siebel.s_screen_view scrv on scrv.screen_id = scr.row_id and scrv.repository_id = rep.row_id
inner join siebel.s_application appl on rep.row_id = appl.repository_id
left outer join siebel.s_page_tab ptab on ptab.application_id = appl.row_id and ptab.repository_id = rep.row_id and ptab.screen_name = scr.name
left outer join siebel.s_page_tab_intl ptabi on ptabi.page_tab_id = ptab.row_id and ptabi.repository_id = rep.row_id and ptabi.name = ‘ENU-STD’
inner join siebel.s_view vw on vw.name = scrv.view_name and vw.repository_id = rep.row_id
left outer join siebel.s_view_intl vwi on vwi.view_id = vw.row_id and vwi.repository_id = rep.row_id and vwi.name = ‘ENU-STD’
inner join siebel.s_view_web_tmpl vwt on vwt.view_id = vw.row_id and vwt.repository_id = rep.row_id
left outer join siebel.s_view_wtmpl_it vwti on vwti.view_web_tmpl_id = vwt.row_id and vwti.repository_id = rep.row_id
inner join siebel.s_applet ap on ap.name = vwti.applet_name and ap.repository_id = rep.row_id
left outer join siebel.s_applet_intl api on api.applet_id = ap.row_id and api.repository_id = rep.row_id and api.name = ‘ENU-STD’
where  rep.name = ‘Siebel Repository’
and    appl.name = ‘Siebel Power Communications’
and    nvl(rep.inactive_flg,’N’) = ‘N’
and    nvl(scr.inactive_flg,’N’) = ‘N’
and    nvl(scri.inactive_flg,’N’) = ‘N’
and    nvl(scrv.inactive_flg,’N’) = ‘N’
and    nvl(vw.inactive_flg,’N’) = ‘N’
and    nvl(vwi.inactive_flg,’N’) = ‘N’
and    nvl(vwt.inactive_flg,’N’) = ‘N’
and    nvl(vwti.inactive_flg,’N’) = ‘N’
and    nvl(ap.inactive_flg,’N’) = ‘N’
and    nvl(api.inactive_flg,’N’) = ‘N’
union
select scr.name “Screen Name”
,nvl(nvl(ptabi.tab_text, scri.viewbar_text), scr.viewbar_text) “Screen”
,scrv.sequence “View Seq”
,vw.name “View Name”
,vwi.title “View”
,vw.busobj_name “Business Object”
,vwti.item_num “Item Num”
,apta.name “Applet Name”
,api.title “Applet”
,apta.buscomp_name “Business Component”
from   siebel.s_repository rep
inner join siebel.s_screen scr on scr.repository_id = rep.row_id
left outer join siebel.s_screen_intl scri on scri.screen_id = scr.row_id and scri.repository_id = rep.row_id and scri.name = ‘ENU-STD’
inner join siebel.s_screen_view scrv on scrv.screen_id = scr.row_id and scrv.repository_id = rep.row_id
inner join siebel.s_application appl on rep.row_id = appl.repository_id
left outer join siebel.s_page_tab ptab on ptab.application_id = appl.row_id and ptab.repository_id = rep.row_id and ptab.screen_name = scr.name
left outer join siebel.s_page_tab_intl ptabi on ptabi.page_tab_id = ptab.row_id and ptabi.repository_id = rep.row_id and ptabi.name = ‘ENU-STD’
inner join siebel.s_view vw on vw.name = scrv.view_name and vw.repository_id = rep.row_id
left outer join siebel.s_view_intl vwi on vwi.view_id = vw.row_id and vwi.repository_id = rep.row_id and vwi.name = ‘ENU-STD’
inner join siebel.s_view_web_tmpl vwt on vwt.view_id = vw.row_id and vwt.repository_id = rep.row_id
left outer join siebel.s_view_wtmpl_it vwti on vwti.view_web_tmpl_id = vwt.row_id and vwti.repository_id = rep.row_id
inner join siebel.s_applet ap on ap.name = vwti.applet_name and ap.repository_id = rep.row_id
inner join siebel.s_applet_toggle apt on apt.applet_id = ap.row_id and apt.repository_id = rep.row_id
inner join siebel.s_applet apta on apta.name = apt.applet_name and apta.repository_id = rep.row_id
left outer join siebel.s_applet_intl api on api.applet_id = apta.row_id and apta.repository_id = rep.row_id and api.name = ‘ENU-STD’
where  rep.name = ‘Siebel Repository’
and    appl.name = ‘Siebel Power Communications’
and    nvl(rep.inactive_flg,’N’) = ‘N’
and    nvl(scr.inactive_flg,’N’) = ‘N’
and    nvl(scri.inactive_flg,’N’) = ‘N’
and    nvl(scrv.inactive_flg,’N’) = ‘N’
and    nvl(vw.inactive_flg,’N’) = ‘N’
and    nvl(vwi.inactive_flg,’N’) = ‘N’
and    nvl(vwt.inactive_flg,’N’) = ‘N’
and    nvl(vwti.inactive_flg,’N’) = ‘N’
and    nvl(ap.inactive_flg,’N’) = ‘N’
and    nvl(api.inactive_flg,’N’) = ‘N’
order by “Screen”
,”View Seq”
,”View Name”
,”Item Num”
,”Applet Name”

Output looks like -

Applet to BC mapping -

select  “Applet Name”
,”BC Name”
,”BC Field”
,”Required”
,”Calculated”
,”Calculated Value”
,”Join Name”
,”Table”
,”Column”
,”Data Type”
,”Length”
,”Multi-valued”
,”MV Link”
,”Pick List”
,”LOV Name”
,min(“Caption”) “Caption”
,”Display Order”
from (
select ap.name “Applet Name”
,bc.name “BC Name”
,fld.name “BC Field”
,fld.required “Required”
,fld.calculated “Calculated”
,fld.calcval “Calculated Value”
,fld.join_name “Join Name”
,(case when fld.mvlink_name is null then nvl(nvl(jotab.name, fld.join_name), case when fld.calculated = ‘Y’ then null else bc.table_name end) else null end) “Table”
,fld.col_name “Column”
,fld.type “Data Type”
,(case when fld.prec_num is null then to_char(fld.textlen)
else to_char(fld.prec_num) || to_char(case when fld.scale is null or fld.scale = 0 then ” else ‘,’ || fld.scale end)
end) “Length”
,fld.multi_valued “Multi-valued”
,fld.mvlink_name “MV Link”
,pl.name “Pick List”
,pl.type_value “LOV Name”
,coi.caption “Caption”
,co.sequence “Display Order”
from   siebel.s_control co
inner join siebel.s_control_intl coi on coi.control_id = co.row_id and coi.name = ‘ENU-STD’
inner join siebel.s_applet ap on co.applet_id = ap.row_id
inner join siebel.s_buscomp bc on ap.buscomp_name = bc.name
inner join siebel.s_field fld on fld.name = co.field_name and fld.buscomp_id = bc.row_id
inner join siebel.s_repository rep on bc.repository_id = rep.row_id
left outer join siebel.s_join jo on jo.buscomp_id = fld.buscomp_id and fld.join_name = jo.name
left outer join siebel.s_table jotab on jotab.name = jo.dest_tbl_name and jotab.repository_id = rep.row_id
left outer join siebel.s_picklist pl on fld.picklist_name = pl.name and pl.repository_id = rep.row_id
where  rep.name = ‘Siebel Repository’
and    ap.repository_id = rep.row_id
and    co.repository_id = rep.row_id
and    bc.repository_id = rep.row_id
and    fld.repository_id = rep.row_id
and    nvl(co.inactive_flg,’N’) = ‘N’
and    nvl(ap.inactive_flg,’N’) = ‘N’
and    nvl(bc.inactive_flg,’N’) = ‘N’
and    nvl(fld.inactive_flg,’N’) = ‘N’
and    nvl(rep.inactive_flg,’N’) = ‘N’
and    nvl(jo.inactive_flg,’N’) = ‘N’
union all
select ap.name “Applet Name”
,bc.name “BC Name”
,fld.name “BC Field”
,fld.required “Required”
,fld.calculated “Calculated”
,fld.calcval “Calculated Value”
,fld.join_name “Join Name”
,(case when fld.mvlink_name is null then nvl(nvl(jotab.name, fld.join_name), case when fld.calculated = ‘Y’ then null else bc.table_name end) else null end) “Table”
,fld.col_name “Column”
,fld.type “Data Type”
,(case when fld.prec_num is null then to_char(fld.textlen)
else to_char(fld.prec_num) || to_char(case when fld.scale is null or fld.scale = 0 then ” else ‘,’ || fld.scale end)
end) “Length”
,fld.multi_valued “Multi-valued”
,fld.mvlink_name “MV Link”
,pl.name “Pick List”
,pl.type_value “LOV Name”
,coi.display_name “Caption”
,co.sequence “Display Order”
from   siebel.s_list li
inner join siebel.s_applet ap on li.applet_id = ap.row_id
inner join siebel.s_list_column co on co.list_id = li.row_id
left outer join siebel.s_list_col_intl coi on coi.list_column_id = co.row_id and coi.name = ‘ENU-STD’
inner join siebel.s_buscomp bc on ap.buscomp_name = bc.name
inner join siebel.s_field fld on fld.name = co.field_name and fld.buscomp_id = bc.row_id
inner join siebel.s_repository rep on bc.repository_id = rep.row_id
left outer join siebel.s_join jo on jo.buscomp_id = fld.buscomp_id and fld.join_name = jo.name
left outer join siebel.s_table jotab on jotab.name = jo.dest_tbl_name and jotab.repository_id = rep.row_id
left outer join siebel.s_picklist pl on fld.picklist_name = pl.name and pl.repository_id = rep.row_id
where  rep.name = ‘Siebel Repository’
and    li.repository_id = rep.row_id
and    ap.repository_id = rep.row_id
and    co.repository_id = rep.row_id
and    bc.repository_id = rep.row_id
and    fld.repository_id = rep.row_id
and    nvl(li.inactive_flg,’N’) = ‘N’
and    nvl(co.inactive_flg,’N’) = ‘N’
and    nvl(ap.inactive_flg,’N’) = ‘N’
and    nvl(bc.inactive_flg,’N’) = ‘N’
and    nvl(fld.inactive_flg,’N’) = ‘N’
and    nvl(rep.inactive_flg,’N’) = ‘N’
and    nvl(jo.inactive_flg,’N’) = ‘N’
)
group by  “Applet Name”
,”BC Name”
,”BC Field”
,”Required”
,”Calculated”
,”Calculated Value”
,”Join Name”
,”Table”
,”Column”
,”Data Type”
,”Length”
,”Multi-valued”
,”MV Link”
,”Pick List”
,”LOV Name”
,”Display Order”
order by “Applet Name”
,”BC Name”
,”MV Link” desc
,”Table”
,”Display Order”
Output looks like -

So there you go…you could later consolidate both to have a full UI to Data level mapping.

Categories: Siebel Tags: ,

What Administrators Should Do for Siebel Reporting with BI Publisher?

April 18, 2014 Leave a comment

There are a couple of things you want to perform as Administrators to manage the Siebel Reporting environment and maintain the BI Publisher reports in Siebel. Here is a list of the tasks that the Administrators should be responsible for.

  • Purging Siebel Reports
  • Optimize Siebel Reporting Environment
  • Enabling Logging for Debugging

Purging Siebel Reports

When the users run the Siebel reports all the generated reports output files will be stored on the Siebel database. These files can be opened from the ‘My BI Publisher Reports’ menu. However, at a certain point of time you might want to delete some of the files due to the size of keeping all the reports on the file system and also due to a compliance matter.

You as Siebel Administrator can purge such report files from the Siebel database using filters or by running a workflow process. I’m going to talk about how to set up reports to be automatically or manually purged.

Automatic Purge

You can set up to automatically purge your reports from the Siebel database after a specified time interval. The ‘BIP Delete After Days’ system preference allows you to specify any non-zero positive value that executes the Auto Purge workflow to purge the reports. Based on the value that you enter, the reports are purged from the database after the number of days specified.

To automatically purge reports

  1. Log in to the Siebel application with system administrator privileges.
  2. Navigate to the Administration – Application screen, then System Preferences view.
  3. In the System Preferences list, select ‘BIP Delete After Days’, and change the value to any positive nonzero value.
    By default, the value is set to -1 (minus 1), which means it never purge.

    BIP_Delete_After_Days

  4. Navigate to the Administration – Server Management screen, then Jobs view.
  5. Add a new job
  6. Click the search icon to select ‘Workflow Process Manager’
  7. Click ‘New’ button to add a Job Parameter to the job
  8. Select Workflow Process Name for the name
  9. Type ‘XMLP Purge Records’ as the value
  10. Click Submit.

Alternatively you can schedule this job to run periodically using the Siebel workflow, see Siebel Business Process Framework: Workflow Guide for the detail.

Manual Purge

When manually purging Siebel reports, you can specify criteria by which the reports are purged. Reports meeting that criteria will be removed from the Siebel database. You can also purge multiple reports together by selecting a date range, the reports that were generated within the specified date range will be purged. If both the report name and the date range are entered, then only those reports with that name and that were generated within that specified date range are purged. You can also purge reports for a specific user by entering his/her user ID as the criteria.

To manually purge a report:

  1. Log in to the Siebel application with system administrator privileges.
  2. Navigate to the Administration – BIP Reports screen, then Purge Administration view.

    Purge_Admin

  3. In the Purge Administration form, you can select a report name, type From Date, To Date, and select User ID. You don’t need to fill all of them. Whatever you enter will be used as a criteria to select the reports to be purged.
  4. Click Run.
    The reports that meet the specified criteria are purged.

Optimizing Performance for Siebel Reports

Now the next topic is to optimize the Siebel Reports runtime environment to have better performance and scalability. There are several attributes that you can use to best fit to your reporting and system requirements from performance and scalability perspective.

Here is a list of the attributes.

  • Report Execution Wait Time
  • Server Request Processor Wait Time
  • Setting Concurrency Parameters
  • Max Fetch Size (DSMaxFetchArraySize) for Large Data Volumes
  • Enabling Scalable Mode
Execution Wait Time

By setting this threshold value you can cancel some of the reports, which would take longer than the specified time duration, to run. In some cases some reports might take a long time and when you have multiple reports taking long time at the same time other users might have to wait for those reports to finish the jobs. Typically such long running reports should be executed at when most of the users are not accessing such as at night time as a batch process, but there is no control to prevent the users to run such reports as long as they have access to them. So you can use this attribute to control such.

Here is a list of the steps to set the Report Execution Wait Time for Siebel Reports

  1. Navigate to the Administration – Application screen, then System Preferences view.
  2. In the System Preferences list, select BIP Report Wait Time, and then change the value to any number greater than 100. By default, the threshold is set to 100 seconds.
Setting the Server Request Processor Wait Time for Siebel Reports

Some times your database doesn’t respond due to heavy duty work currently being performed at the database or simply not available. Or there is a quick temporary issue on the network. Whatever the reason your report request trying to access to the database might not getting any response back. Typically the applications try to reconnect to the database after a certain waiting time. You can control this waiting time with this setting.

Follow the steps below to set the Server Request Processor Wait Time for Siebel Reports

  1. Navigate to the Administration – Server Configuration screen,  Servers, and then Components view.
  2. In the Components list, select Server Request Processor (alias SRProc).
  3. Scroll down and click the Parameters subview, and then click Hidden.
  4. In the Parameter list, select Database Polling Interval, and change value from 10 to 1. The Value on Restart and Default Values are updated as well.
  5. Restart the Siebel Server.
Setting Concurrency Parameters for Siebel Reports

You can set a maximum number of tasks per XMLP Report Server, which is not the BI Publisher Enterprise but it’s the engine that takes care of the report request and response within the Siebel, per a single Siebel server. Also you can set a maximum number of MT (Multi Threaded) Servers per a single Siebel server.

Typical guideline would be:

  • MaxTasks = peak (concurrent users)
  • MaxMTServers = MaxTasks / 100

So, for example, let’s say you have 1000 users accessing to the reporting at the same time then the MaxTasks would be 1000 and the MaxMTServers would be 10. Note that this is a generic guide line and these numbers should not be used as a static number for your environment. Each environment and reporting needs would impact on the above numbers and requires a series of performance testing to come up with the best numbers.

You can follow the steps below to set concurrency parameters for using the GUI

  1. Log in to the Siebel application with administrator privileges.
  2. Navigate to the Administration – Server Configuration screen, Servers, and then Components view.
  3. In the Components list, select XMLP Report Server.
  4. Click on the Parameters view tab and set accordingly.
Optimizing Performance of Siebel Reports for Large Data Volumes

When you have a large data coming back for your reports then you can set a Data Source maximum fetch array size (DSMaxFetchArraySize) profile parameter value to ‘-1’ so that the size is unlimited. But again, this value should be fitting to your specific environment so you might want to increase the value to a certain threshold instead of setting it as unlimited.

You can follow the steps below to optimize performance of Siebel Reports for large data volumes

  1. Navigate to the Administration – Server Configuration screen, Enterprises, and then Profile Configuration view.
  2. In the Profile Configuration view list, select Server Datasource (alias ServerDataSrc).
  3. Scroll down to the Profile Parameters, and then click Advanced.
  4. In the Profile Parameters list, select Datasource maximum fetch array size (alias DSMaxFetchArraySize), and then change the value to -1.
  5. Restart the Siebel Server.
Enabling Scalable Mode for Siebel Reports

When you have a large data volume or have complex XSL transformation logic you might want to enable BI Publisher’s XSLT engine to be scalable so that the engine will transform the raw data to XSL-FO template and generate the final output by using the hard disk instead of loading the file onto the memory space. In this way you can avoid ‘out-of-memory’ related issue at the BI Publisher’s reports generation process. You can enable the scalable mode parameter by configuring the BI Publisher’s configuration file, xdo.cfg file, which is located under the %JRE_HOME%\lib directory, where JRE_HOME is the one used for BI Publisher Enterprise Server.

To enable scalable mode for Siebel Reports

  1. Navigate to the jre\lib installation directory.
    NOTE: The path for the Java installation folder varies depending on where you installed JRE.
  2. Open the xdo.cfg file, and in the <Properties></Properties> tag, use the following syntax to set the Scalable Mode property to true (if not already set):
    <property name=”xslt-scalable”>true</property>
    NOTE: You can set Scalable mode to either true or false.
  3. Save the xdo.cfg file.
  4. Restart BI Publisher Server

Next

There are a few other critical things you can do as an Administrator such as Migrating the reports from Development environment to QA/Production environment, Enabling Logging for Debugging.

Categories: Oracle, Siebel Tags: ,

How to lock/unlock statistics on a table?

April 10, 2014 Leave a comment

In certain cases you may want to lock statistics in a table in certain cases, for example if you want a table not be analyzed by automatic statistics job but analyze it later or in cases where you want prevent from analyzing statistics in cases where data in the table doesn’t change.


-How to find table where statistics are locked.

select owner, table_name, stattype_locked from dba_tab_statistics where stattype_locked is not null; 

– unlock statistics
SQL> exec dbms_stats.unlock_table_stats(‘<schema>’, ‘<Table>’);
– To gather statistics on a table
SQL> exec dbms_stats.gather_index_stats(‘<schema>’, ‘<Table>’);
–To Lock statistics
exec dbms_stats.lock_table_stats(‘<schema>’, ‘<Table>’);
 
 
– shows when stats is locked the value of stattype_locked is ALL

SQL> SELECT stattype_locked FROM dba_tab_statistics WHERE table_name = ‘<table_name>’ and owner = ‘<Schema>’;
Follow

Get every new post delivered to your Inbox.

Join 527 other followers