zoukankan      html  css  js  c++  java
  • 使用union

    QUERY: explain extended select id from states where country_id < 100 union (select id from countries where id > 10)
                                TRACE: {
      "steps": [
        {
          "join_preparation": {
            "select#": 1,
            "steps": [
              {
                "expanded_query": "/* select#1 */ select `states`.`id` AS `id` from `states` where (`states`.`country_id` < 100)"
              }
            ]
          }
        },
        {
          "join_preparation": {
            "select#": 2,
            "steps": [
              {
                "expanded_query": "/* select#2 */ select `countries`.`id` AS `id` from `countries` where (`countries`.`id` > 10)"
              }
            ]
          }
        },
        {
          "creating_tmp_table": {
            "tmp_table_info": {
              "table": "intermediate_tmp_table",
              "row_length": 5,
              "key_length": 4,
              "unique_constraint": false,
              "location": "memory (heap)",
              "row_limit_estimate": 3355443
            }
          }
        },
        {
          "join_optimization": {
            "select#": 1,
            "steps": [
              {
                "condition_processing": {
                  "condition": "WHERE",
                  "original_condition": "(`states`.`country_id` < 100)",
                  "steps": [
                    {
                      "transformation": "equality_propagation",
                      "resulting_condition": "(`states`.`country_id` < 100)"
                    },
                    {
                      "transformation": "constant_propagation",
                      "resulting_condition": "(`states`.`country_id` < 100)"
                    },
                    {
                      "transformation": "trivial_condition_removal",
                      "resulting_condition": "(`states`.`country_id` < 100)"
                    }
                  ]
                }
              },
              {
                "table_dependencies": [
                  {
                    "table": "`states`",
                    "row_may_be_null": false,
                    "map_bit": 0,
                    "depends_on_map_bits": [
                    ]
                  }
                ]
              },
              {
                "ref_optimizer_key_uses": [
                ]
              },
              {
                "rows_estimation": [
                  {
                    "table": "`states`",
                    "table_scan": {
                      "rows": 4120,
                      "cost": 12
                    }
                  }
                ]
              },
              {
                "considered_execution_plans": [
                  {
                    "plan_prefix": [
                    ],
                    "table": "`states`",
                    "best_access_path": {
                      "considered_access_paths": [
                        {
                          "access_type": "scan",
                          "rows": 4120,
                          "cost": 836,
                          "chosen": true
                        }
                      ]
                    },
                    "cost_for_plan": 836,
                    "rows_for_plan": 4120,
                    "chosen": true
                  }
                ]
              },
              {
                "attaching_conditions_to_tables": {
                  "original_condition": "(`states`.`country_id` < 100)",
                  "attached_conditions_computation": [
                  ],
                  "attached_conditions_summary": [
                    {
                      "table": "`states`",
                      "attached": "(`states`.`country_id` < 100)"
                    }
                  ]
                }
              },
              {
                "refine_plan": [
                  {
                    "table": "`states`",
                    "access_type": "table_scan"
                  }
                ]
              }
            ]
          }
        },
        {
          "join_optimization": {
            "select#": 2,
            "steps": [
              {
                "condition_processing": {
                  "condition": "WHERE",
                  "original_condition": "(`countries`.`id` > 10)",
                  "steps": [
                    {
                      "transformation": "equality_propagation",
                      "resulting_condition": "(`countries`.`id` > 10)"
                    },
                    {
                      "transformation": "constant_propagation",
                      "resulting_condition": "(`countries`.`id` > 10)"
                    },
                    {
                      "transformation": "trivial_condition_removal",
                      "resulting_condition": "(`countries`.`id` > 10)"
                    }
                  ]
                }
              },
              {
                "table_dependencies": [
                  {
                    "table": "`countries`",
                    "row_may_be_null": false,
                    "map_bit": 0,
                    "depends_on_map_bits": [
                    ]
                  }
                ]
              },
              {
                "ref_optimizer_key_uses": [
                ]
              },
              {
                "rows_estimation": [
                  {
                    "table": "`countries`",
                    "range_analysis": {
                      "table_scan": {
                        "rows": 246,
                        "cost": 52.3
                      },
                      "potential_range_indices": [
                        {
                          "index": "PRIMARY",
                          "usable": true,
                          "key_parts": [
                            "id"
                          ]
                        }
                      ],
                      "best_covering_index_scan": {
                        "index": "PRIMARY",
                        "cost": 50.439,
                        "chosen": true
                      },
                      "setup_range_conditions": [
                      ],
                      "group_index_range": {
                        "chosen": false,
                        "cause": "not_group_by_or_distinct"
                      },
                      "analyzing_range_alternatives": {
                        "range_scan_alternatives": [
                          {
                            "index": "PRIMARY",
                            "ranges": [
                              "10 < id"
                            ],
                            "index_dives_for_eq_ranges": true,
                            "rowid_ordered": true,
                            "using_mrr": false,
                            "index_only": true,
                            "rows": 236,
                            "cost": 48.419,
                            "chosen": true
                          }
                        ],
                        "analyzing_roworder_intersect": {
                          "usable": false,
                          "cause": "too_few_roworder_scans"
                        }
                      },
                      "chosen_range_access_summary": {
                        "range_access_plan": {
                          "type": "range_scan",
                          "index": "PRIMARY",
                          "rows": 236,
                          "ranges": [
                            "10 < id"
                          ]
                        },
                        "rows_for_plan": 236,
                        "cost_for_plan": 48.419,
                        "chosen": true
                      }
                    }
                  }
                ]
              },
              {
                "considered_execution_plans": [
                  {
                    "plan_prefix": [
                    ],
                    "table": "`countries`",
                    "best_access_path": {
                      "considered_access_paths": [
                        {
                          "access_type": "range",
                          "rows": 236,
                          "cost": 95.619,
                          "chosen": true
                        }
                      ]
                    },
                    "cost_for_plan": 95.619,
                    "rows_for_plan": 236,
                    "chosen": true
                  }
                ]
              },
              {
                "attaching_conditions_to_tables": {
                  "original_condition": "(`countries`.`id` > 10)",
                  "attached_conditions_computation": [
                  ],
                  "attached_conditions_summary": [
                    {
                      "table": "`countries`",
                      "attached": "(`countries`.`id` > 10)"
                    }
                  ]
                }
              },
              {
                "refine_plan": [
                  {
                    "table": "`countries`",
                    "access_type": "range"
                  }
                ]
              }
            ]
          }
        },
        {
          "join_explain": {
            "select#": 1,
            "steps": [
            ]
          }
        },
        {
          "join_explain": {
            "select#": 2,
            "steps": [
            ]
          }
        },
        {
          "join_preparation": {
            "select#": "fake",
            "steps": [
              {
                "expanded_query": "/* select#fake */ select `id` AS `id` from dual"
              }
            ]
          }
        },
        {
          "join_optimization": {
            "select#": "fake",
            "steps": [
              {
                "table_dependencies": [
                  {
                    "table": "``.``",
                    "row_may_be_null": false,
                    "map_bit": 0,
                    "depends_on_map_bits": [
                    ]
                  }
                ]
              },
              {
                "rows_estimation": [
                  {
                    "table": "``.``",
                    "table_scan": {
                      "rows": 0,
                      "cost": 10
                    }
                  }
                ]
              },
              {
                "considered_execution_plans": [
                  {
                    "plan_prefix": [
                    ],
                    "table": "``.``",
                    "best_access_path": {
                      "considered_access_paths": [
                        {
                          "access_type": "scan",
                          "rows": 0,
                          "cost": 10,
                          "chosen": true
                        }
                      ]
                    },
                    "cost_for_plan": 10,
                    "rows_for_plan": 0,
                    "chosen": true
                  }
                ]
              },
              {
                "attaching_conditions_to_tables": {
                  "original_condition": null,
                  "attached_conditions_computation": [
                  ],
                  "attached_conditions_summary": [
                    {
                      "table": "``.``",
                      "attached": null
                    }
                  ]
                }
              },
              {
                "refine_plan": [
                  {
                    "table": "``.``",
                    "access_type": "table_scan"
                  }
                ]
              }
            ]
          }
        },
        {
          "join_explain": {
            "select#": "fake",
            "steps": [
            ]
          }
        }
      ]
    }
    MySQL限时解答,24小时内友哥专业解答
    http://www.yougemysqldba.com
    如有进一步需要请联系微信onesoft007
    微博账号@友哥一指
  • 相关阅读:
    NODE_PATH的疑难杂症(转)
    教你如何做一个优雅的Ecmascripter /转
    MDLMaterial Design Lite框架推荐
    GPU硬件加速原理 /转
    透明遮罩图层VS高斯模糊滤镜 效果分析
    QML vs WEB
    PixelMatorPro快捷键大全(osx)
    睡眠排序、面条排序、猴子排序...........................
    全栈设计模式套餐MVVM, RESTful, MVC的历史探索
    2018博客之星评选,我非常需要您宝贵的一票!♪(・ω・)ノ
  • 原文地址:https://www.cnblogs.com/youge-OneSQL/p/9544261.html
Copyright © 2011-2022 走看看