You are on page 1of 24

SQL Tuning

27/06/2016
Chandra Sekhar
Mohd Sayeed Akthar
Agenda

SQL client parameters

SQL specific broker parameters

SQL Server tuning

2
SQL client parameters
The Driver is the network

ODBC/JDBC

4
Managing connections - Connection Retry Count

- Connection Retry Delay


Client Client Client
- Login Timeout

Retry??

How long should I wait??


SQL

After what delay


??

DB How many
times??
5
Query Timeout
- Query Timeouts
SELECT * FROM Application
Pub.vBigTable

ODBC
SELECT * FROM
Pub.vBigTable
How much can I wait
for one query
SQL Server execution??

DB

6
Managing Availability - Alternate Servers

- Failover Mode
Client Client Client
- Failover Granularity

- Failover Preconnect

- Load balancing
SQL SQL SQL

DB DB DB

7
Security configurations -EncryptionMethod

SQL - CryptoProtocolVersion
Client
SELECT * FROM XY&*X#$
CUSTOMER - ValidateServerCertificate
*(KNJ$(#$
- HostNameInCertificate

$ @ % A A A A

% ( ^ ( B B B B Are protocol ver. and


^ ^ * * C C C C

& ! ! ^ D D D D
encryption method same
* @ $ #
SQL Server E E E E

at both the ends??


Start Broker
with -ssl DB

8
Network Using more efficiently - Fetch Array Size

SQL
Client

SQL Server
A

B
A

B
A

B
A

B
What should I configure??
C C C C

D D D D

E E E E

DB How many rows in one


request??

9
Handling with different code pages IANAAppCodePage=18

SELECT * FROM Application


.
EUC-JP

ODBC {, , }

SELECT * FROM UTF-8


USA.Presidents How to synchronize
between different
SQL Server Character sets??
{Kennedy, Obama, }

DB

10
SQL specific broker parameters
All about Locks
What should I
configure???

Transaction T1 Transaction T2

SQLLockWaitTimeout

Res-A Res-B

Locks Default: 5 Seconds

Transaction Management DFLT_LOCKWAIT-TIMEOUT

proserve db <dbname> -S <port-number> Max: 32 bit integer


-SQLLockWaitTimeout 15
12
4,294,967,295 Seconds
All about Locks

Transaction T1 Transaction T2

TRANSACTION
ISOLATION LEVEL
Res-A Res-B
SET TRANSACTION ISOLATION
NO LOCK
LEVEL READ UNCOMMITTED
Locks
SELECT CustNum, Name from
LOCK TABLE Pub.Customer
Pub.Customer Where IN
Transaction Management EXCLUSIVE
City=Bedford MODE;
(NOLOCK)

13
ABL inserted more

SQLTruncateTooLarge
SQL: ahh, I can see you (California)
SQL: I can see but partially (Califor)!! SQLWidthUpdate
SQL: I cannot understand you!!
ABL: I Can see (California)!! How should I
SQL ABL configure???

proserve db <dbname> -S <port-number>


-SQLTruncateTooLarge <on/off>
DB jdbc:datadirect:openedge://<ip>:<port>;
databaseName=<dbname>;
varchar(7) : truncateTooLarge=<on/off>;
Hey, can you see (California)?
14
SQL query plan caching -SQLStmtCache

O Statements
Cache
O SQL
O

DB

15
Temporary tables, buffers - configurations
-SQLTempBuff

-T

-t
O Temporary Tables
buffer
O SQL
Select CustNum, Count(OrderNum)
O
From Pub.Order Group By
CustNum Order By Custnum
Sorting
DB
Temp
DB
Aggregation
Temp. Result Set

16
Configuring Stack size


Local Data
Return 3 Default - 1MB -SQLStack

Local Data
O How big it
Return 2
SQL O should be???
O Local Data
Return 1

DB Local Data
Return 0

17
SQL Server Tuning
Optimizer and Statistics
Statistics
SELECT * FROM Customer, Order WHERE
Customer.CustNum=Order.CustNum

Which one is Opt..

good??? SQL Cost


Based

Join Join
DB

Order Customer Customer Order

19
What to look for
UPDATE STATISTICS;
Statistics
UPDATE TABLE STATISTICS AND
INDEX STATISTICS AND
COLUMN STATISTICS FOR Customer; How often I
should update?
Table Column
_SysTblStat _SysColStat
Index
_SysIdxStat

On 20% change in data!!

20
Is it good to create many indexes?

Indexes comes with some overhead.


Overhead in terms of INSERT, UPDATE and DELETE
In terms on memory consumption
Creating indexes on right columns.
Columns which are most often used in WHERE clause
Columns which are most often used as JOIN predicate
Columns which are most often used in GROUPING (Aggregations)
Columns which are most often used in ORDERING (Sorting)
Use Type-2 areas

21
SQL Hints

NOEXECUTE
SELECT CustNum, Name from Pub.Customer Where City=Bedford NOEXECUTE;
NO REORDER
SELECT CustNum,OrderNum from
Pub.Customer c, Pub.Order o {NO REORDER}
Where c.custNum = o.CustNum
FORCE INDEX
SELECT CustNum,Name from Pub.Customer FORCE ( INDEX (IDX_NAME))

Where CustNum > 10 and Name=American Express

22
Questions?

You might also like