50 tips for optimizing query: (see which one is suitable for you)
1. Place data, logs, and indexes on different I/O devices to increase the reading speed. In the past, tempdb can be placed on raid0, which is not supported by SQL2000. The larger the data size (size), the more important it is to increase I/O.
2. vertically and horizontally split the table to reduce the table size (sp_spaceuse)
3. upgrade hard
to explicitly delete all temporary tables at the end of the stored procedure, TRUNCATE table first, and then drop table, which avoids longer locking of the system tables. 25. Avoid using cursors as much as possible, because cursors are inefficient and should be considered for overwriting if the cursor is manipulating more than 10,000 rows of data. 26. Before using a cursor-based method or temporal table method, you should first look for a set-based solution to solve the problem, and the set-bas
30 SQL query optimization tips for mysql with tens of millions of big data, mysqlsql
1. To optimize the query, try to avoid full table scanning. First, consider creating an index on the columns involved in where and order.
2. try to avoid null value determination on the fiel
Yesterday's SQL Server query performance optimization-index creation principle (I) mainly introduced the principle. today are some of the main principles and checks the created indexes.
Iii. indexing principles
In general, building indexes depends on the data usage scenarios. In other words, which SQL statements are co
data types of the participating operations, such as the int type has ">,
d)join/on clause position: The JOIN/ON clause can be split into two parts, one is the JOIN block is similar to the FROM clause, and the ON clause block is similar to the WHERE clause, both of which can appear subqueries. The subquery is handled in the same way as the FROM clause and the WHERE clause.
e)GROUPBY clause position: The destination column must be associated with the GROUPBY 1. Subq
= rcvlbes.customer_id and rcvblls.balance>0 ORDER by Cust.name Into TEMP cust_with_balance Then query in the temporary table in the following way: SELECT * from Cust_with_balance WHERE postcode> "98000" The rows in the staging table are less than the rows in the primary table, and the physical order is the required order, reducing disk I/O, so the query effort can be significantly reduced. Note: Changes to
First of all, let's look at one of the steps here that translates into banner, which requires pivot, step-by-step Then look at the overall query results for the two query methods after the main table join So take a look at the latter query method is also through the industry after the conversion to do the join execution plan, you can see only the Word table
cust_with_balanceThen query in the temporary table in the following way:SELECT * from Cust_with_balanceWHERE postcode> "98000"The rows in the staging table are less than the rows in the primary table, and the physical order is the required order, reducing disk I/O, so the query effort can be significantly reduced.Note: Changes to the primary table are not reflected when the staging table is created. When d
Optimization objectivesReduce IO timesIo is always the easiest place to bottleneck the database, which is determined by the responsibility of the database, most of the database operations over 90% of the time is occupied by IO operations, reducing IO times is the first priority in SQL optimization, of course, is the most obvious
MySQL configuration file, my.cnf (Windows My.ini), and add the following lines under [Mysqld]: slow_query_log=1 long_query_time=2 slow_query_log_file= /usr/slow.log log_queries_not_using_indexes=1 Restarting the MySQL service Location of MySQL configuration file The windows:windows configuration file is My.ini, usually under the MySQL installation directory or under C:\Windows. The Linux:linux configuration file is my.cnf, usually in/etc. Identify the QR code in the
cursors are inefficient and should be considered for overwriting if the cursor is manipulating more than 10,000 rows of data.26. Before using a cursor-based method or temporal table method, you should first look for a set-based solution to solve the problem, and the set-based approach is generally more efficient.27. As with temporary tables, cursors are not unusable. Using Fast_forward cursors on small datasets is often preferable to other progressive processing methods, especially if you must
rcvblls.balance>0ORDER by Cust.nameInto TEMP cust_with_balanceThen query in the temporary table in the following way:SELECT * from Cust_with_balanceWHERE postcode> "98000"The rows in the staging table are less than the rows in the primary table, and the physical order is the required order, reducing disk I/O, so the query effort can be significantly reduced.Note: Changes to the primary table are not reflec
Optimization of SQL massive data query and non-use like processing solutions, data query like
1. To optimize the query, try to avoid full table scanning. First, consider creating an index on the columns involved in where and order.
2. Try to avoid null value determination on
Optimization of SQL massive data query and non-use like processing solutions, data query like
1. To optimize the query, try to avoid full table scanning. First, consider creating an index on the columns involved in where and order.2. Try to avoid null value determination on
like:SELECT [Column1],[column2],.... From [TABLE] ORDER by [sort] LIMIT [offset],[limit];This SQL statement optimization is relatively simple and can be indexed on the [Sort] field.(2). WHERE + ORDER by + limit combination index optimization, shaped like:SELECT [Column1],[column2],.... From [TABLE] WHERE [COLUMNX] = [VALUE] ORDER by [sort] LIMIT [offset],[limit]
,'YYYYMMDD') Rangebetween thePreceding Currentrow)End asf70115_70011, Case
whenA.c_date>To_char (sysdate-3,'YYYYMMDD')
Then
sum(VALUEF1) Over(Partition byA.code,a. Year Order byTo_date (A.c_date,'YYYYMMDD') Rangebetween thePreceding Currentrow)End asf70104_70011, Case
whenA.c_date>To_char (sysdate-3,'YYYYMMDD')
Then
sum(VALUEF6) Over(Partition byA.code,a. Year Order byTo_date (A.c_date,'YYYYMMDD') Rangebetween thePreceding Currentrow)End asf70126_70011, Case
whenA.c
. Method Three: Using connection query Connection queries include: 1. Self-connect (join equals inner JOIN): Query result is data that exists on both sides 2. Left join to the left join: return all data on the right, return to the back, null not present 3. Right join: Return all data on the right, return on left, no null 4. Fully connected full join: Returns if one of the tables exists and the other does
Five practical tips for MySQL Query Optimization,
This article summarizes and analyzes the MySQL query optimization techniques. We will share this with you for your reference. The details are as follows:
Anyone familiar with SQL s
tables. 25. Avoid using cursors as much as possible, because cursors are inefficient and should be considered for overwriting if the cursor is manipulating more than 10,000 rows of data. 26. Before using a cursor-based method or temporal table method, you should first look for a set-based solution to solve the problem, and the set-based approach is generally more efficient. 27. As with temporary tables, cursors are not unusable. Using Fast_forward cursors on small datasets is often preferabl
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.