亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

postgresql 9.6 建立多列索引測試

發布時間:2020-07-19 12:00:14 來源:網絡 閱讀:2418 作者:pgmia 欄目:數據庫

建立測試表結構

CREATE TABLE t_test

(

    id integer,

    name text COLLATE pg_catalog."default",

    address character varying(500) COLLATE pg_catalog."default"

);


插入測試數據

insert into t_test SELECT generate_series(1,10000000) as key, 'name'||(random()*(10^3))::integer, 'ChangAn Street NO'||(random()*(10^3))::integer;


建立3列索引

create index idx_t_test_id_name_address on t_test(id,name,address);


1.以下查詢語句可以使用索引且較快

索引第一列在where語句,與條件次序無關

一般3毫秒多出結果

explain analyze select * from t_test where id < 2000 and name like 'name%' and address like 'ChangAn%';

explain analyze select * from t_test where address like 'ChangAn%' and name like 'name%' and id < 2000 ;

explain analyze select * from t_test where name like 'name%' and id < 2000 and address like 'ChangAn%'  ;

explain analyze select * from t_test where id < 2000

explain analyze select * from t_test where  name like 'name%' and id < 2000 

explain analyze select * from t_test where  address like 'ChangAn%' and id < 2000 ;

explain analyze select * from t_test where address like 'ChangAn%' and name like 'name%' and id < 2000 ;


2.以下可以使用索引,但是查詢速度較慢

索引第一列在order by 

explain analyze select * from t_test where address like 'ChangAn%' and name like 'name%' order by id;

17S

explain analyze select * from t_test where address like 'ChangAn%' order by id;

8s

explain analyze select * from t_test where name like 'name%' order by id;

9s


以下語句無法使用索引,索引第一列不在 where 或者 order by


explain analyze select * from t_test where address like 'ChangAn%' and name like 'name%';

explain analyze select * from t_test where address like 'ChangAn%';

explain analyze select * from t_test where name like 'name%';


建立雙列索引

create index idx_t_test_name_address on t_test(name,address);

以下語句會使用索引

explain analyze select * from t_test where name = 'name580';

explain analyze select * from t_test where address like 'ChangAn%' and name like 'name580'; 

explain analyze select * from t_test where address like 'ChangAn%' and name = 'name580';


下面語句不會使用索引


explain analyze select * from t_test where name  like 'name%'

explain analyze select * from t_test where address like 'ChangAn%'

explain analyze select * from t_test where address = 'ChangAn Street NO416'


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

新乡县| 静乐县| 同德县| 西昌市| 中宁县| 灵山县| 上饶市| 乌恰县| 登封市| 曲沃县| 嘉鱼县| 论坛| 泰安市| 财经| 东海县| 名山县| 荔波县| 宜阳县| 万盛区| 广安市| 邵阳县| 子洲县| 仲巴县| 彭山县| 宣威市| 岳阳县| 建宁县| 凤城市| 本溪市| 山阳县| 巧家县| 耒阳市| 若羌县| 九江市| 柏乡县| 礼泉县| 开鲁县| 临澧县| 宜兰市| 苏尼特左旗| 东兴市|