~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/unique.h

  • Committer: Stewart Smith
  • Date: 2010-08-12 16:48:46 UTC
  • mto: This revision was merged to the branch mainline in revision 1707.
  • Revision ID: stewart@flamingspork.com-20100812164846-s9bhy47g60bvqs41
bug lp:611379 Equivalent queries with Impossible where return different results

The following two equivalent queries return different results in maria 5.2 and 5.3 (and identical results in mysql 5.5.5) :

SELECT SUM( DISTINCT table1 .`pk` ) FROM B table1 STRAIGHT_JOIN ( BB table2 JOIN CC ON table2 .`col_varchar_key` ) ON table2 .`pk` ;

SELECT * FROM ( SELECT SUM( DISTINCT table1 .`pk` ) FROM B table1 STRAIGHT_JOIN ( BB table2 JOIN CC ON table2 .`col_varchar_key` ) ON table2 .`pk` );

MariaDB returns 0 on the second query and NULL on the first, whereas MySQL returns NULL on both. In MariaDB, both EXPLAIN plans agree that "Impossible WHERE noticed after reading const tables"



We have some slightly different output in drizzle:

main.bug_lp611379 [ fail ]
drizzletest: At line 9: query 'explain select * from (select sum(distinct t1.a) from t1,t2 where t1.a=t2.a)
as t' failed: 1048: Column 'sum(distinct t1.a)' cannot be null

but the fix gets us the correct query results, although with slightly different execution plans.



This fix is directly ported from MariaDB.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
class Unique : public memory::SqlAlloc
42
42
{
 
43
  DYNAMIC_ARRAY file_ptrs;
 
44
  ulong max_elements;
43
45
  size_t max_in_memory_size;
 
46
  internal::IO_CACHE *file;
44
47
  TREE tree;
45
48
  unsigned char *record_pointers;
 
49
  bool flush();
46
50
  uint32_t size;
47
51
 
48
52
public:
53
57
  ulong elements_in_tree() { return tree.elements_in_tree; }
54
58
  inline bool unique_add(void *ptr)
55
59
  {
56
 
    return (not tree_insert(&tree, ptr, 0, tree.custom_arg));
 
60
    if (tree.elements_in_tree > max_elements && flush())
 
61
      return(1);
 
62
    return(!tree_insert(&tree, ptr, 0, tree.custom_arg));
57
63
  }
58
64
 
59
65
  bool get(Table *table);
60
66
  static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size,
61
67
                             size_t max_in_memory_size);
62
68
  inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size,
63
 
                                            size_t sortbuff_size)
 
69
                                            size_t max_in_memory_size)
64
70
  {
65
71
    register size_t max_elems_in_tree=
66
 
      (1 + sortbuff_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
 
72
      (1 + max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
67
73
    return (int) (sizeof(uint32_t)*(1 + nkeys/max_elems_in_tree));
68
74
  }
69
75