This article mainly introduces an abnormal MySQL Query case, mainly for index operations. For more information, see
Problem
User ticket question: the same statement, but the last limit row is different. It is strange that the performance of limit 10 is about 10 times slower than that of limit 100 statements.
Hide user table information. the statements and results are as follows:
SELECT f1 , SUM(`f2`) `CNT
Tags: and about an image COM explain online query comparisonAs a PHP developer, the index of MySQL is an essential issue For example, an SQL query: SELECT * FROM Userstatic where the nick like "" and rip=3726854906; Some of the questions that may be asked are: 1. If Nick is not an index and RIP is an index, will this condition
The MySQL version used in this article is 5.1.48
Select SQL _no_cache * from one where ID
#0 my_qsort2 (base_ptr=0x1b2176c0, count=4, size=8, cmp=0x869220
Through this bt, we can know that filesort is used in the join process, but before do_select [for not using temptabel], the qsort sorting algorithm is used.
1. Order by for a single table
Perform sorting in the create_sort_index of join: exec. First, it
MySQL statement execution sequence MySQL's statement is divided into 11 steps, as noted, the first execution is always the from operation, the last is to perform a limit operation. Each of these operations produces a virtual table that acts as a processing input, except that the virtual tables are transparent to the user, but only the last virtual table is returned as a result.If you do not specify a clause in the statement, the corresponding step is
Is there a way for mysql to return data in the specified order. For example, I want to search id1, 2, and 3 data. Whether written as whereidin (, 3) or whereidin (, 2), mysql returns results in the order of 1, 2, 3. Can you specify that mysql is returned in the
Tags: calling init nbsp Using the argument SED principle order configuration fileFirst, MySQL read the configuration file order Reading order:/etc/my.cnf >/etc/mysql/my.cnf >/usr/etc/my.cnf > ~/.MY.CNF Command verification:[[email protected] ~]#
Tags: beyond fetching data sharing picture technology here scan pointer Order SQORDER BY keyword optimization 1 try to sort by using the index method, avoiding sorting using the Filesort method. 2. MySQL supports two sorting methods, Filesort and Index,index, which refer to the MySQL scan index itself to complete the sorting. Filesort is inefficient in ordering.
Http://blog.sina.com.cn/s/blog_75ad10100101by7j.htmlHttp://www.cnblogs.com/zemliu/archive/2013/08/03/3234372.htmlFirst: Query_cache_type How to use query cachingIn general, we will set the Query_cache_type to on, which should be on by defaultMysql> SELECT @ @query_cache_type;+--------------------+| @ @query_cache_type |+--------------------+| On |+--------------------+Query_cache_type has 3 values of 0 for closing the
Label:The MySQL statement is divided into 11 steps, as noted, the first execution is always the from operation, and finally the limit operation is performed. Each of these operations produces a virtual table that acts as a processing input, except that the virtual tables are transparent to the user, but only the last virtual table is returned as a result. If you do not specify a clause in the statement, the corresponding step is skipped. Let's take a
***************************Id: 2Select_type: DEPENDENT SUBQUERYTable: IType: refPossible_keys: subcategoryKey: subcategoryKey_len: 4Ref: c. idRows: 28Extra: Using indexIf you are not familiar with how to analyze mysql statement query plans, see: mysql plans to execute queries from the outside to the inside, rather than from the inside to the outside. I will intr
This example describes a workaround for the Union clause in MySQL that does not support order by. Share to everyone for your reference, specific as follows:
I know very little about db, this problem is only encountered in MySQL, I do not know other DBMS is not the case.
The problem is, I'm going to get two rows next to a record in one table, and I want to take
Personal original address:http://www.phpthinking.com/archives/433 In the database we usually index some of the fields, which can improve the query speed of the data, and improve the performance of the database like order by, the group by before the index needs. First, we need to pay attention.1>mysql only one index can be used for a
SQL statement SELECT statement Query order
(7) SELECT
(8) DISTINCT
(1) from
(3)
(2) on
(4) WHERE
(5) GROUP by
(6) having
(9) ORDER by
(Ten) LIMIT
One, executes the FROM statement, the MySQL is executes from left to right, Oracle is executes from right to left, the SQL statement executes
Create the mysql_order_by_test data table according to the following table structure. We will use instance to tell you how to use MySQL order.
Order by uid ASCQuery data in the forward order of uid, that is, sort data in ascending order of uidOrder by uid DESCQuery data by
Optimize the MySQL statement with ORDER by index
Several guidelines for indexing:
1, reasonable indexing can speed up the efficiency of data reading, the unreasonable indexing will slow down the response speed of the database.
2, the more indexes, the slower the speed of updating data.
3, try to use MyISAM as the engine when using the index (because MySQL to b
Overview
The MySQL optimizer's main work consists of the following sections: Query Rewrite (including outer JOIN conversion), const table detection, range analysis, JOIN optimization (Order and access selection) , plan refinement. This case begins with range analysis.2.2 Range Analysis
This section includes all range and index merge cost evaluations (refer to
through an index optimization, you will need to make a federated index of the field under where Condition and order by!3,limit limit 93060,20 Before this limit will affect the number of scanned rows! 93060 rows of data must be scanned regardless of index! Actually, otherwise! As long as the index is used, it just takes the data !Mysql> desc SELECT ActionId, UserID, CreateUser, ActionType, ActionName, Actio
following example:
IF @ custno is not null -- customer number SELECT... from mers where custno = @ custnoELSE IF @ idno is not null -- ID number SELECT... from mers where natregno = @ natregnoELSE IF @ custname is not null -- customer name select top 200... from mers where custname LIKE @ custname + '%' order by custnameELSE RAISERROR ('no query condition is provided! ', 16, 1)
Note: Do not worry too
Wondering if there is a way to get MySQL to return data in the order specified.
For example I want to search for id=1, 2, 3 data.
Whether it's written as where ID in (1,3,2) or where ID in (*. 1), MySQL returns the result in the order of 2, 3, or not, can you specify MySQL t
; insert into tb_slow select * from tb_slow ;.... insert some records again .... root @ localhost [tempdb]> insert into tb_slow select * from tb_slow; Query OK, 212224 rows affected (37.51 sec) Records: 212224 Duplicates: 0 Warnings: 0root @ localhost [tempdb]> select table_schema, table_name, count (*) from tb_slow-> group by table_schema, table_name order by 3, 2; + -------------------- + ----------------
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.