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

  • Mastering PostgreSQL 9.6
  • Hans Jurgen Schonig
  • 227字
  • 2021-07-09 19:57:16

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.

主站蜘蛛池模板: 吉林市| 永嘉县| 宜昌市| 林州市| 泗水县| 峡江县| 绥宁县| 浦东新区| 黑河市| 沧州市| 临夏市| 奉贤区| 墨玉县| 临清市| 新竹市| 鲁山县| 姚安县| 梁山县| 若尔盖县| 边坝县| 黄山市| 兴义市| 工布江达县| 松潘县| 临漳县| 乐安县| 武乡县| 彭泽县| 常宁市| 罗甸县| 靖远县| 长泰县| 博兴县| 天台县| 蓝田县| 乡城县| 盐源县| 陆良县| 财经| 东丽区| 客服|