IXSCAN的推演公式

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

字段名类型描述
IndexPages整型估算的 IXSCAN 输入的索引页数
IndexLevels整型估算的 IXSCAN 输入的索引层数
MthSelectivity浮点型估算的 IXSCAN 使用匹配符进行过滤的选择率
MthCPUCost整型估算的 IXSCAN 使用匹配符过滤一个记录的 CPU 代价
IXScanSelectivity浮点型估算的 IXSCAN 使用索引时需要扫描索引的比例
IXPredSelectivity浮点型估算的 IXSCAN 使用索引进行过滤的选择率
PredCPUCost整型估算的 IXSCAN 使用索引进行过滤一个记录的 CPU 代价
IndexReadPages数组估算的 IXSCAN 需要读取的索引页个数
NeedEvalIO 为 false 不需要计算
公式为:max( 1, ceil( IndexPages IXScanSelectivity ) )
IndexReadRecords数组估算的 IXSCAN 需要读取的索引记录个数
公式为:max( 1, ceil( Records IXScanSelectivity ) )
ReadPages数组估算的 IXSCAN 需要读取的数据页个数
NeedEvalIO 为 false 不需要计算
公式为:max( 1, ceil( Pages PredSelevtivity ) )
ReadRecords数组估算的 IXSCAN 需要读取的记录个数
公式为:max( 1, ceil( Records IXPredSelectivity ) )
IOCost数组估算的 IXSCAN 的 IO 代价的公式及计算过程
NeedEvalIO 为 false 不需要计算
即各个数据页进行随机扫描的代价总和
公式为:RandomReadIOCostUnit ( IndexReadPages + ReadPages ) ( PageSize / PageUnit )
CPUCost数组估算的 IXSCAN 的 CPU 代价的公式及计算过程
即各个记录从索引页和数据页中提取并进行匹配符过滤的代价总和
如果需要进行匹配符过滤,公式为:IndexReadRecords ( IXExtractCPUCost + PredCPUCost ) + ReadRecords ( RecExtractCPUCost + MthCPUCost )
如果不需要进行匹配符过滤,公式为:IndexReadRecords ( IXExtractCPUCost + PredCPUCost ) + ReadRecords RecExtractCPUCost
StartCost数组估算的 IXSCAN 的启动代价(内部表示)
公式为:IXScanStartCost + PredCPUCost IndexLevels
RunCost数组估算的 IXSCAN 的运行代价(内部表示)
公式为:IOCPURate IOCost + CPUCost
TotalCost数组估算的 IXSCAN 的总代价(内部表示)
公式为:StartCost + RunCost
OutputRecords数组估算的 IXSCAN 的输出记录个数
公式为:max( 1, ceil( Records * min( IXPredSelectivity, MthSelectivity ) ) )

示例

  1. "ScanNode": {
  2. "IndexPages": 49,
  3. "IndexLevels": 1,
  4. "MthSelectivity": 0.00001,
  5. "MthCPUCost": 2,
  6. "IXScanSelectivity": 0.00001,
  7. "IXPredSelectivity": 0.00001,
  8. "PredCPUCost": 1,
  9. "IndexReadPages": [
  10. "max( 1, ceil( IndexPages * IXScanSelectivity ) )",
  11. "max( 1, ceil( 49 * 1e-05 ) )",
  12. 1
  13. ],
  14. "IndexReadRecords": [
  15. "max( 1, ceil( Records * IXScanSelectivity ) )",
  16. "max( 1, ceil( 100000 * 1e-05 ) )",
  17. 1
  18. ],
  19. "ReadPages": [
  20. "max( 1, ceil( Pages * IXPredSelectivity ) )",
  21. "max( 1, ceil( 49 * 1e-05 ) )",
  22. 1
  23. ],
  24. "ReadRecords": [
  25. "max( 1, ceil( Records * IXPredSelectivity ) )",
  26. "max( 1, ceil( 100000 * 1e-05 ) )",
  27. 1
  28. ],
  29. "IOCost": [
  30. "RandomReadIOCostUnit * ( IndexReadPages + ReadPages ) * ( PageSize / PageUnit )",
  31. "10 * ( 1 + 1 ) * ( 65536 / 4096 ) ",
  32. 320
  33. ],
  34. "CPUCost": [
  35. "IndexReadRecords * ( IXExtractCPUCost + PredCPUCost ) + ReadRecords * RecExtractCPUCost",
  36. "1 * ( 2 + 1 ) + 1 * 4",
  37. 7
  38. ],
  39. "StartCost": [
  40. "IXScanStartCost + PredCPUCost * IndexLevels",
  41. "0 + 1 * 1",
  42. 1
  43. ],
  44. "RunCost": [
  45. "IOCPURate * IOCost + CPUCost",
  46. "2000 * 320 + 7",
  47. 640007
  48. ],
  49. "TotalCost": [
  50. "StartCost + RunCost",
  51. "1 + 640007",
  52. 640008
  53. ],
  54. "OutputRecords": [
  55. "max( 1, ceil( Records * min( IXPredSelectivity, MthSelectivity ) ) )",
  56. "max( 1, ceil( 100000 * min( 0.00001, 0.00001 ) ) )",
  57. 1
  58. ]
  59. }