JOIN_TAB

typedef struct st_join_table {
  st_join_table() {}                          /* Remove gcc warning */
  TABLE        *table;
  KEYUSE    *keyuse;            /**< pointer to first used key */
  SQL_SELECT    *select;
  /**
    When doing filesort, the select object is used for building the
    sort index. After the sort index is built, the pointer to the
    select object is set to NULL to avoid that it is used when reading
    the result records (@see create_sort_index()). For subqueries that
    do filesort and that are executed multiple times, the pointer to
    the select object must be restored before the next execution both
    to ensure that the select object is used and to be able to cleanup
    the select object after the final execution of the subquery. In
    order to be able to restore the pointer to the select object, it
    is saved in saved_select in create_sort_index() and restored in
    JOIN::exec() after the main select is done.
  */
  SQL_SELECT    *saved_select;
  COND        *select_cond;
  QUICK_SELECT_I *quick;
  Item           **on_expr_ref;   /**< pointer to the associated on expression   */
  COND_EQUAL    *cond_equal;    /**< multiple equalities for the on expression */
  st_join_table *first_inner;   /**< first inner table for including outerjoin */
  bool           found;         /**< true after all matches or null complement */
  bool           not_null_compl;/**< true before null complement is added      */
  st_join_table *last_inner;    /**< last table table for embedding outer join */
  st_join_table *first_upper;  /**< first inner table for embedding outer join */
  st_join_table *first_unmatched; /**< used for optimization purposes only     */

  /* Special content for EXPLAIN ‘Extra‘ column or NULL if none */
  const char    *info;
  /*
    Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN ‘Extra‘
    column, or 0 if there is no info.
  */
  uint          packed_info;

  READ_RECORD::Setup_func read_first_record;
  Next_select_func next_select;
  READ_RECORD    read_record;
  /*
    Currently the following two fields are used only for a [NOT] IN subquery
    if it is executed by an alternative full table scan when the left operand of
    the subquery predicate is evaluated to NULL.
  */
  READ_RECORD::Setup_func save_read_first_record;/* to save read_first_record */
  READ_RECORD::Read_func save_read_record;/* to save read_record.read_record */
  double    worst_seeks;
  key_map    const_keys;            /**< Keys with constant part */
  key_map    checked_keys;            /**< Keys checked in find_best */
  key_map    needed_reg;
  key_map       keys;                           /**< all keys with can be used */

  /* Either #rows in the table or 1 for const table.  */
  ha_rows    records;
  /*
    Number of records that will be scanned (yes scanned, not returned) by the
    best ‘independent‘ access method, i.e. table scan or QUICK_*_SELECT)
  */
  ha_rows       found_records;
  /*
    Cost of accessing the table using "ALL" or range/index_merge access
    method (but not ‘index‘ for some reason), i.e. this matches method which
    E(#records) is in found_records.
  */
  ha_rows       read_time;

  table_map    dependent,key_dependent;
  uint        use_quick,index;
  uint        status;                ///< Save status for cache
  uint        used_fields,used_fieldlength,used_blobs;
  enum join_type type;
  bool        cached_eq_ref_table,eq_ref_table,not_used_in_distinct;
  bool        sorted;
  /*
    If it‘s not 0 the number stored this field indicates that the index
    scan has been chosen to access the table data and we expect to scan
    this number of rows for the table.
  */
  ha_rows       limit;
  TABLE_REF    ref;
  JOIN_CACHE    cache;
  JOIN        *join;
  /** Bitmap of nested joins this table is part of */
  nested_join_map embedding_map;

  void cleanup();
  /*
    In cases where filesort reads rows from a table using Loose Index
    Scan, the fact that LIS was used is lost because
    create_sort_index() deletes join_tab->select->quick. MySQL needs
    this information during JOIN::exec().

    This variable is a hack for MySQL 5.5 only. A value of true means
    that filesort used LIS to read from the table. In MySQL 5.6 and
    later, join_tab->filesort is a separate structure with it‘s own
    select that can be inquired to get the same information. There is
    no need for this variable in MySQL 5.6 and later.
  */
  bool        filesort_used_loose_index_scan;
  /*
    Similar hack as for filesort_used_loose_index_scan. Not needed for
    MySQL 5.6 and later.
  */
  bool        filesort_used_loose_index_scan_agg_distinct;
  inline bool is_using_loose_index_scan()
  {
    return (filesort_used_loose_index_scan ||
            (select && select->quick &&
             (select->quick->get_type() ==
              QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX))
            );
  }
  bool is_using_agg_loose_index_scan ()
  {
    return (filesort_used_loose_index_scan_agg_distinct ||
            (select && select->quick &&
             (select->quick->get_type() ==
              QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX) &&
             ((QUICK_GROUP_MIN_MAX_SELECT *)select->quick)->is_agg_distinct())
            );
  }
} JOIN_TAB;
时间: 2024-10-15 01:04:26

