复合索引的列顺序判断
复合索引最令人困惑的当属索引列的顺序,不仅依赖于使用该索引的查询,更需考虑排序和分组。前段时候我发了个帖子:where条件顺序和复合索引字段顺序。感兴趣的朋友不妨参与讨论。今天我提个自己的观点。在应用开发阶段,【选择性】是我们首要考虑因素,请看
复合索引最令人困惑的当属索引列的顺序,不仅依赖于使用该索引的查询,更需考虑排序和分组。前段时候我发了个帖子:where条件顺序和复合索引字段顺序。感兴趣的朋友不妨参与讨论。今天我提个自己的观点。在应用开发阶段,【选择性】是我们首要考虑因素,请看简图:
当出现sql性能问题时,你可能需要注意以下几个:1. 随机IO2. 排序(order by)3. 分组(group by or distinct)这时不必也不应该在关注【选择性】我的经验便是,在你手上已经有Top N SQL时,我们应该优先考虑【值的分布】,而不是选择性。
那么该如何判断【值的分布】,我们通过一种被geek称之为 【sarg】的方法,具体操作如下:假如,我们有如下query:
select * from userresult_f where askid=800808 and uid=110996854;
则有2个索引可供选择:1. idx_1 (askid,uid)2. idx_2 (uid,askid)是1 还是2 ?利用【sarg】方法:
mysql> select sum(askid=800808),sum(uid=110996854) from userresult_f\G; *************************** 1. row *************************** sum(askid=800808): 6 sum(uid=110996854): 2 1 row in set (0.00 sec)
依据查询输出,我们应该选择 idx_2
By 数据牧羊人Good Luck!2014-4-27 19:05 于福州

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP email detection: Determine whether the email has been sent successfully. When developing web applications, you often need to send emails to communicate with users. Whether it is registration confirmation, password reset, or sending notifications, the email function is an indispensable part. However, sometimes we cannot ensure whether the email is actually sent successfully, so we need to perform email detection and determine whether the email has been sent successfully. This article will introduce how to use PHP to implement this function. 1. Use SMTP server to send emails. First, we need to use SM

Oracle index types include: 1. B-Tree index; 2. Bitmap index; 3. Function index; 4. Hash index; 5. Reverse key index; 6. Local index; 7. Global index; 8. Domain index ; 9. Bitmap connection index; 10. Composite index. Detailed introduction: 1. B-Tree index is a self-balancing tree data structure that can efficiently support concurrent operations. In Oracle database, B-Tree index is the most commonly used index type; 2. Bit Graph index is an index type based on bitmap algorithm and so on.

Question: How to determine whether the date is the previous day in Go language? In daily development, we often encounter situations where we need to determine whether the date is the previous day. In the Go language, we can implement this function through time calculation. The following will be combined with specific code examples to demonstrate how to determine whether the date is the previous day in Go language. First, we need to import the time package in the Go language. The code is as follows: import("time") Then, we define a function IsYest

jQuery is a JavaScript library widely used in web development. It provides many simple and convenient methods to operate web page elements and handle events. In actual development, we often encounter situations where we need to determine whether a variable is empty. This article will introduce several common methods of using jQuery to determine whether a variable is empty, and attach specific code examples. Method 1: Use the if statement to determine varstr="";if(str){co

In this tutorial, we will write a program that checks whether a given binary number is divisible by 64. We are given a binary number and we can remove some bits to make it divisible by 64. After removing the bits, if the number is divisible by 64, print Yes, otherwise print No. The method we will use is very simple. Let's look at the steps to solve the problem. Initialize a binary number in string format. Iterate over the given binary numbers. Count the number of zeros. If a binary number contains greater than or equal to 6 zero bits, the number is divisible by 64. Prints whether the given binary number is divisible by 64. Example Let's look at the code. #include<bits/stdc++.h>usi

This article will explain in detail how PHP returns the string from the start position to the end position of a string in another string. The editor thinks it is quite practical, so I share it with you as a reference. I hope you will finish reading this article. You can gain something from this article. Use the substr() function in PHP to extract substrings from a string. The substr() function can extract characters within a specified range from a string. The syntax is as follows: substr(string,start,length) where: string: the original string from which the substring is to be extracted. start: The index of the starting position of the substring (starting from 0). length (optional): The length of the substring. If not specified, then

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

How to improve the efficiency of data grouping and data aggregation in PHP and MySQL through indexes? Introduction: PHP and MySQL are currently the most widely used programming languages and database management systems, and are often used to build web applications and process large amounts of data. Data grouping and data aggregation are common operations when processing large amounts of data, but if indexes are not designed and used appropriately, these operations can become very inefficient. This article will introduce how to use indexes to improve the efficiency of data grouping and data aggregation in PHP and MySQL, and improve
