搜索
首页后端开发php教程 PHP 面试题 Mysql 目录

PHP 面试题 Mysql 索引
题目:
PRODUCT表(id,name,price,count)

SQL code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->select * from PRODUCT where price=100

目前已经在price字段上加上了索引
1.不过以上查询速度还是很慢,请试说出慢的原因
2.请问如何优化才能加快速度


------解决方案--------------------
1、数据量大 加上limit 一定数量的限制
2、字段可以写出只要需要的字段 seletc id, name 等
3、主键和price一起做一个联合索引

剩下的楼下补充
------解决方案--------------------
select * from PRODUCT where price=100

就这些?加了索引还很慢的话就没道理了。索引就是非遍历查询,直接定位到price为100的地方!数据量大的话,查询上肯定要比不加要快很多!

难道你的数据库里有很多个price为100的数据?
------解决方案--------------------
探讨

select * from PRODUCT where price=100

就这些?加了索引还很慢的话就没道理了。索引就是非遍历查询,直接定位到price为100的地方!数据量大的话,查询上肯定要比不加要快很多!

难道你的数据库里有很多个price为100的数据?

------解决方案--------------------
也许price字段根本就不适合加索引,并不是所有字段都能加索引,有些加了反而更慢!
------解决方案--------------------
price中重复数据太多导致查询效率下降的可能 最大。

------解决方案--------------------
单就这个查询而言,

慢是因为它不是唯一索引;



如果数据量大,基本上没有太好办法优化! 或者可以给价格加一个区间联合索引,这样可以选查区间,后后再查100
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
Fujifilm X-M5 price expectations rise as leaked selfie display adds complexity to the formerly affordable camera lineFujifilm X-M5 price expectations rise as leaked selfie display adds complexity to the formerly affordable camera lineSep 07, 2024 am 09:34 AM

Fujifilm fans were recently very excited at the prospect of the X-T50, since it presented a relaunch of the budget-oriented Fujifilm X-T30 II that had become quite popular in the sub-$1,000 APS-C category. Unfortunately, as the Fujifilm X-T50's launc

FiiO CP13 cassette player launches with transparent retro lookFiiO CP13 cassette player launches with transparent retro lookJun 16, 2024 am 09:52 AM

TheFiiOCP13cassetteplayerwasannouncedinJanuary.Now,FiiOisexpandingitsportfoliowithtwonewmodels-onewitharedfrontandonewithatransparentfront.Thelatternotonlyperfectlymatchestheretrocharmoftheangulardesign,butalso

Klipsch unveils Flexus Core 300 flagship soundbar with 8K support, 12 speakers and room correctionKlipsch unveils Flexus Core 300 flagship soundbar with 8K support, 12 speakers and room correctionSep 05, 2024 am 10:16 AM

The Klipsch Flexus Core 300 is the top model in the series and is positioned above the already available Flexus Core 200 in the company's soundbar line-up. According to Klipsch, this is the first soundbar in the world whose sound can be adapted to th

Light Phone 3 launches with 50% discount, monochrome OLED and minimalist designLight Phone 3 launches with 50% discount, monochrome OLED and minimalist designJun 13, 2024 pm 10:18 PM

WhiletheLightPhone2from2018wasstillequippedwithaneconomicale-inkdisplay,theLightPhone3usesanOLEDdisplaythatcanonlydisplaygrayscale.Thereasonfortheswitchtothe3.92-inchOLEDpanelwithitsresolutionof1,240x1,080isth

jquery如何隐藏select元素jquery如何隐藏select元素Aug 15, 2023 pm 01:56 PM

jquery隐藏select元素的方法:1、hide()方法,在HTML页面中引入jQuery库,可以使用不同选择器来隐藏select元素,ID选择器将selectId替换为你实际使用的select元素的ID;2、css()方法,使用ID选择器选择需要隐藏的select元素,使用css()方法将display属性设置为none,并将selectId替换为select元素的ID。

Deal | Tesla Model 3 Long Range AWD regains full $7,500 tax incentive, drops to below $40,000Deal | Tesla Model 3 Long Range AWD regains full $7,500 tax incentive, drops to below $40,000Jun 19, 2024 am 09:55 AM

Shortly after Tesla launched the Model 3 Highland refresh towards the end of last year, the US federal EV tax incentive rules changed, cutting the potential discount in half for eligible buyers because of Tesla's use of Chinese LFP cells in the new M

linux要用select的原因是什么linux要用select的原因是什么May 19, 2023 pm 03:07 PM

因为select可以使开发者在同时等待多个文件缓冲区,可减少IO等待的时间,能够提高进程的IO效率。select()函数是IO多路复用的函数,允许程序监视多个文件描述符,等待所监视的一个或者多个文件描述符变为“准备好”的状态;所谓的”准备好“状态是指:文件描述符不再是阻塞状态,可以用于某类IO操作了,包括可读,可写,发生异常三种。select是一个计算机函数,位于头文件#include。该函数用于监视文件描述符的变化情况——读写或是异常。1.select函数介绍select函数是IO多路复用的函

Realme Pad 2 Lite: Affordable tablet launches with quad speakers, 90 Hz display and 15h battery lifeRealme Pad 2 Lite: Affordable tablet launches with quad speakers, 90 Hz display and 15h battery lifeSep 14, 2024 am 06:28 AM

More than a year after the launch of the Realme Pad 2 the manufacturer presents the more affordable Realme Pad 2 Lite. The new model is slightly smaller, as the display shrinks from 11.5 inches to 10.95 inches, with the IPS panel achieving a resoluti

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前By尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前By尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具