Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Overview
What is SQLTRACE ?
Feature description Ways to view info onstat g his sysmaster tables OAT
-2-
What is SQLTRACE?
SQLTRACE is a new feature in IDS 11 that allows you to collect SQL statement history information, including statistics and resource usage at the statement level. Each trace information includes
Optimizer statistics (like SET Explain and EXPLAIN_STAT) Iterator database and table names are available in MED mode Buffer and read/write statistics (like in onstat p) SQL info like onstat g sql (database name, session id, database isolation level, statement host variables) Host variables are only available in HIGH mode Procedure stacks are available in HIGH mode
-3-
Enabling SQLTRACE
Use SQLTRACE in ONCONFIG
SQLTRACE level=high,ntraces=4000,size=2,mode=global
SQLTRACE level=(low|med|high),ntraces=<#>,size=<# (# is in kbytes)>,mode=(global|user)
> execute function sysadmin:task("set sql tracing off"); (expression) SQL tracing off.
International Informix Users Group
-4-
Memory Usage
SQLTRACE level=high,ntraces=4000,size=2,mode=global
Each trace buffer size has been set to ~ 2 kbytes (~ 2048 bytes). Memory allocated for SQLTRACE is 2048 * 4000 = 7.8 Mb Statement text, table names, database name, or iterator information may be truncated if the SQL statement is too large to fit in the trace buffer.
-5-
User Mode
Scenario: You want to trace a single session. Turn on SQLTRACE in USER mode, then execute function sysamin:task for the session you are interested in. > execute function sysadmin:task(set sql tracing on, 4000, 2k, high, user); > execute function sysadmin:task("set sql user tracing on ", 16);
International Informix Users Group 6
-6-
Sessions 16, 17, and 18 are dbcron sessions by default, SQLTRACE is turned off. If the OFF flag is not set, then tracing for the session depends on the SQLTRACE mode, and in user mode, the options set for that mode.
International Informix Users Group
-7-
-8-
-9-
- 10 -
10
sysmaster:syssqltrace_info
SELECT flags, ntraces, format_units(tracesize/1024,'kb') as tracesize, duration , sqlseen, dbinfo('UTC_TO_DATETIME',starttime) as starttime, CASE WHEN sqlseen >= ntraces THEN TRUNC(ntraces/decode(duration,0,1,duration),5) ELSE TRUNC(sqlseen/decode(duration,0,1,duration),5) END as sqlpersec, format_units(memoryused,'b') as mem, (CURRENT - duration UNITS second)::DATETIME YEAR TO SECOND as starttrace FROM syssqltrace_info WHERE ntraces > 0 ; select * from syssqltrace_info; flags 5649 hex is 1611 ntraces 4000 tracesize 2024 duration 778 sqlseen 1785 starttime 1233479590 memoryused 8209744
International Informix Users Group
flags 5649 ntraces 4000 tracesize 1.98 KB duration 778 sqlseen 1786 starttime 2009-02-01 01:13:10 sqlpersec 2.29562 mem 7.83 MB starttrace 2009-02-01 01:13:10
- 11 -
11
sysmaster:syssqltrace_info flags
#define STMT_TRACING_ON #define STMT_TRACING_OFF #define STMT_TRACING_SUSPEND #define STMT_GLOBAL_TRACING #define STMT_USER_TRACING #define #define #define #define #define #define #define #define STMT_TRC_MASK STMT_TRC_DBSNAME STMT_TRC_STATEMENT STMT_TRC_RSAM_STATS STMT_TRC_PROCEDURES STMT_TRC_ITERATORS STMT_TRC_HOST_VARS STMT_TRC_TABNAMES 0x0001 0x0002 0x0004 0x0010 0x0020 0x7F00 0x0100 0x0200 0x0400 0x0800 0x1000 0x2000 0x4000
ON, OFF, SUSPEND GLOBAL or USER MODE LOW, MED, or HIGH LEVEL Attributes
- 12 -
12
MED
HIGH
Everything in MED + host variables
International Informix Users Group
- 13 -
Est Cost 1
Est Rows 1
Statement information: Sess_id User_id Stmt Type 27 200 SELECT Statement Statistics: Page Buffer Read Read 0 4 Lock Requests 4 Lock Waits 0
TX Stamp 2e50c
PDQ 0
Read % Cache 100.00 LK Wait Time (S) 0.0000 Avg Time (S) 0.0033 Actual Rows 1
Buffer IDX Read 0 Log Space 0.000 B Max Time (S) 0.0027 SQL Error 0
Buffer Write 0 Disk Sorts 0 I/O Wait Time (S) 0.000000 Isolation Level LC
Write % Cache 0.00 Memory Sorts 0 Avg Rows Per Sec 372.6609 SQL Memory 10368
Total Total Executions Time (S) 1 0.0033 Estimated Cost 1 Estimated Rows 1
- 14 -
14
Est Cost 1
Est Rows 1
Num Rows 1
Statement information: Sess_id User_id Stmt Type 27 200 SELECT Statement Statistics: Page Buffer Read Read 0 4 Lock Requests 4 Lock Waits 0
TX Stamp 2e50c
PDQ 0
Read % Cache 100.00 LK Wait Time (S) 0.0000 Avg Time (S) 0.0037
Buffer IDX Read 0 Log Space 0.000 B Max Time (S) 0.0031
Buffer Write 0 Disk Sorts 0 I/O Wait Time (S) 0.000000 Isolation Level LC
Write % Cache 0.00 Memory Sorts 0 Avg Rows Per Sec 325.4637 SQL Memory 10368
Estimated Estimated Actual SQL Cost Rows Rows Error 1 1 Informix Users Group 0 1 International
- 15 -
15
Est Cost 1
Est Rows 1
Num Rows 1
10
Statement information: Sess_id User_id Stmt Type 27 200 SELECT Statement Statistics: Page Buffer Read Read 0 4 Lock Requests 4 ... Lock Waits 0
TX Stamp 2e50c
PDQ 0
- 16 -
16
sysmaster tables
On 11.10, host variables info are not available through the sysmaster tables Schema for the sysmaster tables are in $INFORMIXDIR/etc/sysmaster.sql Use sql_id column to tie syssqltrace, syssqltrace_iter, syssqltrace_hvar info
OAT
sysmaster tables in 11.10 : syssqltrace sysqltrace_info sysqltrace_iter sysmaster tables in 11.50 : syssqltrace sysqltrace_info sysqltrace_iter syssqltrace_hvar
International Informix Users Group
- 17 -
17
OAT
Statement Types
Select, Insert, Update, Delete, Execute,
- 18 -
18
OAT
Can use OAT to Enable/Disable/Modify SQLTRACE options
- 19 -
19
Transaction information
Can use session id and TX stamp to group statements into transactions Begin, Commit, or Rollback are not traced See what the application is doing
- 20 -
20
Iterator/Explain ================ ID Left Right Est Cost 2 0 0 3 3 0 0 1 1 2 3 6 ... Total Total Executions Time (S) 1 0.0050 Estimated Cost 6 Estimated Rows 2
customer
Est Rows 3 23 2 Num Rows 2 1 1 Partnum 2097264 2097266 0 Type Seq Scan Index Scan Nested Join
orders
- 21 -
21
customer
Est Rows 3 23 2 Num Rows 16384 1 1 Partnum 2097264 2097266 0 Type Seq Scan Index Scan Nested Join
orders
- 22 -
22
- 23 -
23
- 24 -
24
- 25 -
25
Seq Scan is on the customer table rows processed is 16384. Index Scan is on the orders table rows processed is 23. What is this telling you ?
- 26 -
26
- 27 -
27
Response time is much better after the external directive has been applied.
- 28 -
28
After the External Directive: Seq Scan is now on the orders table rows processed is 23. Index Scan is now on the customer table.
- 29 -
29
Iterator/Explain ================ ID Left Right Est Cost 2 0 0 2 3 0 0 1 1 2 3 9 ... Total Total Executions Time (S) 1 0.0119 Estimated Cost 9 Estimated Rows 2
orders
Est Rows 23 3 2 Num Rows 23 1 1 Partnum 2097266 2097264 0 Type Seq Scan Index Scan Nested Join
customer
- 30 -
30
- 31 -
31
Checking sysdirectives
dbaccess stores_demo > select * from sysdirectives;
id 2 query select c.city, c.state, o.ship_date from customer c, orders o where c.customer_num = o.customer_num and c.state = ? directive FULL(orders), INDEX(customer 100_1) directivecode <BYTE value> active 1 hashcode -1903458431
- 33 -
33
- 34 -
34
- 35 -
35
- 36 -
36
- 37 -
37
- 38 -
38
- 39 -
39
- 40 -
40
Transactions
In a single session, ran 3 transactions Info from onstat g his output TX Stamp: 10bcd4a Statement #: 1 Statement #: 0 TX Stamp: 10bcd51 Statement #: 2 TX Stamp: 10bcd53 Statement #: 3
select col1 from tab1 where col2=? insert into tab1 values (0,100, ?) select col2 from tab1 where col3 matches ? delete from tab1 where col2 = ? ** Transaction was rolled back, but you cannot tell from the SQLTRACE info.
- 41 41
- 42 -
42
- 43 -
43
Quiz
TRUE or FALSE?
Statements in different sessions that have the same sql_begintxtime are part of the same transaction.
TRUE or FALSE?
Transaction stamp in OAT and TX Stamp in onstat g his output are the same.
TRUE or FALSE?
sql_begintxtime and transaction stamp in OAT are the same.
- 44 -
44
- 45 -
45
- 46 -
46
Est Cost 2
Est Rows 3
Num Rows 1
10
Statement information: Sess_id User_id Stmt Type 47 37108 SELECT Statement Statistics: Page Buffer Read Read 3 7
TX Stamp 10bdc4a
PDQ 0
Page Write 0
Buffer Write 2
- 47 -
47
Est Cost 1
Est Rows 1
Num Rows 1
smile
Statement information: Sess_id User_id Stmt Type 47 37108 INSERT Statement Statistics: Page Buffer Read Read 1 3
TX Stamp 10bdc4a
PDQ 0
Page Write 0
Buffer Write 2
- 48 -
48
- 49 -
49
- 50 -
50
sql_id 1
- 51 -
51
> select sql_id, sql_statement, sql_stmtname, sql_tablelist from sysmaster:syssqltrace where sql_begintxtime = 17555740 and sql_sid = 93;
52
- 52 -
syssqltrace (contd)
sql_id 3 sql_statement testdb:notify_shipping() <-- testdb:check_order() sql_stmtname UPDATE sql_tablelist orders sql_id 1 sql_statement testdb:log_updates() <-- testdb:notify_shipping() <-- testdb:check_order() sql_stmtname UPDATE sql_tablelist need_ship_date
sql_id 2 sql_statement testdb:notify_shipping() <-- testdb:check_order() sql_stmtname EXEC PROCEDURE sql_tablelist None
- 53 -
53
- 54 -
54
- 55 -
55
sysmaster tables
Write your own SQL to select from syssqltrace* tables into your own permanent tables
Use the new OAT feature that will allows you to save sysmaster:syssqltrace* tables info into permanent tables
International Informix Users Group 56
- 56 -
- 57 -
57
sql_showsnap procedure selects new traces in SQL buffer and inserts into mon_syssqltrace* tables Use dbschema -d sysadmin -f sql_showsnap to view the text of the sql_showsnap procedure
International Informix Users Group 58
- 58 -
sql_showsnap
CREATE FUNCTION sql_showsnap(task_id INTEGER, seq_id INTEGER) RETURNING INTEGER The task_id and the seq_id are inserted by the DB Scheduler from the tk_id and tk_sequence from the ph_task table The values also correspond to the run_task_id and run_task_seq in the ph_run table sql_showsnap returns the number of rows inserted into mon_syssqltrace table (stored in run_retcode column of ph_run table) Data in mon_syssqltrace* tables are deleted after 1 day (specified by tk_delete interval value in ph_task table)
International Informix Users Group
- 59 -
59
- 60 -
60
- 61 -
61
Previously collected SQLTRACE info being shown from the data saved by Save SQL Trace task.
International Informix Users Group
- 62 -
62
Execute sysadmin:task (...) (Set SQL Tracing INFO) (Set SQL Tracing RESIZE, number, size, mode) (Set SQL Tracing RESUME) (Set SQL Tracing SESSION) (Set SQL Tracing SUSPEND)
- 63 -
63
- 64 -
64
- 65 -
65
Hyun-Ju Vega
IBM vegah@us.ibm.com
- 66 -
66