JOIN_TAB的相关文章

Atitit.code&#160;base&#160;view&#160;视图的实现原理

Atitit.code base view 视图的实现原理 1. 视图的执行算法:1 2. 不可更新的视图:1 3. 关于视图的可插入性:insert2 4. 视图定义3 5. 调用3 1. 视图的执行算法: 存在两种执行算法: 1.  Merge:合并的执行方式,每当执行的时候,先将我们视图的sql语句与外部查询视图的sql语句,混合在一起,最终执行: 2.  Temptable:临时表模式,每当查询的时候,将视图所使用的select语句生成一个结果的临时表,再在当前的临时表内进行查询. 指的

[MySQL 5.6] 初识5.6的optimizer trace

在MySQL5.6中,支持将执行的SQL的查询计划树记录下来,目前来看,即使对于非常简单的查询,也会打印出冗长的查询计划,看起来似乎不是很可读,不过对于一个经验丰富,对查询计划的生成过程比较了解的DBA而言,这是一个优化SQL的宝藏,因为暴露了大量的内部产生查询计划的信息给用户,这意味着,我们可以对开销较大的部分进行优化. 新参数optimizer_trace可以控制是否为执行的SQL生成查询计划树,默认关闭,我们也建议关闭,因为它会产生额外的性能开销(dimitrik的评测:http://di

class JOIN

class JOIN :public Sql_alloc { JOIN(const JOIN &rhs); /**< not implemented */ JOIN& operator=(const JOIN &rhs); /**< not implemented */ public: JOIN_TAB *join_tab,**best_ref; JOIN_TAB **map2table; ///< mapping between table indexes an

MySQL5.6.7-rc index condition pushdown 索引条件下推代码解读

MySQL5.6.7-rc index condition pushdown  索引条件下推代码解读 http://jishu.zol.com.cn/4505.html MySQL5.6.7-rc index condition pushdown代码解读 A-A+ 2013-08-07 11:10| 分享到: 对index condition pushdown很感兴趣,并且跟踪代码让自己受益良多,因此就来跟一下相关代码. 看的是mysql5.6.7-rc官方社区版. 先说说我对研究MySQL源码

MySQL优化器join顺序

前一篇介绍了cost的计算方法,下面测试一下两表关联的查询: 测试用例 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 CREATE TABLE `xpchild` (   `id` int(11) NOT NULL,   `name` varchar(100) DEFAULT NULL,   `c1` int(11) DEFAULT NULL,   `c2` int(11) DEFAULT NULL,   PRIMARY KEY (`id`),   KEY `xpc

1110MySQL select实现原理

转自http://www.jianshu.com/p/NsWbRv 工作中需要借鉴MySQL对于select的具体实现,在网上搜了很久,几乎都是介绍原理的,对于实现细节都没有介绍,无奈之下只得自己对着源码gdb.结合以前对于sql解析的了解,对mysql select的具体实现有了大致的了解,总结一下. 如果要gdb单步调试,需要在编译MySQl时加上debug选项,参见这篇博客.编译好以后就可以用gdb启动了.如果希望mysql运行时有日志输出,可以指定输出文件的路径和日志类型:--debug