Alibabacloud.com offers a wide variety of articles about steps to optimize sql query, easily find your steps to optimize sql query information here online.
[Author]: KwuUsing subqueries to optimize the SQL for hiveExecute a simple statement in 100 million data to query the number of users who only visit the primary site at a time:Select COUNT (*) as CNT from Tracklog GROUP by Cookieid have cnt=1;Query response is slow, half an hour is not the resultOptimizing Hive-
There are many methods to optimize the stored procedure. The seven most commonly used methods are described below.
1. Use the set nocount on Option
When we use the SELECT statement, in addition to returning the corresponding result set, the corresponding number of affected rows will also be returned. After set nocount on is used, no additional information is returned except for the dataset, reducing network traffic.
2. Use the specified schema.
When u
1. To optimize the query, avoid full-table scanning as far as possible, and first consider establishing an index on the columns involved in the Where and order by.2. Try to avoid using the! = or 3. Avoid null-valued fields in the WHERE clause, which will cause the engine to discard full-table scans using the index, such as:Select ID from t where num is nullYou can set the default value of 0 on NUM, make sur
Split fields to optimize SQLToday see a function to handle the connection of SQL, is a group of a netizen, the SQL statement is as follows:SELECT so_order.fdate, so_order.fsnfrom so_order INNER JOIN so_orderitem on CHARINDEX (so_ Orderitem.fid, So_order.fid) >= 1WHERE So_order. forderdate = ' 2015-09-06 'SELECT so_order.fdate, so_orde
about 7 s before optimization, the first 0.3 s after optimization, and the second 0.1 s after optimization.We can see that the disk I/O is the performance bottleneck before optimization, and the SSD speed is much faster than SATA. After optimization, the disk is no longer the bottleneck, and there is no difference in SSD and SATA performance.
On the Linux platform, the/tmp directory is used by default. Note that the/tmp directory is small.
3) when UNION or union all is used, the SELECT
maintenance of your system!Do not underestimate the power of a statement, a statement sufficient to make your system completely unable to work! A question followed by a statement a aimless optimization? How do I find the system's problem statement? What's a priority?See the previous article: Expert Diagnostic Optimization Series------------------statement tuning kickI'll use the Expert for SQL Server tool to tell you how to index a key statement
time will be spent.
(4) Reduce the number of accesses to the database:
Oracle does a lot of work internally: Parsing SQL statements, estimating index utilization, binding variables, reading chunks, and more.
(5) Reset the arraysize parameters in Sql*plus, Sql*forms, and pro*c to increase the amount of retrieved data per database access and the recommended value
), and E (end date). now, you need to split multiple time periods between two dates by month, the first month and the last month start with "S" and "E" respectively, and the Middle month is the complete month.
A
1
= Db. query ("select I, S, E from T ")
2
= A1.news (interval @ m (a = S, B = E) + 1; I, max (a, pdate @ m (after @ m (,~ -1): S, min (B, pdate @ me (after @ m (,~ -1): E)
Pdate @ m and @ me can c
Today, I am reading the new features of SQL Server 2012. when I see one, I find sys. the dm_exec_query_stats System View is upgraded. Because this attempt is always in use and is quite useful, it can be said that it is the calculator used to find and optimize SQL statements. Therefore, we have made a special record today.
The definition of SYS. dm_exec_query
window.If an error is entered in osql, you can use the reset osql command to return to 1> the prompt character,1> sp_helpbd2> Reset1> sp_helpdb2> goTo stop osql, enter quit or exit. You can also press Ctrl + C to end a command or interrupt the query without exiting the osql utility.The osql utility can recognize not only-u,-P, and-S parameters. For more information about available osql parameters and osql, see the osql utility topic in the online gui
Use useindex to optimize SQL queries
Let's take a look at the table structure of arena_match_index. pay attention to the index structure of the table.Create table 'Arena _ match_index '('Tid' int (10) unsigned not null default '0 ','Mid 'Int (10) unsigned not null default '0 ','Group' int (10) unsigned not null default '0 ','Round 'tinyint (3) unsigned not null default '0 ','Day' date not null default '2017
, these columns should be isolated to a different table.SQL OptimizationIf the design of the table has been determined and the modifications are difficult, you can also improve the efficiency of SQL execution by optimizing the SQL statement to reduce the size of the temporary table. The common optimization SQL statements are as follows: 1) Splitting the
unhandled error occurs during the execution of the request,The corresponding processing steps can be configured through the This section allows developers to configureHTML error page to displayTo replace the error stack trace. -Step Two: Execute the following command in CMD to open the SQL Server database support for SqlCacheDependency, using the Aspnet_regsql.exe tool, which is located in the Windows\micr
[bigTransactionHistory] with(paglock)) as twhere t.rn between 15631801 and 15631802
We can see that the method of viewing execution plans is not suitable here. we need to have a more detailed understanding of resource consumption.
Note: We can also use Trace Profiler to capture locks, but be careful when using them.
Row_number () cannot see lock upgrade by default, and may be upgraded back to the global performance bottleneck
If your application doesn't care about dirty reads, the nol
1. Try to avoid using the! = or 2, 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.3, 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
Optimize common oracle SQL statements
1. execution efficiency caused *
Minimize the use of select * For queries. When you use * For queries *,The database parses and converts * to all columns.
Select count (si. student_id)From Student_info si (student_id is the index)AndSelect count (*) from Student_info siDuring execution, the preceding statement is faster than the statement without index statistics below.
Mysqlprofileexplainslow_query_log Analysis and Optimization queries often encounter some SQL problems in performance tests. In fact, the most problems encountered during performance tests over the past few years are the database, which is either high IO or high cpu, therefore, Data Optimization plays an important role in performance testing. I will introduce some msyql Performance
Mysql profile explain slow_query_log Analysis and Optimization queries
]);$data = $query->all();$data = $query->one();
In fact, there are many database query methods in the yii framework, such:
$data = JdCrmSmsUserModel::find()->where([ 'vender_id' => [ $venderId ] ])->all();
Or use findBySql (), findOne (), findAll (), and so on to replace find () for
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.