【SequoiaDB巨杉数据库】SORT推演公式

该博客深入解析了数据库查询中的SORT操作,详细介绍了SORT的输入记录数、排序字段、记录总大小、页面计算、排序类型、IO及CPU成本估算、启动和运行代价等关键概念,并通过示例展示了如何进行代价计算。内容对于理解数据库性能优化至关重要。
摘要由CSDN通过智能技术生成

SORT 的推演公式将展示以下信息:

字段名类型描述
Records长整型估算的 SORT 输入的记录个数
SortFields整型SORT 进行排序的字段个数
RecordTotalSize长整型估算的 SORT 输入的记录总大小
公式为:Records * RecordSize
Pages整型估算的 SORT 输入的记录页数(输入记录个数的总大小存放入 4K 页面中的页数)
公式为:max( 1, ceil( RecordTotalSize / PageUnit) )
SortType字符串SORT 估算的排序类型
RecordTotalSize 小于 sortbuff 时,"InMemory" 为内存排序
RecordTotalSize 大于 sortbuff 时,"External" 为外存排序
IOCost数组估算的 SORT 的 IO 代价的公式及计算过程
SortType 为 "InMemory" 时不需要计算
各个数据页需要写出磁盘,并进行归并排序,假设归并排序中 75% 为顺序读,25% 为随机读
公式为:ceil( Pages * ( SeqWrtIOCostUnit + SeqReadIOCostUnit * 0.75 + RandomReadIOCostUnit * 0.25 ) )
CPUCost数组估算的 SORT 的 CPU 代价的公式及计算过程
即各个记录进行排序的代价
公式为:ceil( 2 * OptrCPUCost * SortFields * max( 2, Records ) * log2( max( 2, Records ) ) )
StartCost数组估算的 SORT 的启动代价
需要计算子操作的总代价和排序的代价
公式为:ChildTotalCost + IOCPURate * IOCost + CPUCost
RunCost数组估算的 SORT 的运行代价(内部表示)
即从排序缓存中提取各个记录的代价
公式为:OptrCPUCost * Records
TotalCost数组估算的 SORT 的总代价(内部表示)
公式为:StartCost + RunCost
OutputRecords数组估算的 SORT 的输出记录个数
公式为:Records

示例

"SortNode": {
  "Records": 1000000,
  "SortFields": 1,
  "RecordTotalSize": [
    "Records * RecordSize",
    "1000000 * 269",
    269000000
  ],
  "Pages": [
    "max( 1, ceil( RecordTotalSize / PageUnit) )",
    "max( 1, ceil( 269000000 / 4096) )",
    65674
  ],
  "SortType": "External",
  "IOCost": [
    "ceil( Pages * ( SeqWrtIOCostUnit + SeqReadIOCostUnit * 0.75 + RandomReadIOCostUnit * 0.25 ) )",
    "ceil( 65674 * ( 2 + 1 * 0.75 + 10 * 0.25 ) )",
    344789
  ],
  "CPUCost": [
    "ceil( 2 * OptrCPUCost * SortFields * max( 2, Records ) * log2( max( 2, Records ) ) )",
    "ceil( 2 * 1 * 1 * max( 2, 1000000 ) * log2( max( 2, 1000000 ) ) )",
    39863138
  ],
  "StartCost": [
    "ChildTotalCost + IOCPURate * IOCost + CPUCost",
    "160864000 + 2000 * 344789 + 39863138",
    890305138
  ],
  "RunCost": [
    "OptrCPUCost * Records",
    "1 * 1000000",
    1000000
  ],
  "TotalCost": [
    "StartCost + RunCost",
    "890305138 + 1000000",
    891305138
  ],
  "OutputRecords": [
    "Records",
    "1000000",
    1000000
  ]
}

相关内容:

访问计划的搜索过程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值