ITPub博客

首页 > 数据库 > 数据库开发技术 > SQL优化 —— 读懂执行计划

SQL优化 —— 读懂执行计划

原创 数据库开发技术 作者:fiona8953 时间:2016-11-15 13:21:40 0 删除 编辑
Bucket and Batch
I saw that functions which use hash join, like as ExecHashGetBucketAndBatch and ExecScanHashBucket, have bucket and batch concepts.
So, I would like to know the differences between bucket and batch. I dont understand tables partitioning mechanism in hash join.
A bucket is, well, one bucket of a hash table --- it holds all the tuples that have the same hash code (for as many bits of the hash code as we are choosing to use).  We try to size the hash table with enough buckets so there's not more than 10 tuples per bucket on average.

A batch is a range of buckets that we process at the same time.  Tuples (from either side of the join) whose hash codes show they fall into batches other than the first one get dumped into temporary holding files, and then (after finishing joining the first batch) we pull each successive batch back into memory and join that portion of the tuples.
The batch size is chosen to make the amount of memory needed be approximately work_mem.

IOW, there are really nbuckets * nbatches "virtual" buckets in the hash table, but only nbuckets worth of them are kept in memory at any one time.
Note that we don't currently do batches for hash aggregates, only joins
currently.

show Heap Fetches in EXPLAIN for index-only scans


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26477398/viewspace-2128499/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: GPDB pg_log
请登录后发表评论 登录
全部评论

注册时间:2014-06-13

  • 博文量
    284
  • 访问量
    222487