MySQL学习笔记6:索引_MySQL
bitsCN.com
索引是创建在表上的,对数据库表中一列或多列的值进行排序的一种结构
其作用主要在于提高查询的速度,降低数据库系统的性能开销
通过索引,查询数据不必读完记录的全部信息进行匹配,而是只查询索引列
索引相当于字典中的音序表,要查询某字时可以在音序表中找到
然后直接跳转到那一音序所在位置,而不必从字典第一页开始翻,逐字匹配
tips:索引虽能提高查询速度,但在插入记录时会按照索引进行排序,因此降低了插入速度
最好的操作方式是先删除索引,插入大量记录后再创建索引
索引分类
1.普通索引:不附加任何限制条件,可创建在任何数据类型中
2.唯一性索引:使用unique参数可以设置索引为唯一性索引,在创建索引时,限制该索引的值必须唯一,主键就是一种唯一性索引
3.全文索引:使用fulltext参数可以设置索引为全文索引。全文索引只能创建在char、varchar或text类型的字段上。查询数据量较大的字符串类型字段时,效果明显。但只有MyISAM存储引擎支持全文检索
4.单列索引:在表中单个字段上创建的索引,单列索引可以是任何类型,只要保证索引只对应一个一个字段
5.多列索引:在表中多个字段上创建的索引,该索引指向创建时对应的多个字段
6.空间索引:使用spatial参数可以设置索引为空间索引,空间索引只能建立在空间数据类型上比如geometry,并且不能为空,目前只有MyISAM存储引擎支持
在创建表时创建索引
创建普通索引
1 |
|
此处在id字段上创建索引,show create table可查看
创建唯一性索引
1 |
|
此处使用id字段创建了一个名为index2_id的索引
这里的id字段可以不设置唯一性约束,但这样一来索引就没有作用
创建全文索引
1 |
|
要注意创建全文索引时只能使用MyISAM存储引擎
创建单列索引
1 |
|
此处subject字段长度是30,而索引长度则是10
这么做的目的在于提高查询速度,对于字符型的数据不用查询全部信息
创建多列索引
1 |
|
可以看出,这里使用了name字段和sex字段创建索引列
创建空间索引
1 |
|
这里需要注意空间space字段不能为空,还有存储引擎
在已经存在的表上创建索引
创建普通索引
1 |
|
这里在现有表的id字段上创建了一条名为index7_id的索引
创建唯一性索引
1 |
|
此处只需要在index关键字前面加上unique即可
至于表中的course_id字段,最要也设置唯一性约束条件
创建全文索引
1 |
|
fulltext关键字用来设置全文引擎,此处的表必须是MyISAM存储引擎
创建单列索引
1 |
|
此表中address字段的长度是20,这里只查询4字节,不需要全部查询
创建多列索引
1 |
|
索引创建好之后,查询中必须有name字段才能使用
创建空间索引
1 |
|
这里需要注意存储引擎是MyISAM,还有空间数据类型
用alter table语句来创建索引
创建普通索引
1 |
|
创建唯一性索引
1 |
|
创建全文索引
1 |
|
创建单列索引
1 |
|
创建多列索引
1 |
|
创建空间索引
1 |
|
到此,三种操作方式,每种索引类别的建立就都列举了
对于索引,重要的是理解索引的概念,明白索引的种类
更多的是自己的使用经验
最后来看看索引的删除
删除索引
1 |
|
这里是刚刚创建的一条索引
其中index18_space是索引名,example11是表名
bitsCN.com

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



Microsoft Word documents contain some metadata when saved. These details are used for identification on the document, such as when it was created, who the author was, date modified, etc. It also has other information such as number of characters, number of words, number of paragraphs, and more. If you might want to remove the author or last modified information or any other information so that other people don't know the values, then there is a way. In this article, let’s see how to remove a document’s author and last modified information. Remove author and last modified information from Microsoft Word document Step 1 – Go to

Pinduoduo software provides a lot of good products, you can buy them anytime and anywhere, and the quality of each product is strictly controlled, every product is genuine, and there are many preferential shopping discounts, allowing everyone to shop online Simply can not stop. Enter your mobile phone number to log in online, add multiple delivery addresses and contact information online, and check the latest logistics trends at any time. Product sections of different categories are open, search and swipe up and down to purchase and place orders, and experience convenience without leaving home. With the online shopping service, you can also view all purchase records, including the goods you have purchased, and receive dozens of shopping red envelopes and coupons for free. Now the editor has provided Pinduoduo users with a detailed online way to view purchased product records. method. 1. Open your phone and click on the Pinduoduo icon.

How to View Command History in Linux In Linux, we use the history command to view the list of all previously executed commands. It has a very simple syntax: history Some options for pairing with the history command include: Option description -c clears the command history for the current session -w writes the command history to a file -r reloads the command history from the history file -n Limit the number of output of recent commands Simply run the history command to see a list of all previously executed commands in a Linux terminal: In addition to viewing command history, you can also manage command history and perform modifications to previously executed commands , reverse search command history or even delete history completely

Call recording in iPhone is often underestimated and is one of the most critical features of iPhone. With its simplicity, this feature is of vital importance and can provide important insights about the calls made or received on the device. Whether for work purposes or legal proceedings, the ability to access call records can prove invaluable. In simple terms, call history refers to the entries created on your iPhone whenever you make or receive a call. These logs contain key information, including the contact's name (or number if not saved as a contact), timestamp, duration, and call status (dialed, missed, or not answered). They are a concise record of your communication history. Call history includes call history strips stored on your iPhone

Using System Information Click Start and enter System Information. Just click on the program as shown in the image below. Here you can find most of the system information, and one thing you can find is graphics card information. In the System Information program, expand Components, and then click Show. Let the program gather all the necessary information and once it's ready, you can find the graphics card-specific name and other information on your system. Even if you have multiple graphics cards, you can find most content related to dedicated and integrated graphics cards connected to your computer from here. Using the Device Manager Windows 11 Just like most other versions of Windows, you can also find the graphics card on your computer from the Device Manager. Click Start and then

iPhone lets you add medications to the Health app to track and manage the medications, vitamins and supplements you take every day. You can then log medications you've taken or skipped when you receive a notification on your device. After you log your medications, you can see how often you took or skipped them to help you track your health. In this post, we will guide you to view the log history of selected medications in the Health app on iPhone. A short guide on how to view your medication log history in the Health App: Go to the Health App>Browse>Medications>Medications>Select a Medication>Options&a

In iOS 17, there's a new AirDrop feature that lets you exchange contact information with someone by touching two iPhones. It's called NameDrop, and here's how it works. Instead of entering a new person's number to call or text them, NameDrop allows you to simply place your iPhone near their iPhone to exchange contact details so they have your number. Putting the two devices together will automatically pop up the contact sharing interface. Clicking on the pop-up will display a person's contact information and their contact poster (you can customize and edit your own photos, also a new feature of iOS17). This screen also includes the option to "Receive Only" or share your own contact information in response.

Current image 3D reconstruction work usually uses a multi-view stereo reconstruction method (Multi-view Stereo) that captures the target scene from multiple viewpoints (multi-view) under constant natural lighting conditions. However, these methods usually assume Lambertian surfaces and have difficulty recovering high-frequency details. Another approach to scene reconstruction is to utilize images captured from a fixed viewpoint but with different point lights. Photometric Stereo methods, for example, take this setup and use its shading information to reconstruct the surface details of non-Lambertian objects. However, existing single-view methods usually use normal map or depth map to represent the visible
