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

Combined indexes

In my job, as a professional PostgreSQL support vendor, I am often asked about the difference between 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's 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 this. 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 indexed separately, you will most likely end up seeing bitmap scans. Of course, a single hand-tailored index is better.

主站蜘蛛池模板: 利川市| 陇川县| 清流县| 长汀县| 剑阁县| 新安县| 铁力市| 库尔勒市| 独山县| 新蔡县| 秦安县| 梓潼县| 曲阜市| 任丘市| 上蔡县| 锦屏县| 亳州市| 若尔盖县| 铜山县| 汉中市| 桐庐县| 普格县| 科尔| 峡江县| 蒙山县| 社旗县| 巴里| 桂阳县| 噶尔县| 囊谦县| 西贡区| 玛纳斯县| 星座| 锡林浩特市| 兖州市| 岳西县| 响水县| 秦皇岛市| 西城区| 称多县| 鹿泉市|