官术网_书友最值得收藏!

Combined indexes

In my job as a professional PostgreSQL support vendor, I am often asked about the difference between a combined and individual indexes. In this section, I will try to shed some light on this question.

The general rule is this: if a single index can answer your question, it is usually the best choice. However, you cannot index all possible combinations of fields people are filtering on. What you can do is use the properties of combined indexes to achieve as much gain as possible.

Let us suppose we have a table containing three columns: postal_code, last_name, and first_name. A telephone book would make use of a combined index like that. You will see that data is ordered by location. Within the same location, data will be sorted by last name and first name.

The following table will show which operations are possible given the three column index:

If columns are indexes separately, you will most likely end up seeing bitmap scans. Of course, a single hand-tailored index is better.

主站蜘蛛池模板: 长岭县| 彭山县| 中西区| 武义县| 盐城市| 松溪县| 舒城县| 太和县| 西林县| 凤山县| 永吉县| 天长市| 邵东县| 介休市| 宜宾县| 霸州市| 岳阳县| 荆门市| 海城市| 德阳市| 左云县| 易门县| 阳曲县| 青田县| 泸州市| 班玛县| 公主岭市| 西宁市| 衡水市| 西乌珠穆沁旗| 三穗县| 石嘴山市| 沙雅县| 青海省| 额尔古纳市| 桐柏县| 甘孜县| 瑞丽市| 安图县| 阿克陶县| 交城县|