Article 1: how to optimize slow query SQL statements in MySQL56-Introduction to slow logs: in actual log analysis, there are usually a large number of slow logs, at the same time, there will be a large number of records for the same query. here we need to find the most problematic and optimized log in the actual log an
get the data), all (for each previous row, Data is obtained through a full table scan.
Possible_keys: An index that may be used when querying.key: Represents the index that is actually used.Key_len: The length of the indexed field.rows: Number of scanned rows.Extra: Description and description of the implementation.
In the example above, it is already possible to confirm that a full table scan of table A is not efficient, then create an index to the Year field of Table A, as follows:
Mysql>
occur, the index becomes invalid, resulting in Table scanning. Because the query optimizer is an overhead-based optimizer, when it finds that the bookmarked search overhead caused by the use of non-clustered indexes is larger than the overhead of table scanning, it will discard the use of indexes and turn to table scanning.
1. re-create the index IX_UserName on the UserName and Age columns, and change the overwrite column to (UserName, Age, UserID)
=650; "src=" Https://s1.51cto.com/wyfs02/M00/96/06/wKioL1kcDgjRe_bMAAAs9MW26Zc669.png "style=" float : none; "title=" 9.png "alt=" Wkiol1kcdgjre_bmaaas9mw26zc669.png "/>find the average age of employees ?650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M02/96/06/wKiom1kcDg_gE8GLAAzuxPvuuVY834.jpg "style=" float : none; "title=" 10.jpg "alt=" Wkiom1kcdg_ge8glaazuxpvuuvy834.jpg "/>Check the average age of various positions , and sorted in descend
SQL Duplicate record query
1, look for redundant records in the table, duplicate records are based on a single field (Peopleid) to judge
SELECT * from people
where Peopleid to (select Peopleid from People GROUP by Peopleid have count (Peopleid) > 1)
Case Two:
SELECT * from TestTable
where Numeber to (select number from people group by number has count (number) > 1)
can detec
learned how to view the execution plan. I finally got a rough idea about the query process through the query plan. I also learned that clustered index scan and table scan did not use indexes, when you see the clustering index and index search, you can see the RID and key search secretly. You can see that the key search is definitely a keyword search. If you use the index, the efficiency must be high, so ev
, sum (s.total_logical_reads) sum_total_logical_reads, sum (s.total_ logical_writes) sum_total_logical_writes from sys.dm_exec_query_stats s GROUP by S.plan_ Handle ) as SS Cross APPLY sys.dm_exec_sql_text (ss.plan_handle) Torder by Sum_total_logical_readsdesc3. Identify slow-running queries:You need to periodically monitor the execution time of the input SQL queries and
Oracle with other methods (such as: RowNumber). In a later discussion about the "paging display stored procedure for TENS data", we will use the keyword top.Iv. how the query optimizer operatesThe preferred process to go through when we throw a T-SQL statement to SQL Server ready for execution is the compilation process, and if the statement was previously execu
required to complete the query is in the data buffer. It will soon find that the data is not in the data buffer, the pre-read mechanism is enabled to read the first nine of the 10 Data Pages required by the system to the data buffer zone. When SQL Server checks whether all the required data is already in the data buffer, it will
number of times they are executed. The smaller the number of executions, the faster the query speed. [7.0, 2000,200 5]
*****
In the execution plan, you can see the I/O and CPU costs. They do not have the "actual" meaning, for example, the usage of specific resources. The query optimizer uses these numbers to make the best choice. They can be used as a reference. Smaller I/O or higher CPU costs use less ser
to view the execution plan. I finally got a rough idea about the query process through the query plan. I also learned that clustered index scan and table scan did not use indexes, when you see the clustering index and index search, you can see the RID and key search secretly. You can see that the key search is definitely a keyword search. If you use the index, the efficiency must be high, so every time I w
Find duplicate data T-SQL in the database ========== first article ============ there are duplicate records under a field in a table, there are many ways, however, there is a method that is relatively efficient. The following statement: Select data_guid from adam_entity_datas A where. rowid> (select Min (B. rowid) from adam_entity_datas B where B. data_guid =. data_guid) if the table contains a large amount
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
T-SQL query: CTE, T-SQL: CTE
I have seen a simple example of the with as Clause in two books. I have not found any relevant information on the Internet.
Summary:
[Batch update of large tables]
[Batch Delete large tables]
[Keep only one row for completely repeated rows]
-- Create a test TABLE -- drop table [tabName] SELECT * INTO [tabName] FROM sys. objectsSELEC
clustered index
5. Then learn to view the implementation plan, through the query plan finally have a general understanding of the query process, I know, too. Clustered index Scan and table scan did not use the index, see Clustered index, index lookup happy exultant, see RID, key find secretly pleased, see, Key lookup is definitely the keyword search, with the in
Well, this is often a tricky situation, where you are running into virtual address fragmentation and getting OOM (out-of-memory) errors in your SQL Server. more often than not there is confusion between physical memory pressure. virtual Memory pressure. adding more RAM is definitely not a solution here!
Here are some sample error messages you might have seen in your SQL errorlog which will indicate if this
unlocked unlocked not locked NOLOCK unlocked unlocked unlocked HOLDLOCK shared share share update UPDLOCK error update update TABLOCKX error Unlocked not Lock update other unlocked unlocked Unlocked update * Specifies that the NOLOCK hint will make the table specified with this hint read-only in cursor.16, use Profiler to track the query, get the time required to query,
.
5. then I learned how to view the execution plan. I finally got a rough idea about the query process through the query plan. I also learned that clustered index scan and table scan did not use indexes, when you see the clustering index and index search, you can see the RID and key search secretly. You can see that the key search is definitely a keyword search. If you use the index, the efficiency must b
Top keyword: write in front of the field after selectFor example, you want to display the first 5 records of a query, as follows:Select Top 5 * from StudentIn general, top is the same as the order byOrder by uses the order by after the name of the table to fill in the fields you want to sort by, in ascending order (from small to large)Percent: Percent%=percentFor example, to display 5% of data processing, cannot write top 5%, but top 5 percentTip: If
clustered index on the datasheet, or the query optimizer does not use an index to find it. Each row of the data table is checked. If the table is relatively small, the table scan can be very fast and sometimes even faster than using the index.
So, when you see an execution table scan, the first thing to do is to see how many rows of data the data table has. If not too many, then the table scan may pro
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.