Mysql优化之延迟索引和分页优化_MySQL
什么是延迟索引?使用索引查询出来数据,之后把查询结果和同一张表中数据进行连接查询,进而提高查询速度!
分页是一个很常见功能,select ** from tableName limit ($page - 1 ) * $n ,$n
通过一个存储过程插入10000条数据进行测试:
create table smth1 ( id int auto_increment , ver int(11) default null, content varchar(1000) not null, intro varchar(1000) not null, primary key(id), key idver(id,ver) )engine = innodb default charset = utf8; create procedure smthTest1() begin declare num int default 100001; while num < 1000000 do set num := num +1; insert into smth1 values (num ,num,'我是*****','我是谁'); end while ; end;
查询:
mysql> show profiles; +----------+------------+----------------------------------------------+ | Query_ID | Duration | Query | +----------+------------+----------------------------------------------+ | 1 | 0.002006 | select id ,content from smth1 limit 1000,10 | | 2 | 0.030106 | select id ,content from smth1 limit 5000,10 | | 3 | 0.042428 | select id ,content from smth1 limit 9000,10 | | 4 | 0.01297225 | select id ,content from smth1 limit 10000,10 | | 5 | 0.13077625 | select id ,content from smth1 limit 20000,10 |
怎样避免这种情况?
一般我们数据库里面数据都不会直接删除,数据时很宝贵的,不舍得删除,另一方便能提高查询数据
先利用索引查询出来数据,再进行联合查询不就行了
select C.id,C.content from smth1 C inner join ( select id from smth1 where id > 1000 limit 10 ) as t on C.id = t.id ; select C.id,C.content from smth1 C inner join ( select id from smth1 where id > 5000 limit 10 ) as t on C.id = t.id ; select C.id,C.content from smth1 C inner join ( select id from smth1 where id > 9000 limit 10 ) as t on C.id = t.id ; select C.id,C.content from smth1 C inner join ( select id from smth1 where id > 10000 limit 10 ) as t on C.id = t.id ; select C.id,C.content from smth1 C inner join ( select id from smth1 where id > 20000 limit 10 ) as t on C.id = t.id ; 进行执行计划分析,没有一个大于1s的 11 | 0.04538625 | select C.id,C.content from smth1 C inner join ( select id from smth1 where id > 5000 limit 10 ) as t on C.id = t.id | | 12 | 0.023278 | select C.id,C.content from smth1 C inner join ( select id from smth1 where id > 9000 limit 10 ) as t on C.id = t.id | | 13 | 0.02320425 | select C.id,C.content from smth1 C inner join ( select id from smth1 where id > 10000 limit 10 ) as t on C.id = t.id | | 14 | 0.001938 | select C.id,C.content from smth1 C inner join ( select id from smth1 where id > 20000 limit 10 ) as t on C.id = t.id |

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

如何在Window11上修復100%的磁碟使用率查找導致100%磁碟使用的有問題的應用程式或服務的直接方法是使用任務管理器。若要開啟任務管理器,請右鍵點選開始功能表並選擇任務管理器。按一下磁碟列標題,查看佔用最多資源的內容。從那裡開始,您將很好地了解從哪裡開始。但是,問題可能比僅僅關閉應用程式或停用服務更嚴重。繼續閱讀以查找問題的更多潛在原因以及如何解決這些問題。停用SuperfetchSuperfetch功能(在Windows11中也稱為SysMain)有助於透過存取預取檔案來減少啟動時

如果您的搜尋欄在Windows11中不起作用,有幾種快速方法可以立即啟動並運行!任何微軟作業系統有時都可能遇到故障,最新的作業系統不能免除該規則。此外,正如Reddit上的使用者u/zebra_head1所指出的那樣,同樣的錯誤出現在Windows11的22H2Build22621.1413上。用戶抱怨切換工作列搜尋框的選項隨機消失。因此,您必須為任何情況做好準備。為什麼我無法在電腦上的搜尋欄中鍵入內容?無法在計算機上鍵入可歸因於不同的因素和過程。以下是您應該注意的一些事項:Ctfmon.

<h2>如何在Windows11上從搜尋中隱藏檔案和資料夾</h2><p>我們首先要看的是自訂Windows搜尋檔案的位置。透過跳過這些特定位置,您應該可以更快地看到結果,同時還可以隱藏您想要保護的任何檔案。 </p><p>如果要從Windows11上的搜尋排除檔案和資料夾,請使用下列步驟:</p><ol&

oracle索引類型有:1、B-Tree索引;2、位圖索引;3、函數索引;4、雜湊索引;5、反向鍵索引;6、局部索引;7、全域索引;8、網域索引;9、位圖連接索引;10、複合索引。詳細介紹:1、B-Tree索引,是一種自平衡的、可以有效率地支援並發操作的樹狀資料結構,在Oracle資料庫中,B-Tree索引是最常用的一種索引類型;2、位圖索引,是一種基於點陣圖演算法的索引類型等等。

在Outlook中執行搜尋和索引疑難排解您可以開始的更直接的修復之一是執行搜尋和索引疑難排解。若要在Windows11上執行疑難排解,請執行下列操作:按一下開始按鈕或按Windows鍵並從功能表中選擇設定。當設定開啟時,選擇系統>疑難排解>其他疑難排解。在右側向下捲動,找到SearchandIndexing,然後按一下Run按鈕。選擇Outlook搜尋不傳回結果並繼續畫面上的說明。當您運行它時,疑難排解程式將自動識別並修復問題。執行疑難排解後,開啟Outlook並查看搜尋是否正常。如

這篇文章將為大家詳細講解有關PHP返回一個字符串在另一個字符串中開始位置到結束位置的字符串,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章後可以有所收穫。 PHP中使用substr()函數從字串中擷取子字串substr()函數可從字串中擷取指定範圍內的字元。其語法如下:substr(string,start,length)其中:string:要從中提取子字串的原始字串。 start:子字串開始位置的索引(從0開始)。 length(可選):子字串的長度。如果未指定,則提

解決方法有:1、檢查索引值是否正確:先確認你的索引值是否超出了陣列的長度範圍。數組的索引從0開始,所以最大索引值應該是數組長度減1;2、檢查循環邊界條件:如果是在循環中使用索引進行數組訪問,要確保循環的邊界條件正確;3、初始化數組:在在使用陣列之前,請確保陣列已經正確初始化;4、使用異常處理:在程式中可以使用異常處理機制來捕捉索引超出陣列界限的錯誤,並進行相應的處理。

如何透過索引提升PHP與MySQL的資料分組與資料聚合的效率?引言:PHP和MySQL是目前應用最廣泛的程式語言和資料庫管理系統,常被用來建構web應用程式和處理大量資料。在處理大量資料時,資料分組和資料聚合是常見的操作,但如果不合理地設計和使用索引,這些操作可能會變得非常低效。本文將介紹如何透過索引來提升PHP與MySQL的資料分組與資料聚合的效率,並提
