~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/util/string.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:
1
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 * Copyright (C) 2010 Brian Aker
 
4
 * Copyright (c) 2010, Brian Aker
5
5
 * All rights reserved.
6
6
 *
7
7
 * Redistribution and use in source and binary forms, with or without
36
36
#ifndef DRIZZLED_UTIL_STRING_H
37
37
#define DRIZZLED_UTIL_STRING_H
38
38
 
39
 
#include <utility>
40
39
#include <string>
41
 
#include <vector>
42
 
 
43
40
#include <boost/algorithm/string/predicate.hpp>
44
41
#include <boost/functional/hash.hpp>
45
 
#include <boost/shared_ptr.hpp>
46
42
 
47
43
namespace drizzled
48
44
{
50
46
namespace util
51
47
{
52
48
 
53
 
 
54
 
namespace string {
55
 
typedef boost::shared_ptr<std::string> shared_ptr;
56
 
typedef boost::shared_ptr<const std::string> const_shared_ptr;
57
 
typedef std::vector< std::string > vector;
58
 
}
59
 
 
60
49
struct insensitive_equal_to : std::binary_function<std::string, std::string, bool>
61
50
{
62
51
  bool operator()(std::string const& x, std::string const& y) const
81
70
  }
82
71
};
83
72
 
84
 
struct sensitive_hash : std::unary_function< std::vector<char>, std::size_t>
85
 
{
86
 
  std::size_t operator()(std::vector<char> const& x) const
87
 
  {
88
 
    std::size_t seed = 0;
89
 
 
90
 
    for(std::vector<char>::const_iterator it = x.begin(); it != x.end(); ++it)
91
 
    {
92
 
      boost::hash_combine(seed, *it);
93
 
    }
94
 
 
95
 
    return seed;
96
 
  }
97
 
};
98
 
 
99
73
} /* namespace util */
100
74
} /* namespace drizzled */
101
75