~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/thr_lock.h

  • Committer: Prafulla Tekawade
  • Date: 2010-07-13 16:07:35 UTC
  • mto: (1662.1.4 rollup)
  • mto: This revision was merged to the branch mainline in revision 1664.
  • Revision ID: prafulla_t@users.sourceforge.net-20100713160735-2fsdtrm3azayuyu1
This bug is simillar to mysql bug 36133
http://bugs.mysql.com/bug.php?id=36133

Taking changes from that fix.

  - The problem was that the range optimizer evaluated constant expressions, 
    and among them it would try to evaluate IN-subquery predicates slated for
    handling with materialization strategy. However, these predicates require
    that parent_join->setup_subquery_materialization() is invoked before one
    attempts to evaluate them.
  
  - Fixed by making the range optimizer not to evaluate expressions that have
    item->is_expensive() == TRUE (these are materialization subqueries and 
    stored function calls). This should also resolve the problem that EXPLAIN 
    may be too long. 
    This change cuts off some opportunities for range optimizer, but this is 
    the price we're willing to pay for separation of query optimization and
    execution. 

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>
24
 
 
25
 
#include <drizzled/visibility.h>
 
21
#include <pthread.h>
26
22
 
27
23
namespace drizzled
28
24
{
29
25
 
 
26
struct st_thr_lock;
 
27
 
 
28
namespace internal
 
29
{
 
30
extern pthread_mutex_t THR_LOCK_lock;
 
31
}
 
32
 
30
33
extern uint64_t max_write_lock_count;
31
34
extern uint64_t table_lock_wait_timeout;
 
35
extern bool thr_lock_inited;
32
36
 
33
37
 
34
38
enum thr_lock_type { TL_IGNORE=-1,
73
77
  of an instance of this structure is used to uniquely identify the thread.
74
78
*/
75
79
 
76
 
struct THR_LOCK_INFO
 
80
typedef struct st_thr_lock_info
77
81
{
 
82
  pthread_t thread;
78
83
  uint64_t thread_id;
79
84
  uint32_t n_cursors;
80
 
 
81
 
  THR_LOCK_INFO() : 
82
 
    thread_id(0),
83
 
    n_cursors(0)
84
 
  { }
85
 
 
86
 
  void init();
87
 
 
88
 
};
 
85
} THR_LOCK_INFO;
89
86
 
90
87
/*
91
88
  Lock owner identifier. Globally identifies the lock owner within the
93
90
  structure is used as id.
94
91
*/
95
92
 
96
 
struct THR_LOCK_OWNER
 
93
typedef struct st_thr_lock_owner
97
94
{
98
95
  THR_LOCK_INFO *info;
99
 
 
100
 
  THR_LOCK_OWNER() :
101
 
    info(0)
102
 
  { }
103
 
 
104
 
};
105
 
 
106
 
struct THR_LOCK;
107
 
struct THR_LOCK_DATA;
108
 
 
109
 
struct DRIZZLED_API THR_LOCK_DATA {
 
96
} THR_LOCK_OWNER;
 
97
 
 
98
 
 
99
typedef struct st_thr_lock_data {
110
100
  THR_LOCK_OWNER *owner;
111
 
  struct THR_LOCK_DATA *next,**prev;
112
 
  struct THR_LOCK *lock;
113
 
  boost::condition_variable_any *cond;
 
101
  struct st_thr_lock_data *next,**prev;
 
102
  struct st_thr_lock *lock;
 
103
  pthread_cond_t *cond;
114
104
  enum thr_lock_type type;
115
105
  void *status_param;                   /* Param to status functions */
116
 
 
117
 
  THR_LOCK_DATA() :
118
 
    owner(0),
119
 
    next(0),
120
 
    prev(0),
121
 
    lock(0),
122
 
    cond(0),
123
 
    type(TL_UNLOCK),
124
 
    status_param(0)
125
 
  { }
126
 
 
127
 
  void init(THR_LOCK *lock,
128
 
            void *status_param= NULL);
129
 
};
 
106
} THR_LOCK_DATA;
130
107
 
131
108
struct st_lock_list {
132
109
  THR_LOCK_DATA *data,**last;
133
 
 
134
 
  st_lock_list() :
135
 
    data(0),
136
 
    last(0)
137
 
  { }
138
110
};
139
111
 
140
 
struct THR_LOCK {
141
 
private:
142
 
  boost::mutex mutex;
143
 
public:
 
112
typedef struct st_thr_lock {
 
113
  pthread_mutex_t mutex;
144
114
  struct st_lock_list read_wait;
145
115
  struct st_lock_list read;
146
116
  struct st_lock_list write_wait;
148
118
  /* write_lock_count is incremented for write locks and reset on read locks */
149
119
  uint32_t write_lock_count;
150
120
  uint32_t read_no_write_count;
151
 
 
152
 
  THR_LOCK() :
153
 
    write_lock_count(0),
154
 
    read_no_write_count(0)
155
 
  { }
156
 
 
157
 
  ~THR_LOCK()
158
 
  { }
159
 
 
160
 
  void abort_locks();
161
 
  bool abort_locks_for_thread(uint64_t thread);
162
 
 
163
 
  void lock()
164
 
  {
165
 
    mutex.lock();
166
 
  }
167
 
 
168
 
  void unlock()
169
 
  {
170
 
    mutex.unlock();
171
 
  }
172
 
 
173
 
  void init()
174
 
  {
175
 
  }
176
 
 
177
 
  void deinit()
178
 
  {
179
 
  }
180
 
 
181
 
  boost::mutex *native_handle()
182
 
  {
183
 
    return &mutex;
184
 
  }
185
 
};
186
 
 
187
 
class Session; 
188
 
 
 
121
  void (*get_status)(void*, int);       /* When one gets a lock */
 
122
  void (*copy_status)(void*,void*);
 
123
  void (*update_status)(void*);         /* Before release of write */
 
124
  void (*restore_status)(void*);         /* Before release of read */
 
125
  bool (*check_status)(void *);
 
126
} THR_LOCK;
 
127
 
 
128
 
 
129
bool init_thr_lock(void);               /* Must be called once/thread */
189
130
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
190
 
DRIZZLED_API void thr_lock_init(THR_LOCK *lock);
191
 
enum enum_thr_lock_result thr_multi_lock(Session &session, THR_LOCK_DATA **data,
 
131
void thr_lock_info_init(THR_LOCK_INFO *info);
 
132
void thr_lock_init(THR_LOCK *lock);
 
133
void thr_lock_delete(THR_LOCK *lock);
 
134
void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data,
 
135
                        void *status_param);
 
136
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
192
137
                                         uint32_t count, THR_LOCK_OWNER *owner);
193
138
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count);
 
139
void thr_abort_locks(THR_LOCK *lock);
 
140
bool thr_abort_locks_for_thread(THR_LOCK *lock, uint64_t thread);
194
141
 
195
142
} /* namespace drizzled */
196
143