~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/registry.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) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
24
24
#include <vector>
25
25
#include <map>
26
26
#include <algorithm>
27
 
#include <iostream>
28
 
 
29
 
#include <boost/scoped_ptr.hpp>
30
 
 
31
 
#include <drizzled/gettext.h>
32
 
#include <drizzled/unireg.h>
33
 
#include <drizzled/errmsg_print.h>
34
 
#include <drizzled/plugin/plugin.h>
35
 
 
 
27
 
 
28
#include "drizzled/gettext.h"
 
29
#include "drizzled/unireg.h"
 
30
#include "drizzled/errmsg_print.h"
36
31
 
37
32
namespace drizzled
38
33
{
 
34
namespace plugin
 
35
{
 
36
class Plugin;
 
37
}
39
38
 
40
39
namespace module
41
40
{
42
41
class Module;
43
42
class Library;
44
 
class Graph;
45
 
 
46
43
 
47
44
class Registry
48
45
{
49
 
public:
50
 
 
51
 
  typedef std::map<std::string, Library *> LibraryMap;
52
 
  typedef std::map<std::string, Module *> ModuleMap;
53
 
  typedef std::vector<Module *> ModuleList;
54
46
private:
55
 
  LibraryMap library_registry_;
56
 
  ModuleMap module_registry_;
57
 
  boost::scoped_ptr<Graph> depend_graph_; 
58
 
  
59
 
  plugin::Plugin::map plugin_registry;
60
 
 
61
 
  bool deps_built_;
62
 
 
63
 
  Registry();
 
47
  std::map<std::string, Library *> library_map;
 
48
  std::map<std::string, Module *> module_map;
 
49
  std::map<std::string, plugin::Plugin *> plugin_registry;
 
50
 
 
51
  Registry()
 
52
   : module_map(),
 
53
     plugin_registry()
 
54
  { }
 
55
 
64
56
  Registry(const Registry&);
65
57
  Registry& operator=(const Registry&);
66
58
  ~Registry();
67
 
 
68
 
  void buildDeps();
69
59
public:
70
60
 
71
61
  static Registry& singleton()
74
64
    return *registry;
75
65
  }
76
66
 
77
 
  void copy(plugin::Plugin::vector &arg);
78
 
 
79
67
  static void shutdown();
80
68
 
81
69
  Module *find(std::string name);
82
70
 
83
71
  void add(Module *module);
84
72
 
85
 
  void remove(Module *module);
86
 
 
87
 
  std::vector<Module *> getList();
88
 
 
89
 
  const plugin::Plugin::map &getPluginsMap() const
 
73
 
 
74
  std::vector<Module *> getList(bool active);
 
75
 
 
76
  const std::map<std::string, plugin::Plugin *> &getPluginsMap() const
90
77
  {
91
78
    return plugin_registry;
92
79
  }
93
80
 
94
 
  const ModuleMap &getModulesMap() const
 
81
  const std::map<std::string, Module *> &getModulesMap() const
95
82
  {
96
 
    return module_registry_;
 
83
    return module_map;
97
84
  }
98
85
 
99
86
  Library *addLibrary(const std::string &plugin_name, bool builtin= false);
106
93
  void add(T *plugin)
107
94
  {
108
95
    bool failed= false;
109
 
    std::string plugin_type(plugin->getTypeName());
110
 
    std::transform(plugin_type.begin(), plugin_type.end(),
111
 
                   plugin_type.begin(), ::tolower);
112
96
    std::string plugin_name(plugin->getName());
113
97
    std::transform(plugin_name.begin(), plugin_name.end(),
114
98
                   plugin_name.begin(), ::tolower);
115
 
    if (plugin_registry.find(std::make_pair(plugin_type, plugin_name)) != plugin_registry.end())
 
99
    if (plugin_registry.find(plugin_name) != plugin_registry.end())
116
100
    {
117
 
      errmsg_printf(error::ERROR,
118
 
                    _("Loading plugin %s failed: a %s plugin by that name "
119
 
                      "already exists.\n"),
120
 
                    plugin->getTypeName().c_str(),
121
 
                    plugin->getName().c_str());
 
101
      errmsg_printf(ERRMSG_LVL_ERROR,
 
102
                    _("Loading plugin %s failed: a plugin by that name already "
 
103
                      "exists.\n"), plugin->getName().c_str());
122
104
      failed= true;
123
105
    }
124
106
    if (T::addPlugin(plugin))
125
 
    {
126
107
      failed= true;
127
 
    }
128
 
 
129
108
    if (failed)
130
109
    {
131
 
      errmsg_printf(error::ERROR,
132
 
                    _("Fatal error: Failed initializing %s::%s plugin.\n"),
133
 
                    plugin->getTypeName().c_str(),
 
110
      errmsg_printf(ERRMSG_LVL_ERROR,
 
111
                    _("Fatal error: Failed initializing %s plugin.\n"),
134
112
                    plugin->getName().c_str());
135
113
      unireg_abort(1);
136
114
    }
137
 
    plugin_registry.insert(std::make_pair(std::make_pair(plugin_type, plugin_name), plugin));
 
115
    plugin_registry.insert(std::pair<std::string, plugin::Plugin *>(plugin_name, plugin));
138
116
  }
139
117
 
140
118
  template<class T>
141
119
  void remove(T *plugin)
142
120
  {
143
 
    std::string plugin_type(plugin->getTypeName());
144
 
    std::transform(plugin_type.begin(), plugin_type.end(),
145
 
                   plugin_type.begin(), ::tolower);
146
121
    std::string plugin_name(plugin->getName());
147
122
    std::transform(plugin_name.begin(), plugin_name.end(),
148
123
                   plugin_name.begin(), ::tolower);
149
124
    T::removePlugin(plugin);
150
 
    plugin_registry.erase(std::make_pair(plugin_type, plugin_name));
 
125
    plugin_registry.erase(plugin_name);
151
126
  }
152
127
 
153
128