优化一句SQL语句!该怎么解决
优化一句SQL语句!
- SQL code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->select a.id,b.id as mycompid,b.typeid,b.co_end,a.pro_price,a.pro_name as realproname,a.discount_rate,a.bigpic,a.temp_url,b.co_name,c.pro_name,d.city_name,a.begindate,a.modifydate,a.pro_intro from product a left join company b on(a.userid=b.id) left join pro c on(b.proid=c.id) left join city d on(b.cityid=d.id) left join protype e on(a.typeid=e.id) where (a.pro_name like binary '%%' or a.pro_intro like binary '%%' or a.keywords like binary '%%') and co_type=112 and b.islock=0 and a.isdel=0 and a.comp_state=1 and b.islock=0 order by b.realtypeid desc,a.modifydate desc limit 0,20
给大家简单解释下这句,就是搜索产品列表显示页 product产品表记录6万 company是企业表 记录4万 pro是省份信息,city是城市信息,protype是产品分类信息,
主要是想搜索结果是以企业的等级排序,如果是同等级的就按产品的发布时间排序,所以就写了这么个SQL语句,不过效率真的很低,估计要6秒执行时间
我测试了下,主要原因就出在排序 order by b.realtypeid desc,a.modifydate desc 这上面
可是这个排序又必须要排,请大家帮我出出点子吧,应该怎么办!~
------解决方案--------------------
路过学习 望高手指点
------解决方案--------------------
我看一下
------解决方案--------------------
数据量比较大的时候,建议分批来取数据
试试这个会不会快一些
select a.id,b.id as mycompid,b.typeid,b.co_end,a.pro_price, a.pro_name as realproname,a.discount_rate,a.bigpic,a.temp_url,b.co_name, c.pro_name,d.city_name,a.begindate,a.modifydate,a.pro_intro from product a,company b,protype e
left join pro c on(b.proid=c.id)
left join city d on(b.cityid=d.id)
where a.userid=b.id and a.typeid=e.id and (a.pro_name like binary '%%' or a.pro_intro like binary '%%' or a.keywords like binary '%%') and co_type=112 and b.islock=0 and a.isdel=0 and a.comp_state=1 and b.islock=0 order by b.realtypeid desc,a.modifydate desc limit 0,20
------解决方案--------------------
b.realtypeid,a.modifydate给它们两列建立索引..
------解决方案--------------------
建议用视图!
------解决方案--------------------
如果数据太大,分步取然后用PHP处理还不不错的,在不行explain一下吧,
------解决方案--------------------
分段索引在排序吧 排序是很慢
------解决方案--------------------
你问题是出在left join上把
这么多大量数据的表进行连续left join 太大啊。。。
------解决方案--------------------
可以试试把条件常用的字段加上索引
------解决方案--------------------
(a.pro_name like binary '%%' or a.pro_intro like binary '%%' or a.keywords like binary '%%')
这个啥意思??

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

iPhone 15 Pro vs. iPhone 14 Pro: Specs Comparison Here is a spec comparison between iPhone 15 Pro Max and iPhone 14 Pro Max: iPhone 15 Pro Max iPhone 14 Pro Max Display size 6.7 inches 6.7 inches Display technology Super Retina 2,000 nits Dimensions 6.29x3.02x0.32 inches 6.33x3.06x0.31 inches Weight 221 grams 240 grams

Many users don’t know how to turn on the Xiaomi Mi Band 8 when they first come into contact with it. In fact, the method is very simple. We only need to find the USB data cable and connect the watch to the power supply, and then charge it for a while. You can press the button to turn on. How to turn on Xiaomi Mi Band 8pro 1. First install the watch, that is, connect the theme and the strap on both sides. 2. Then when we turn on the watch for the first time, we need to connect the charging cable. The connection method is at the bottom of the watch. 3. Wait for the watch to vibrate to power on, and then connect to your phone. >>>

