• unknown's avatar
    WL#926 "SUM(DISTINCT) and AVG(DISTINCT)": improvement of SUM(DISTINCT) and · 1534ed8e
    unknown authored
     implementation of AVG(DISTINCT) which utilizes the approach with Fields.
    The patch implemented in October is portede to the up-to-date tree 
    containing DECIMAL type.
    Tests for AVG(DISTINCT) (although there is not much to test provided
    that SUM(DISTINCT) works), cleanups for COUNT(DISTINCT) and GROUP_CONCAT()
    will follow in another changeset.
    
    
    sql/field.cc:
      A handy way to init create_field used for use with virtual tmp tables.
      Feel free to extend it for your own needs.
    sql/field.h:
      Declaration for create_field::init_for_tmp_table()
    sql/item.cc:
      Implementation for a framework used to easily handle different result
      types of SQL expressions. Instead of having instances of each possible 
      result type (integer, decimal, double) in every item, variables
      of all used types are moved to struct Hybrid_type.
      Hybrid_type can change its dynamic type in runtime, and become,
      for instance, DECIMAL from INTEGER.
      All type-specific Item operations are moved to the class hierarchy
      Hybrid_type_traits. Item::decimals and Item::max_length can
      be moved to Hybrid_type as well.
    sql/item.h:
      Declaration for Hybrid_type framework. See also comments for item.cc
      in this changeset.
    sql/item_sum.cc:
      Rewritten implementation for Item_sum_sum_distinct (SUM(DISTINCT))
      and added implementation for Item_sum_avg_distinct (AVG(DISTINCT)).
      The classes utilize Hybrid_type class hierarchy and Fields to
      convert SUM/AVG arguments to binary representation and store in a RB-tree.
    sql/item_sum.h:
      Declarations for Item_sum_distinct (the new intermediate class used
      for SUM and AVG distinct), Item_sum_sum_distinct, Item_sum_avg_distinct.
    sql/sql_select.cc:
      Implementatio of create_virtual_tmp_table().
    sql/sql_select.h:
      Declaration for create_virtual_tmp_table.
    sql/sql_yacc.yy:
      Grammar support for Item_sum_avg_distinct.
    1534ed8e
sql_select.h 16.1 KB