解析 沒有新增索引的案例導致查詢變慢

2021-09-10 13:23:01 字數 1510 閱讀 1075

完成某乙個功能的時候,測試環境沒有問題,但是發布到生產環境後,查詢很慢,差不多一分鐘。但是測試環境只需要不到5second。這個不正常

開始以為是程式太複雜,走讀**發現不是主要問題,

在product執行簡單的left查詢,也需要很久。這個不正常。

趕緊檢視表結構,是index沒有新增進去-------------大寫的坑

新增後問題解決

-- ***新增唯一索引

alter table *** add unique task_id (task_id);

alter table *** add index inspection_code (inspection_code);

-- ***新增索引

alter table *** add index taskasset (task_id,asset_code);

新增完成索引後,速度提起來了。

常用修改語句記錄:

alter table 語句用於在已有的表中新增、修改或刪除列

add [column] column name (column definitions) [first or after column_name]

add index [index_name] (column_list)

add primary key (column_list)

add unique [index_name] (column_list)

alter [column] column_name

change [column] old_col_name create_definition

drop [column] col_name

drop primary key

drop index index_name

modify [column] create_definition

rename [as] new_tbl_name

alter table employee add column account_number int

alter table employee add index (id)

alter table employee add primary key (id)

alter table employee add unique (id)

alter table employee change id salary int

alter table employee drop customer_id

alter table employee drop primary key

alter table employee drop index customer_id

alter table employee modify first_name varchar(100)

alter table employee rename customer

工作要細心

查詢沒有主鍵的表 沒有索引的表

1 查詢沒有主鍵的表 沒有索引的表 select so.name as 沒有主鍵的表 from sysobjects so where so.xtype u and objectproperty so.id tablehasprimarykey 0 order by name select so.n...

lucene索引的新增與查詢

public class indexfiles 使用方法 indexfiles 索引輸出目錄 索引的檔案列表 public static void main string args throws exception string indexpath args 0 indexwriter writer...

MySql 索引的新增,刪除,修改,查詢

索引主要分為六大類 唯一索引,單列索引,多列索引,普通索引,空間索引,全文索引。索引建立前面有必須有關鍵字 index 索引的新增有三種方式,一,在建立表的時候新增索引,在需要建立的表的時候新增index 再加上自己需要索引的欄位名 1,普通索引 create table a user id int...