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

Using bitmap scans effectively

The question naturally arising now is: when is a bitmap scan most beneficial and when is it chosen by the optimizer? From my point of view, there are really two use cases:

  • Avoiding using the same block over and over again
  • Combining relatively bad conditions

The first case it quite common. Suppose you are looking for everybody who speaks a certain language. For the sake of the example, we can assume that 10% of all people speak the required language. Scanning the index would mean that a block in the table has to be scanned all over again as many skilled speakers might be stored in the same block. By applying a bitmap scan, it is ensured that a specific block is only used once, which of course leads to better performance.

The second common use case is to use relatively weak criteria together. Let's suppose we are looking for everybody between 20 and 30 years of age owning a yellow shirt. Now, maybe 15% of all people are between 20 and 30 and maybe 15% of all people actually own a yellow shirt. Scanning a table sequentially is expensive, and so PostgreSQL might decide to choose two indexes because the final result might consist of just 1% of the data. Scanning both indexes might be cheaper than reading all of the data.

主站蜘蛛池模板: 德江县| 天祝| 营口市| 富裕县| 东丰县| 常德市| 临猗县| 深州市| 宿迁市| 白山市| 桓仁| 白银市| 张家口市| 商丘市| 安化县| 梁山县| 辽源市| 盖州市| 台南县| 青海省| 本溪| 元朗区| 金沙县| 万荣县| 雷波县| 临沂市| 彩票| 太湖县| 淳化县| 上栗县| 玉溪市| 永和县| 汪清县| 西平县| 弥渡县| 龙里县| 博乐市| 泰兴市| 镇平县| 桂东县| 永福县|