辛星让mysql跑得更快第二节之索引上部分_MySQL
如果把我们的数据库信息当做一本书或者一个字典,那么索引可以理解为它的目录,如果我们创建一个优秀的目录,那么我们检索信息就会快得多,如果我们创建一个渣渣索引,也有可能拖垮整个系统。
索引我们分为四类,通常分为四大类型,即主键索引、全文索引、唯一索引、普通索引,这是按照索引的类型来分的。所谓主键索引,那就是当我们创建一张表的时候,如果我们指定了一个主键,那么它就自动成为主键索引,比如SQL语句如下(这里的id就自动成为了主键索引):
create table xin(id int unsigned primary key auto_increment, name varchar(32) not null default '');
一般来说,对于普通索引,我们可以在创建表的时候指定索引,也可以在创建表的时候指定索引,下面我们以县创建表然后再添加索引为例,看代码:
#创建一个数据表 create table xin(id int unsigned, name varchar(32) not null default ''); #在该表上创建一个索引 create index xiaohei on xin(id);
然后说一下全文索引,所谓全文索引,主要是从数据库中搜索字符串信息的,比如我们逛很多论坛,它的搜索功能就特别需要全文索引了,我们的全文索引主要针对文件、文本的索引,而且目前来说,全文索引依然只对引擎MyIASM有效,咱们指定一下表的引擎就可以了,看下面代码:
#创建一个文章表,并且设置索引 create table article(id int primary key, title varchar(200) not null , body text, fulltext(title,body) ) engine = myisam ;
#按照这种方式我们可以快速的使用全文索引来查找内容 select * from article where match(title,body) against ('xin');
对于unique索引,也就是唯一索引,我们直接在在列级完整性约束后面加一个unique即可,这里需要注意的是被unique修饰的字段是可以为空的,而且是可以有多个为空的,当然也可以像创建一个普通index那样去创建,但是此时的index必须在前面加上一个unique修饰符。
对于索引的删除,可以使用【alter table 表名 drop index 索引名】,但是我感觉我们使用【drop index 索引名 on 表名】更好一些。
那么我们怎么看一个表的索引呢,我们可以用【desc 表名】的方式来查看索引,我们还可以使用【show index from 表名】或者【show index from 表名】来查看一个表的索引。

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

AI Hentai Generator
Generate AI Hentai for free.

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



How to Fix 100% Disk Usage on Windows 11 The straightforward way to find the problematic application or service causing 100% disk usage is to use Task Manager. To open Task Manager, right-click on the Start menu and select Task Manager. Click the Disk column header to see what's using the most resources. From there, you'll have a good idea of where to start. However, the problem may be more serious than simply closing an application or disabling a service. Read on to find more potential causes of problems and how to fix them. Disabling SuperfetchSuperfetch feature (also known as SysMain in Windows 11) helps reduce startup time by accessing prefetch files

<h2>How to Hide Files and Folders from Search on Windows 11</h2><p>The first thing we need to look at is customizing the location of Windows Search files. By skipping these specific locations, you should be able to see results faster while also hiding any files you want to protect. </p><p>If you want to exclude files and folders from searches on Windows 11, use the following steps: </p><ol&

If your search bar isn't working in Windows 11, there are a few quick ways to get it up and running in no time! Any Microsoft operating system can experience glitches from time to time, and the latest operating systems are not exempt from this rule. Additionally, as pointed out by user u/zebra_head1 on Reddit, the same error appears on Windows 11 with 22H2Build22621.1413. Users complained that the option to toggle the taskbar search box randomly disappeared. Therefore, you must be prepared for any situation. Why can't I type in the search bar on my computer? The inability to type on the computer can be attributed to different factors and processes. Here are some things you should be aware of: Ctfmon.

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.

Run the Search and Indexing Troubleshooter in Outlook One of the more straightforward fixes you can start is to run the Search and Indexing Troubleshooter. To run the troubleshooter on Windows 11: Click the Start button or press the Windows key and select Settings from the menu. When Settings opens, select System > Troubleshooting > Additional Troubleshooting. Scroll down on the right side, find SearchandIndexing and click the Run button. Select Outlook Search to return no results and continue with the on-screen instructions. When you run it, the troubleshooter will automatically identify and fix the problem. After running the troubleshooter, open Outlook and see if the search is working properly. like

The solutions are: 1. Check whether the index value is correct: first confirm whether your index value exceeds the length range of the array. The index of the array starts from 0, so the maximum index value should be the array length minus 1; 2. Check the loop boundary conditions: If you use the index for array access in a loop, make sure the loop boundary conditions are correct; 3. Initialize the array: Before using an array, make sure that the array has been initialized correctly; 4. Use exception handling: You can use the exception handling mechanism in the program to catch errors where the index exceeds the bounds of the array, and handle it accordingly.

Tags define the divisions of an HTML document. This tag is primarily used to group similar content together for easy styling, and also serves as a container for HTML elements. We use CSS properties to place three section tags side by side in HTML. The CSS property float is used to achieve this purpose. Syntax Below is the syntax for the <div> tag. <divclass='division'>Content…</div>The Chinese translation of Example1 is: Example 1 The following is an example of using CSS properties to place three division classes side by side in HTML. <!DOCTYPEhtml><html><

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
