About SQL SERVER high concurrency solutions

SQL SERVER high concurrency solutions mainly from the following aspects:

1.SQL statement optimization:

  A. exactly as the query conditions and query field, narrow your search (including the use of paging query);

  B. query in as little as possible: like, (not) in, (not) is null, order by, distinct, count (*), =, <>;!

  C. Do not functional operation of the field query,

    Such as: aa substring ( 'aa123', 1,2) = 'aa', but it should be:. 'Aa123' like 'aa%'; --- applied to the index

      . Bb 'aa' + '123' = 'aa123', but it should be: 'aa' = left ( 'aa123', 2)

  D. judgment data is present, do not use the TOP 1, but should be: EXITS

  E. For complex SQL queries, stored procedures can be used directly or create SQL view (view is not too complex);

  F. as little as possible with the cursor, trigger;

Table 2. Design Optimization:

  A. Design of the longitudinal partition table, the table in accordance with certain principles (reader may be designed in accordance with the field frequency) are designed to correspond to several tables, using the correlation between the main (off) key query;

  B. Design of the transverse partition table, the data table used in accordance with the value (for example: only valid data is used only in the past three months) to transfer backup data to reduce the amount of data tables;

  C. partition table data storing physical design, the data in the table to establish a physical partition to store table according to certain rules, in order to reduce the burden on the hard disk IO;

  D. establish appropriate index (clustered index and non-clustered index);

3. Set the transaction optimization:

  There :( transaction isolation level isolation level in effect on the transaction, while the lock acts on each SQL statement)

Isolation Levels

Dirty read

Non-repeatable read

Phantom

Explanation

 Generating a corresponding lock or equivalent

Uncommitted read (read uncommitted)

Yes

Yes

Yes

If another transaction updates, regardless of whether or not to submit, immediate implementation

 NOLOCK

Read Committed (read committed by default)

no

Yes

Yes

Reads the data submitted. If another transaction updates did not submit, then wait

 HOLD LOCK

Repeatable Read (repeatable read)

no

no

Yes

During the inquiry, does not allow other transactions update

 HOLD LOCK

Serializable (Serializable)

no

no

no

During the inquiry, does not allow other affairs insert or delet

 HOLD LOCK

    A. transaction isolation principles: shared read, exclusive write , that means: when performing a query, if the data consistency demanding, can be re-read (repeatable read) isolation level, if not strictly required, you can We recommend the use of uncommitted read (read uncommitted) isolation level;

4. The server hardware optimization:

  A. The core hardware performance server memory, hard drive, etc. Of course, the stronger the better;

  B. later establish multiple servers and clustered to allow parallel calculation using a plurality of computers so as to obtain a high calculation speed, a plurality of computers may be used for backup, so that any bad a machine or the entire system to normal operation;

    C. Establishment DB mirror synchronization, and read by the server in a multi-stage separation, i.e.: In addition to one or several servers having the specified update allowed, the rest of the servers only as a data mirror synchronization can not be updated, only the query;

 

Original link: https://www.cnblogs.com/soundcode/p/6927543.html

Guess you like

Origin www.cnblogs.com/zhaoyl9/p/11346526.html