sql query optimization tips

Read about sql query optimization tips, The latest news, videos, and discussion topics about sql query optimization tips from alibabacloud.com

SQL server2005 Optimization Query Speed 50 Methods summary _mssql2005

, shrink data and log DBCC SHRINKDB,DBCC shrinkfile. Set up automatic shrink logging. For large databases do not set up automatic database growth, it can degrade server performance. There is a lot of emphasis on T-SQL, and here's a list of common points: first, the process that the DBMS processes the query plan is this:The lexical and grammatical checks of the query

Oracle SQL query optimization. Part4

"> 2. Merge into statement: For the top statement, you can use the merge into statement --Merge into implementation method merge into EMP using (SELECT * from emp_new1 ) E on (e.empno = emp.empno) when matched then update set emp.empdesc = E.empdesc;The execution results are the same as the results in 1, assuming inference. It is recommended to use the merge into method. Because merge into only visits once emp_new1. Iii. Deleting delete op

Query optimization of tree hierarchical data in SQL

In a data query, starting with 2008, SQL Server provides a new data type, HierarchyID, specifically for manipulating hierarchical data structures.The HierarchyID type logically encodes information about a single node in the hierarchy tree by encoding the path from the root of the tree to the node.This path is logically represented as a sequence of node labels for all children that are accessed after the roo

MySQL Common 30 kinds of SQL query statement optimization method

from T where 1=0This type of code does not return any result sets, but consumes system resources and should be changed to this:CREATE TABLE #t (...)13, a lot of times with exists instead of in is a good choice:Select num from a where num in (select num from B)Replace with the following statement:Select num from a where exists (select 1 from b where num=a.num)14, not all indexes are valid for the query, SQL

A 20-second SQL slow query optimization experience and processing scheme

the first b_table left associated a_table, very slow, about 1 seconds more , and the amount of data is very small, but if in turn, a_table left associated b_table, then quickly, It's about 100 milliseconds . So, another interesting phenomenon is found: Large table Left association small table, very slow, small table left associative right table, soon. Of course, these we all know theoretically, but the actual development will be forgotten. Or when both tables are empty at first, and without ta

Supplement to SQL query optimization-(exists)

In the previous article "Supplement to SQL query optimization -- (in)", we mainly discussed the query statements such as select... from... where... in. Next, let's discuss Select... from... where... exists. The query speed of exists is much higher than that of in, which is w

SQL query optimization 1

1. UseProgramTo minimize the number of accesses to the database. By searching for parameters, You can minimize the number of rows accessed to the table and the result set, thus reducing the network burden; separate operations should be processed separately to improve the response speed each time. When using SQL in the data window, try to place the indexes in the first column selected;AlgorithmThe structure should be as simple as possible; During the

MySQL TENS Big Data SQL query optimization

is used, be sure 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

Large Data Volume query optimization-database design, SQL statement, Java encoding

Label:Database Design Aspects: 1, to optimize the query, should try to avoid full table scan, first of all should consider the where and order by the columns involved in the index. 2, should try to avoid the null value of the field in the Where clause to judge, otherwise it will cause the engine to abandon the use of the index for a full table scan.such as: Select ID from t where num is nullYou can set the default value of 0 on NUM, make sure that the

7 Common SQL Optimization tips

As programmers often interact with the database very frequently, it is necessary to master some of the optimization techniques of SQL. Here are some common SQL optimization tips, interested friends can understand.1. Note the use of like in a wildcardThe following notation ca

30 SQL query optimization principles

where num = 20 5. InAndNot inUse it with caution. Otherwise, full table scan may occur, for example:Select ID from t where num in (1, 2, 3)Continuous values can be usedBetweenDo not useInNow:Select ID from t where num between 1 and 3 6.The following query will also cause a full table scan:Select ID from t where name like '% ABC %'To improve efficiency, you can consider full-text search. 7. if you use parameters in the where clause, full ta

SQL Server Query Performance optimization--Creating index Principles (ii)

(user_lookups), if these two values are small, you might consider dropping the index.When you restart the SQL Server service, the various counters in the Sys.dm_db_index_usage_stats system view are initialized to null values. In addition, whenever data is detached or closed (for example, because Auto_Close is set to ON), all data rows associated with the database are deleted. When an index is first used, it is added to the system's statistics, and Sy

SQL query Slow optimization

', ' 11451 ') and (g.user_id = U.useridand g.is_up = ' true ' and g.checks = 1AND g.disabled = ' false ' And u.disabled = ' false ' and U.checkid = 2) LIMIT 50The above SQL runs for dozens of seconds because the data is a bit more, and then I use Explan.The index of walking is IND_IS_UPAnd then look at the is_up of how much data, in fact, are all true, so the ind_is_up here is not really interesting.So we're going to go back to the

Union all is used to replace union in SQL Union query optimization.

the complexity of O (n) algorithms to ensure that the data between datasets are not duplicated. With the theoretical basis, you can change the SQL structure. After ensuring that there are no duplicates in the Data logic, you can change the two Union statements to Union all, the response speed of a query changes from 1.7 seconds to 300 milliseconds, which takes only 17% of the previous time. Union is also u

SQL Query Performance Optimization----Resolve Bookmark Lookups

overlay index becomes very wide, then you can consider an index connection.For this sentence SQL (select Username,gender from dbo. UserInfo where username= ' userN600 ' and gender=1 ' can build a nonclustered index on the Gender.For this example, it is possible that the SQL optimizer does not use both the nonclustered index ix_username and our newly established index on gender, so we can tell the

Multi-table associated SQL query optimization

Tags: nbsp ati exist query multi-table Org Table Association 1.4 SeleSelect a from a a b where a.t=b.tSelect a from a-a where a.t in (select b.t from b b)Select distinct a.org_code,a.org_name from t_organzation a,t_dm_cdbp_organzation b where a.org_code=b.org_code;Select distinct a.org_code,a.org_name from T_organzation a where a.org_code in (select B.org_code from T_dm_cdbp_organzati on B);Select distinct a.org_code,a.org_name from T_organzation a wh

Multi-field fuzzy query SQL like % optimization and Difference

Multi-field fuzzy query SQL like % optimization and Difference Http://anforen.5d6d.com/ Select * From [klims]. [DBO]. [task] Where clientcompany like '% A %' or [address] Like '% A %' Select * From [klims]. [DBO]. [task] Where clientcompany + [address] Like '% A %' However, if one of the fields is null, data cannot be found in the second type. Http:

database design and SQL query optimization

Label:1. Overview2. Database design Principles1) familiar with the requirements2) Develop a database that conforms to the specifications3) Audit Database designIn addition to auditing the logical issues in database design, the audit team should also focus on whether the data dictionary is detailed and understandable, whether the data table structure is redundant, and suggests changes.3. Database Design Code1) Naming conventions2) clarify the relationship between the entity and the data table3) A

SQL High Performance Query optimization statement

V_cust_rcvlbesWHERE postcode> "98000"The number of rows in the view is 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. 23, you can use distinct without GROUP bySELECT OrderID from Details WHERE UnitPrice > Ten GROUP by OrderIDCan be changed to:SELECT DISTINCT OrderID from Details WHERE UnitPrice > 10 24. Use UNION ALL to not use UnionUNION all

SQL Query optimization

if the amount of data is small, create table to mitigate the resources of the system tables. Then insert. 24. If a temporary table is used, be sure 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. 2

Total Pages: 15 1 .... 7 8 9 10 11 .... 15 Go to: Go

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.