本文主要讲述了如何加速动态网站的MySQL索引分析和优化。
一、什么是索引?
索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都以B-树的形式保存。如果没有索引,执行查询时MySQL必须从第一个记录开始扫描整个表的所有记录,直至找到符合要求的记录。表里面的记录数量越多,这个操作的代价就越高。如果作为搜索条件的列上已经创建了索引,MySQL无需扫描任何记录即可迅速得到目标记录所在的位置。如果表有1000个记录,通过索引查找记录至少要比顺序扫描记录快100倍。
假设我们创建了一个名为people的表:
CREATE TABLE people ( peopleid SMALLINT NOT NULL,
name CHAR(50) NOT NULL );
然后,我们完全随机把1000个不同name值插入到people表。在数据文件中name列没有任何明确的次序。如果我们创建了name列的索引,MySQL将在索引中排序name列,对于索引中的每一项,MySQL在内部为它保存一个数据文件中实际记录所在位置的“指针”。因此,如果我们要查找name等于“Mike”记录的peopleid(SQL命令为“SELECT peopleid FROM people WHERE name=’Mike’;”),MySQL能够在name的索引中查找“Mike”值,然后直接转到数据文件中相应的行,准确地返回该行的peopleid(999)。在这个过程中,MySQL只需处理一个行就可以返回结果。如果没有“name”列的索引,MySQL要扫描数据文件中的所有记录,即1000个记录!显然,需要MySQL处理的记录数量越少,则它完成任务的速度就越快。
二、索引的类型
MySQL提供多种索引类型供选择:
普通索引 :
这是最基本的索引类型,而且它没有唯一性之类的限制。普通索引可以通过以下几种方式创建:
创建索引,例如CREATE INDEX <索引的名字> ON tablename (列的列表);
修改表,例如ALTER TABLE tablename ADD INDEX [索引的名字] (列的列表);
创建表的时候指定索引,例如CREATE TABLE tablename ( […], INDEX [索引的名字] (列的列表) );
唯一性索引:
这种索引和前面的“普通索引”基本相同,但有一个区别:索引列的所有值都只能出现一次,即必须唯一。唯一性索引可以用以下几种方式创建:
创建索引,例如CREATE UNIQUE INDEX <索引的名字> ON tablename (列的列表);
修改表,例如ALTER TABLE tablename ADD UNIQUE [索引的名字] (列的列表);
创建表的时候指定索引,例如CREATE TABLE tablename ( […], UNIQUE [索引的名字] (列的列表) );
主键 :
主键是一种唯一性索引,但它必须指定为“PRIMARY KEY”。如果你曾经用过AUTO_INCREMENT类型的列,你可能已经熟悉主键之类的概念了。主键一般在创建表的时候指定,例如“CREATE TABLE tablename ( […], PRIMARY KEY (列的列表) ); ”。但是,我们也可以通过修改表的方式加入主键,例如“ALTER TABLE tablename ADD PRIMARY KEY (列的列表); ”。每个表只能有一个主键。
全文索引:
MySQL从3.23.23版开始支持全文索引和全文检索。在MySQL中,全文索引的索引类型为FULLTEXT。全文索引可以在VARCHAR或者TEXT类型的列上创建。它可以通过CREATE TABLE命令创建,也可以通过ALTER TABLE或CREATE INDEX命令创建。对于大规模的数据集,通过ALTER TABLE(或者CREATE INDEX)命令创建全文索引要比把记录插入带有全文索引的空表更快。
波比源码 » 加速PHP动态网站 关于MySQL索引分析优化
purchase levaquin sale order levaquin 250mg sale
dutasteride price flomax brand order ondansetron
sildenafil 50mg usa cost aurogra 50mg estrace pill
buy tadalis 20mg order voltaren 100mg oral voltaren
buy anastrozole for sale buy generic viagra online uk viagra 100mg pills for sale
buy deltasone pills buy prednisone 20mg online cheap viagra online buy
terazosin 5mg over the counter order azulfidine generic azulfidine tablet
order benicar pills purchase acetazolamide sale order acetazolamide 250mg generic
buy imdur 40mg online cheap order lanoxin pills order generic micardis
molnunat online purchase lansoprazole for sale buy prevacid 30mg
cost tadalafil 20mg cialis coupons viagra price
tadalafil 10mg ca tadalafil pills order symmetrel 100 mg for sale
naltrexone 50 mg cheap order femara 2.5 mg for sale order generic aripiprazole 30mg
purchase medroxyprogesterone pill cost biltricide 600 mg order periactin generic
zithromax buy online purchase neurontin pills gabapentin 600mg price
aralen uk order baricitinib 4mg sale order baricitinib sale
buy sildenafil 50mg pill viagra online order purchase lisinopril
zyvox online order casino online usa gambling website
help writing essays buying essay sildenafil 25mg for sale
priligy 90mg drug synthroid price synthroid 150mcg pills
xenical tablet buy xenical generic acyclovir 800mg usa
cialis 20mg ca purchase inderal sale buy clopidogrel 75mg generic
cheap allopurinol order crestor online cheap zetia ca
buy methotrexate 2.5mg generic order warfarin 5mg generic buy reglan 20mg online
slot games online free online casinos live blackjack
buy generic tamsulosin 0.4mg generic aldactone order spironolactone 100mg online
cialis generic buy acillin for sale cheap ciprofloxacin 500mg
buy generic zocor proscar cheap order proscar 5mg pills
cefuroxime 500mg sale generic cefuroxime order robaxin 500mg for sale
buy trazodone online order desyrel without prescription order sildenafil online
deltasone 5mg cost accutane pills amoxil oral
sildenafil 50mg us order viagra generic tadalafil 20mg generic
casino online real money purchase stromectol online cheap modafinil 100mg without prescription
purchase furosemide online cheap order lasix 100mg for sale plaquenil drug
purchase prednisone generic buy generic prednisone 40mg order vermox 100mg generic
tiotropium bromide sale minocycline 50mg canada purchase terazosin generic
tadalafil 10mg oral free online poker games best casino
slot game free online blackjack no download casino game
ivermectin 0.5% lotion buy stromectol 12mg generic dapsone 100mg over the counter
empire casino online free spins no deposit usa cheap custom essays
mesalamine 400mg tablet generic mesalamine purchase avapro online cheap
benicar generic order generic olmesartan 10mg depakote drug
cost lanoxin lanoxin 250 mg pills order molnunat 200 mg generic
tricor online cheap viagra sale sildenafil overnight shipping usa
cialis 5mg without prescription viagra 50mg cost sildenafil 100mg
order minocin for sale minocycline 50mg without prescription order hytrin generic
provigil order generic provigil 200mg buy metoprolol online
prednisolone drug furosemide 40mg pill order furosemide for sale
order azathioprine for sale telmisartan 80mg usa naproxen 250mg pill
how to get levofloxacin without a prescription buy actigall 150mg zyban canada
cenforce 100mg brand buy chloroquine 250mg pills buy generic glucophage for sale
order atorvastatin 80mg for sale sildenafil 50mg pills for men order viagra 50mg without prescription
order letrozole 2.5 mg online cheap buy letrozole 2.5mg pills order viagra 50mg without prescription
buy cialis generic cialis next day delivery buy cheap generic ed pills
gabapentin without prescription furosemide 100mg without prescription doxycycline 200mg cheap
buy generic albuterol levothroid order cheap levothroid generic
order tadalafil 5mg for sale Free sildenafil samples buy sildenafil pills
estradiol drug lamictal 200mg ca prazosin buy online
generic fluconazole 200mg cheap acillin ciprofloxacin 500mg generic
oral mebendazole buy tretinoin pills for sale tadalis 10mg drug
order metronidazole 200mg sale brand keflex keflex 125mg generic
avana buy online order avanafil 100mg generic oral cambia
how to get cleocin without a prescription erythromycin pill buy sildenafil 50mg sale
purchase indocin online terbinafine 250mg uk cefixime for sale
trimox 500mg cost order clarithromycin 500mg sale clarithromycin 250mg generic
careprost generic how to get bimatoprost without a prescription order desyrel 100mg without prescription
order suhagra 50mg generic buy sildalis cheap buy cheap sildalis
buy cheap minocycline minocin 50mg for sale order actos 15mg generic
oral arava leflunomide tablet azulfidine without prescription
ivermectin 3mg for humans for sale prednisone 10mg for sale buy prednisone cheap
brand azithromycin azithromycin 500mg oral order neurontin 100mg
lasix 100mg pill monodox pill albuterol 2mg generic
order levitra 20mg pill buy hydroxychloroquine 200mg sale purchase plaquenil generic
buy generic acetazolamide for sale isosorbide 40mg cost generic imuran 50mg
oral priligy 30mg buy cytotec 200mcg generic order generic xenical 120mg
generic diltiazem 180mg diltiazem cost order allopurinol 300mg generic
order aristocort pill desloratadine usa claritin 10mg brand
ampicillin 250mg ca metronidazole 200mg drug metronidazole 400mg generic
buy toradol inderal where to buy propranolol tablet
order erythromycin online erythromycin 250mg us buy tamoxifen without prescription
metoclopramide 20mg ca buy cozaar 50mg online nexium pills
order topiramate 200mg generic cost levaquin 250mg buy cheap generic levofloxacin
celecoxib cost order tamsulosin 0.4mg sale buy cheap ondansetron
buy aurogra 100mg online cheap estrace 2mg pill purchase estradiol online cheap
order aldactone generic order zocor pill order valtrex 500mg for sale
order proscar 5mg online purchase proscar generic viagra oral
buy tadalafil 20mg pills oral cialis purchase viagra online
tadalafil 40mg oral buy ed pills best price buy ed meds online
order generic arimidex 1mg order biaxin 500mg online catapres 0.1mg canada
buy generic meclizine for sale meclizine where to buy buy minocycline generic
buy movfor tablets order generic naprosyn 500mg cefdinir 300mg price
order lansoprazole 30mg without prescription protonix 20mg brand order protonix online
buy generic avlosulfon over the counter dapsone order online perindopril 4mg without prescription
best erection pills tadalafil 5mg price tadalafil price
purchase fexofenadine online cheap buy altace cheap order glimepiride online
irbesartan 150mg cheap buy generic temovate over the counter order buspirone 10mg for sale
buy praziquantel 600mg for sale buy generic cyproheptadine cyproheptadine 4 mg sale
brand luvox purchase fluvoxamine for sale order cymbalta 20mg online cheap
glucotrol online order glipizide 5mg for sale buy betamethasone 20 gm without prescription
buy cheap tinidazole zyprexa 10mg ca cheap bystolic 20mg
decadron 0,5 mg cheap order zyvox order starlix online cheap
order captopril for sale atacand 16mg us carbamazepine 200mg without prescription
order generic zyban 150 mg buy zyban 150 mg sale strattera canada
ciplox 500 mg drug buy generic cefadroxil 500mg brand cefadroxil 500mg
epivir where to buy zidovudine order purchase quinapril online
frumil 5mg tablet buy cheap generic frumil acivir cheap
cheap zebeta 10mg buy indapamide without prescription buy generic terramycin 250mg