SORT的推演公式

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

示例

  1. "SortNode": {
  2. "Records": 1000000,
  3. "SortFields": 1,
  4. "RecordTotalSize": [
  5. "Records * RecordSize",
  6. "1000000 * 269",
  7. 269000000
  8. ],
  9. "Pages": [
  10. "max( 1, ceil( RecordTotalSize / PageUnit) )",
  11. "max( 1, ceil( 269000000 / 4096) )",
  12. 65674
  13. ],
  14. "SortType": "External",
  15. "IOCost": [
  16. "ceil( Pages * ( SeqWrtIOCostUnit + SeqReadIOCostUnit * 0.75 + RandomReadIOCostUnit * 0.25 ) )",
  17. "ceil( 65674 * ( 2 + 1 * 0.75 + 10 * 0.25 ) )",
  18. 344789
  19. ],
  20. "CPUCost": [
  21. "ceil( 2 * OptrCPUCost * SortFields * max( 2, Records ) * log2( max( 2, Records ) ) )",
  22. "ceil( 2 * 1 * 1 * max( 2, 1000000 ) * log2( max( 2, 1000000 ) ) )",
  23. 39863138
  24. ],
  25. "StartCost": [
  26. "ChildTotalCost + IOCPURate * IOCost + CPUCost",
  27. "160864000 + 2000 * 344789 + 39863138",
  28. 890305138
  29. ],
  30. "RunCost": [
  31. "OptrCPUCost * Records",
  32. "1 * 1000000",
  33. 1000000
  34. ],
  35. "TotalCost": [
  36. "StartCost + RunCost",
  37. "890305138 + 1000000",
  38. 891305138
  39. ],
  40. "OutputRecords": [
  41. "Records",
  42. "1000000",
  43. 1000000
  44. ]
  45. }