Many users are not sure which one is worth buying, Xiaomi Mi Pad 6 or Mi Pad 6. From the configuration point of view, the higher configuration of Pro is definitely recommended, but it also depends on the price and their own budget, and the different product positioning groups are also different. Which one is worth buying, Xiaomi Mi Pad 6 or Pro? Answer: Xiaomi Mi Pad 6 Pro will be better, both in terms of performance and camera battery life. 1. Processor Xiaomi Pad 6: Snapdragon 870 Xiaomi Mi Pad 6 Pro: more powerful first-generation Snapdragon 8+ processor 2. Battery size Xiaomi Mi Pad 6: 8840mAh, 67W second charge Xiaomi Mi Pad 6 Pro: 8600mAh, 33W The fast-charging Xiaomi Mi Pad 6 will have better battery life, but charging will be slower. 3. Take photos with Xiaomi Mi Pad 6

Xiaomi pro14 is already on the market, and its configuration is very good for a business office notebook. There are three processor configurations to choose from, and the price is not particularly high. Many friends don’t know the specific launch time of Xiaomi Pro14. Xiaomi Pro14 launch time A: Xiaomi Pro14 Ryzen Edition will be available for pre-order on November 10, 2021, with an initial price starting from 5,299 yuan. Xiaomi Notebook Pro 14 will be released on July 4, 2022, and will officially go on sale at midnight on July 8. Xiaomi pro14 introduction 1. The screen is equipped with a 14-inch 2.5K Super Retina screen with a resolution of 2560x1600, a screen-to-body ratio of up to 88%, a 100% sRGB color gamut, and a refresh rate of 120Hz. 2. Appearance adopts 6 series

Have you installed cameras in your home? In recent years, home camera products have suddenly become a hit. I asked my friends around me, and boy, every house has one, and some even have more than one. However, with the popularity of the product, it has also brought some complaints during use. For example, you can only see one place at the same time, and if you want to see other places, you have to adjust the pan/tilt and rotate the camera back and forth. There is a certain blind spot and time difference when viewing the picture; or when you want to take a closer look at a certain location in your home, you find that the picture is blurry and you cannot see it at all. Clarity; etc... The experience is greatly compromised. Honor Select and Xiaopai Technology jointly launched the Honor Select Xiaopai Smart Camera Pro featuring "three lenses and dual images". Provides new solutions to industry and user pain points

MacBook Air is an Apple laptop. Many users are curious about the differences between MacBook Air and Pro. These two notebooks have some differences in processor core, main frequency and graphics card type. The differences between MacBook Air and Pro: 1. Different processor cores and threads: MacBook Air's processor has dual cores and four threads. The Pro is more powerful than the MacBook Air, with four cores and eight threads. 2. The main frequency of the processor is different: the processor of MacBook Air has a main frequency of 1.6GHz. The main frequency of the pro's processor is 1.4GHz, which is slightly lower than that of the macbook air. 3. Different graphics cards: macbookair adopts

Apple continues to push the boundaries of technology, and the latest proof of its innovation is the launch of the Apple A17 Pro GPU. This cutting-edge component features a completely redesigned GPU that promises significant improvements in performance, graphics, and user experience. The Apple A17 Pro GPU, launched alongside the iPhone 15 Pro, is a marvel of semiconductor engineering. It's manufactured using a 3nm process, which represents a major leap in miniaturization, packing more transistors into a single chip than ever before. This technical feat translates into greater power efficiency and computing power. Apple A17 Pro GPU delivers stunning graphics One of the standout features of the A17 Pro chip is its redesigned GPU. Apple has invested heavily in optimizing graphics performance, making it

Although Apple will launch the iPhone's video playback time to let users know that the iPhone battery is almost available. But normal users don't use their iPhone to view videos all day long. 7 iPhones tested for endurance in daily applications. Includes 7 models including iPhone15ProMax, iPhone15Pro, iPhone15Plus, iPhone15, iPhone14ProMax, iPhone14 and iPhone13ProMax. Running through some daily applications, such as Spotify, Zoom, Tiktok, Headspace, think about Apps, games, etc., we can see the battery life of different iPhones. this
