~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/sync0arr.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
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1995, 2009, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file include/sync0arr.h
21
 
The wait array used in synchronization primitives
22
 
 
23
 
Created 9/5/1995 Heikki Tuuri
24
 
*******************************************************/
25
 
 
26
 
#ifndef sync0arr_h
27
 
#define sync0arr_h
28
 
 
29
 
#include "univ.i"
30
 
#include "ut0lst.h"
31
 
#include "ut0mem.h"
32
 
#include "os0thread.h"
33
 
 
34
 
/** Synchronization wait array cell */
35
 
typedef struct sync_cell_struct         sync_cell_t;
36
 
/** Synchronization wait array */
37
 
typedef struct sync_array_struct        sync_array_t;
38
 
 
39
 
/** Parameters for sync_array_create() @{ */
40
 
#define SYNC_ARRAY_OS_MUTEX     1       /*!< protected by os_mutex_t */
41
 
#define SYNC_ARRAY_MUTEX        2       /*!< protected by mutex_t */
42
 
/* @} */
43
 
 
44
 
/*******************************************************************//**
45
 
Creates a synchronization wait array. It is protected by a mutex
46
 
which is automatically reserved when the functions operating on it
47
 
are called.
48
 
@return own: created wait array */
49
 
UNIV_INTERN
50
 
sync_array_t*
51
 
sync_array_create(
52
 
/*==============*/
53
 
        ulint   n_cells,        /*!< in: number of cells in the array
54
 
                                to create */
55
 
        ulint   protection);    /*!< in: either SYNC_ARRAY_OS_MUTEX or
56
 
                                SYNC_ARRAY_MUTEX: determines the type
57
 
                                of mutex protecting the data structure */
58
 
/******************************************************************//**
59
 
Frees the resources in a wait array. */
60
 
UNIV_INTERN
61
 
void
62
 
sync_array_free(
63
 
/*============*/
64
 
        sync_array_t*   arr);   /*!< in, own: sync wait array */
65
 
/******************************************************************//**
66
 
Reserves a wait array cell for waiting for an object.
67
 
The event of the cell is reset to nonsignalled state. */
68
 
UNIV_INTERN
69
 
void
70
 
sync_array_reserve_cell(
71
 
/*====================*/
72
 
        sync_array_t*   arr,    /*!< in: wait array */
73
 
        void*           object, /*!< in: pointer to the object to wait for */
74
 
        ulint           type,   /*!< in: lock request type */
75
 
        const char*     file,   /*!< in: file where requested */
76
 
        ulint           line,   /*!< in: line where requested */
77
 
        ulint*          index); /*!< out: index of the reserved cell */
78
 
/******************************************************************//**
79
 
This function should be called when a thread starts to wait on
80
 
a wait array cell. In the debug version this function checks
81
 
if the wait for a semaphore will result in a deadlock, in which
82
 
case prints info and asserts. */
83
 
UNIV_INTERN
84
 
void
85
 
sync_array_wait_event(
86
 
/*==================*/
87
 
        sync_array_t*   arr,    /*!< in: wait array */
88
 
        ulint           index);  /*!< in: index of the reserved cell */
89
 
/******************************************************************//**
90
 
Frees the cell. NOTE! sync_array_wait_event frees the cell
91
 
automatically! */
92
 
UNIV_INTERN
93
 
void
94
 
sync_array_free_cell(
95
 
/*=================*/
96
 
        sync_array_t*   arr,    /*!< in: wait array */
97
 
        ulint           index); /*!< in: index of the cell in array */
98
 
/**********************************************************************//**
99
 
Note that one of the wait objects was signalled. */
100
 
UNIV_INTERN
101
 
void
102
 
sync_array_object_signalled(
103
 
/*========================*/
104
 
        sync_array_t*   arr);   /*!< in: wait array */
105
 
/**********************************************************************//**
106
 
If the wakeup algorithm does not work perfectly at semaphore relases,
107
 
this function will do the waking (see the comment in mutex_exit). This
108
 
function should be called about every 1 second in the server. */
109
 
UNIV_INTERN
110
 
void
111
 
sync_arr_wake_threads_if_sema_free(void);
112
 
/*====================================*/
113
 
/**********************************************************************//**
114
 
Prints warnings of long semaphore waits to stderr.
115
 
@return TRUE if fatal semaphore wait threshold was exceeded */
116
 
UNIV_INTERN
117
 
ibool
118
 
sync_array_print_long_waits(void);
119
 
/*=============================*/
120
 
/********************************************************************//**
121
 
Validates the integrity of the wait array. Checks
122
 
that the number of reserved cells equals the count variable. */
123
 
UNIV_INTERN
124
 
void
125
 
sync_array_validate(
126
 
/*================*/
127
 
        sync_array_t*   arr);   /*!< in: sync wait array */
128
 
/**********************************************************************//**
129
 
Prints info of the wait array. */
130
 
UNIV_INTERN
131
 
void
132
 
sync_array_print_info(
133
 
/*==================*/
134
 
        FILE*           file,   /*!< in: file where to print */
135
 
        sync_array_t*   arr);   /*!< in: wait array */
136
 
 
137
 
 
138
 
#ifndef UNIV_NONINL
139
 
#include "sync0arr.ic"
140
 
#endif
141
 
 
142
 
#endif