~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/thr_lock.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:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* For use with thr_locks */
17
17
 
18
18
#ifndef DRIZZLED_THR_LOCK_H
19
19
#define DRIZZLED_THR_LOCK_H
20
20
 
21
 
#include <boost/thread/mutex.hpp>
22
 
#include <boost/thread/shared_mutex.hpp>
23
 
#include <boost/thread/condition_variable.hpp>
 
21
#include <pthread.h>
24
22
 
25
23
namespace drizzled
26
24
{
73
71
 
74
72
struct THR_LOCK_INFO
75
73
{
 
74
  pthread_t thread;
76
75
  uint64_t thread_id;
77
76
  uint32_t n_cursors;
78
77
 
79
78
  THR_LOCK_INFO() : 
 
79
    thread(0),
80
80
    thread_id(0),
81
81
    n_cursors(0)
82
82
  { }
108
108
  THR_LOCK_OWNER *owner;
109
109
  struct THR_LOCK_DATA *next,**prev;
110
110
  struct THR_LOCK *lock;
111
 
  boost::condition_variable_any *cond;
 
111
  pthread_cond_t *cond;
112
112
  enum thr_lock_type type;
113
113
  void *status_param;                   /* Param to status functions */
114
114
 
137
137
 
138
138
struct THR_LOCK {
139
139
private:
140
 
  boost::mutex mutex;
 
140
  pthread_mutex_t mutex;
141
141
public:
142
142
  struct st_lock_list read_wait;
143
143
  struct st_lock_list read;
160
160
 
161
161
  void lock()
162
162
  {
163
 
    mutex.lock();
 
163
    pthread_mutex_lock(&mutex);
164
164
  }
165
165
 
166
166
  void unlock()
167
167
  {
168
 
    mutex.unlock();
 
168
    pthread_mutex_unlock(&mutex);
169
169
  }
170
170
 
171
171
  void init()
172
172
  {
 
173
    pthread_mutex_init(&mutex, NULL);
173
174
  }
174
175
 
175
176
  void deinit()
176
177
  {
 
178
    pthread_mutex_destroy(&mutex);
177
179
  }
178
180
 
179
 
  boost::mutex *native_handle()
 
181
  pthread_mutex_t *native_handle()
180
182
  {
181
183
    return &mutex;
182
184
  }
183
185
};
184
186
 
185
 
class Session; 
186
187
 
187
188
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
 
189
void thr_lock_info_init(THR_LOCK_INFO *info);
188
190
void thr_lock_init(THR_LOCK *lock);
189
 
enum enum_thr_lock_result thr_multi_lock(Session &session, THR_LOCK_DATA **data,
 
191
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
190
192
                                         uint32_t count, THR_LOCK_OWNER *owner);
191
193
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count);
192
194