Factors Affecting Sql Server Performance

At present, I am reading "SQL Server Performance Tuning Practice", the following are the notes I took while reading this book

Database performance depends on various factors:
  hardware, operating system, software Hardware:   memory
, CPU,
  disk
Some objects that occupy a lot of CPU resources may not be properly cached in the memory, and a large amount of CPU resources need to be used to process the calculation of these objects, which will bring more pressure to the CPU.
  Memory:
    1. Execution plan cache
      database engine receives When it comes to the statement to be executed, a series of complex calculations and analysis will be carried out to obtain the corresponding execution plan, and then various operations will be performed according to the execution plan.
      Since the calculation and analysis of the execution plan requires a lot of CPU resources, it is very difficult. It is easy to cause the tension of CPU resources. In order to solve this problem, the database will cache the execution plan.
    2.
      If the data cache encounters a data access operator, it will first check whether the corresponding data is in the data cache, and if it exists, it will be removed from the cache.
      If the database memory is insufficient, the database engine will algorithmically clear the cache that is not commonly used, read the required data from the disk and cache the data into the data . In the cache, this will cause a lot of disk I/O, and cause the execution of the statement to be inefficient
      . If this happens in a large number of statements, it will cause the server CPU usage to skyrocket. If the server CPU is busy for a long time and the disk I/O of the database is high, it is estimated that the memory of the database has reached the bottleneck
  CPU: the database needs to use a lot of       CPU
    resources when performing tasks such as task scheduling, plan analysis, sorting and other calculations.
When the resource is around 30%: the current server is idle
      When the CPU resource is around 60%: the current server is busy When the
      CPU resource reaches 80%: the server is very busy, and it is necessary to find the reason (usually, some statements with high execution efficiency and unsatisfactory performance will cause such problems ; in a few cases, the database server has reached a bottleneck.) For
  high-concurrency database systems, it is recommended to use the following configuration scheme:
  split the data files of the main database into multiple files
  , and store the data files and log files on different physical disks. Thereby improving the concurrency of I/O.
  System database files, especially Tempdb data files, should be placed on independent physical disks, and the data files should be split into multiple pieces. It is recommended to have the same number of logical CPUs to improve concurrency

. Design table suggestion:
  add data as complete as possible Constraints, such as: not-null constraints, default value constraints, check constraints, unique constraints, foreign key constraints, etc. The addition of these constraints helps the database relational engine to analyze the execution plan
  using the smallest possible field type, especially for large tables, Minimal space will bring better performance
  . The design of table structure should consider the operation and frequency brought by business requirements, make business logic as simple as possible, and use simple SQL statements to avoid excessive table association
writing. SQL statement suggestion:
  Before writing a statement, you must first fully understand the business requirements, and know the purpose and usage of the table.
  Determine whether the filter fields used by the business can use indexes, and whether it is necessary to add indexes on the fields.
  Do not have more indexes. Fields perform any calculations, including functions, as this would make it impossible to use the index for data retrieval, resulting in a scan operation
  Small table operations are given priority, and small tables are used to drive large tables, so as to use NESTED LOOP-nested loops as much as possible (NESTED LOOP is a physical operation method for table association operations, which uses the foreach method to take a dataset with a smaller amount of data as It is more efficient than several other associated operations to compare the tables with larger built-in foreach loops.)
  Only query the required fields and avoid*
  try to use simple SQL statements to realize business functions. If the functions are too complex, you can consider Split it into several simple SQL statements
Simple SQL:
  no more than 4 associated tables at most
  No complex filter conditions, only 2 to 3 filter conditions, you can use the index search operation

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324509565&siteId=291194637