1/* Copyright (C) 2008-2017 Kentoku Shiba
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
15
16#ifdef USE_PRAGMA_IMPLEMENTATION
17#pragma implementation
18#endif
19
20#define MYSQL_SERVER 1
21#include <my_global.h>
22#include "mysql_version.h"
23#include "spd_environ.h"
24#if MYSQL_VERSION_ID < 50500
25#include "mysql_priv.h"
26#include <mysql/plugin.h>
27#else
28#include "sql_priv.h"
29#include "probes_mysql.h"
30#include "sql_class.h"
31#include "key.h"
32#ifdef HANDLER_HAS_DIRECT_AGGREGATE
33#include "sql_select.h"
34#endif
35#endif
36#include "ha_partition.h"
37#include "spd_param.h"
38#include "spd_err.h"
39#include "spd_db_include.h"
40#include "spd_include.h"
41#include "ha_spider.h"
42#include "spd_table.h"
43#include "spd_sys_table.h"
44#include "spd_trx.h"
45#include "spd_conn.h"
46#include "spd_db_conn.h"
47#include "spd_ping_table.h"
48#include "spd_malloc.h"
49
50#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002
51#define SPIDER_CAN_BG_SEARCH (1LL << 37)
52#define SPIDER_CAN_BG_INSERT (1LL << 38)
53#define SPIDER_CAN_BG_UPDATE (1LL << 39)
54#else
55#define SPIDER_CAN_BG_SEARCH (LL(1) << 37)
56#define SPIDER_CAN_BG_INSERT (LL(1) << 38)
57#define SPIDER_CAN_BG_UPDATE (LL(1) << 39)
58#endif
59
60extern handlerton *spider_hton_ptr;
61extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
62#ifdef SPIDER_HAS_HASH_VALUE_TYPE
63extern HASH spider_open_tables;
64#endif
65extern pthread_mutex_t spider_lgtm_tblhnd_share_mutex;
66
67ha_spider::ha_spider(
68) : handler(spider_hton_ptr, NULL)
69{
70 DBUG_ENTER("ha_spider::ha_spider");
71 DBUG_PRINT("info",("spider this=%p", this));
72 spider_alloc_calc_mem_init(mem_calc, 139);
73 spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this));
74 share = NULL;
75 trx = NULL;
76 conns = NULL;
77 need_mons = NULL;
78 condition = NULL;
79 cond_check = FALSE;
80 blob_buff = NULL;
81 conn_keys = NULL;
82 spider_thread_id = 0;
83 trx_conn_adjustment = 0;
84#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
85 trx_hs_r_conn_adjustment = 0;
86 trx_hs_w_conn_adjustment = 0;
87#endif
88 search_link_query_id = 0;
89 searched_bitmap = NULL;
90#ifdef WITH_PARTITION_STORAGE_ENGINE
91 partition_handler_share = NULL;
92 pt_handler_share_creator = NULL;
93#endif
94#ifdef HA_MRR_USE_DEFAULT_IMPL
95 multi_range_keys = NULL;
96 mrr_key_buff = NULL;
97#endif
98 append_tblnm_alias = NULL;
99 use_index_merge = FALSE;
100 is_clone = FALSE;
101 clone_bitmap_init = FALSE;
102 pt_clone_source_handler = NULL;
103 pt_clone_last_searcher = NULL;
104 ft_handler = NULL;
105 ft_first = NULL;
106 ft_current = NULL;
107 ft_count = 0;
108 ft_init_without_index_init = FALSE;
109 sql_kinds = 0;
110 error_mode = 0;
111 use_spatial_index = FALSE;
112#ifdef SPIDER_HAS_GROUP_BY_HANDLER
113 use_fields = FALSE;
114#endif
115 use_pre_call = FALSE;
116 use_pre_records = FALSE;
117#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
118 do_direct_update = FALSE;
119#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
120 hs_pushed_ret_fields_num = MAX_FIELDS;
121 hs_pushed_ret_fields = NULL;
122 hs_pushed_ret_fields_size = 0;
123 hs_increment = FALSE;
124 hs_decrement = FALSE;
125 hs_pushed_strref_num = 0;
126#endif
127 direct_update_fields = NULL;
128#endif
129#ifdef INFO_KIND_FORCE_LIMIT_BEGIN
130 info_limit = 9223372036854775807LL;
131#endif
132#ifdef HA_CAN_BULK_ACCESS
133 is_bulk_access_clone = FALSE;
134 synced_from_clone_source = FALSE;
135 bulk_access_started = FALSE;
136 bulk_access_executing = FALSE;
137 bulk_access_pre_called = FALSE;
138 bulk_access_link_first = NULL;
139/*
140 init_ha_mem_root = FALSE;
141*/
142#endif
143 prev_index_rnd_init = SPD_NONE;
144#ifdef HANDLER_HAS_DIRECT_AGGREGATE
145 direct_aggregate_item_first = NULL;
146#endif
147 result_link_idx = 0;
148 result_list.have_sql_kind_backup = FALSE;
149 result_list.sqls = NULL;
150 result_list.insert_sqls = NULL;
151 result_list.update_sqls = NULL;
152 result_list.tmp_sqls = NULL;
153#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
154 result_list.hs_result_buf = NULL;
155#endif
156 result_list.tmp_tables_created = FALSE;
157 result_list.bgs_working = FALSE;
158 result_list.direct_order_limit = FALSE;
159 result_list.direct_limit_offset = FALSE;
160#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
161 result_list.hs_has_result = FALSE;
162#endif
163 result_list.set_split_read = FALSE;
164 result_list.insert_dup_update_pushdown = FALSE;
165 result_list.tmp_pos_row_first = NULL;
166#ifdef HANDLER_HAS_DIRECT_AGGREGATE
167 result_list.direct_aggregate = FALSE;
168 result_list.snap_direct_aggregate = FALSE;
169#endif
170 result_list.direct_distinct = FALSE;
171 result_list.casual_read = NULL;
172 result_list.use_both_key = FALSE;
173 result_list.in_cmp_ref = FALSE;
174 DBUG_VOID_RETURN;
175}
176
177ha_spider::ha_spider(
178 handlerton *hton,
179 TABLE_SHARE *table_arg
180) : handler(hton, table_arg)
181{
182 DBUG_ENTER("ha_spider::ha_spider");
183 DBUG_PRINT("info",("spider this=%p", this));
184 spider_alloc_calc_mem_init(mem_calc, 0);
185 spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this));
186 share = NULL;
187 trx = NULL;
188 conns = NULL;
189 need_mons = NULL;
190 condition = NULL;
191 cond_check = FALSE;
192 blob_buff = NULL;
193 conn_keys = NULL;
194 spider_thread_id = 0;
195 trx_conn_adjustment = 0;
196#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
197 trx_hs_r_conn_adjustment = 0;
198 trx_hs_w_conn_adjustment = 0;
199#endif
200 search_link_query_id = 0;
201 searched_bitmap = NULL;
202#ifdef WITH_PARTITION_STORAGE_ENGINE
203 partition_handler_share = NULL;
204 pt_handler_share_creator = NULL;
205#endif
206#ifdef HA_MRR_USE_DEFAULT_IMPL
207 multi_range_keys = NULL;
208 mrr_key_buff = NULL;
209#endif
210 append_tblnm_alias = NULL;
211 use_index_merge = FALSE;
212 is_clone = FALSE;
213 clone_bitmap_init = FALSE;
214 pt_clone_source_handler = NULL;
215 pt_clone_last_searcher = NULL;
216 ft_handler = NULL;
217 ft_first = NULL;
218 ft_current = NULL;
219 ft_count = 0;
220 ft_init_without_index_init = FALSE;
221 sql_kinds = 0;
222 error_mode = 0;
223 use_spatial_index = FALSE;
224#ifdef SPIDER_HAS_GROUP_BY_HANDLER
225 use_fields = FALSE;
226#endif
227 use_pre_call = FALSE;
228 use_pre_records = FALSE;
229#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
230 do_direct_update = FALSE;
231#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
232 hs_pushed_ret_fields_num = MAX_FIELDS;
233 hs_pushed_ret_fields = NULL;
234 hs_pushed_ret_fields_size = 0;
235 hs_increment = FALSE;
236 hs_decrement = FALSE;
237 hs_pushed_strref_num = 0;
238#endif
239 direct_update_fields = NULL;
240#endif
241#ifdef INFO_KIND_FORCE_LIMIT_BEGIN
242 info_limit = 9223372036854775807LL;
243#endif
244#ifdef HA_CAN_BULK_ACCESS
245 is_bulk_access_clone = FALSE;
246 synced_from_clone_source = FALSE;
247 bulk_access_started = FALSE;
248 bulk_access_executing = FALSE;
249 bulk_access_pre_called = FALSE;
250 bulk_access_link_first = NULL;
251/*
252 init_ha_mem_root = FALSE;
253*/
254#endif
255 prev_index_rnd_init = SPD_NONE;
256#ifdef HANDLER_HAS_DIRECT_AGGREGATE
257 direct_aggregate_item_first = NULL;
258#endif
259 result_link_idx = 0;
260 result_list.have_sql_kind_backup = FALSE;
261 result_list.sqls = NULL;
262 result_list.insert_sqls = NULL;
263 result_list.update_sqls = NULL;
264 result_list.tmp_sqls = NULL;
265#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
266 result_list.hs_result_buf = NULL;
267#endif
268 result_list.tmp_tables_created = FALSE;
269 result_list.bgs_working = FALSE;
270 result_list.direct_order_limit = FALSE;
271 result_list.direct_limit_offset = FALSE;
272#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
273 result_list.hs_has_result = FALSE;
274#endif
275 result_list.set_split_read = FALSE;
276 result_list.insert_dup_update_pushdown = FALSE;
277 result_list.tmp_pos_row_first = NULL;
278#ifdef HANDLER_HAS_DIRECT_AGGREGATE
279 result_list.direct_aggregate = FALSE;
280 result_list.snap_direct_aggregate = FALSE;
281#endif
282 result_list.direct_distinct = FALSE;
283 result_list.casual_read = NULL;
284 result_list.use_both_key = FALSE;
285 result_list.in_cmp_ref = FALSE;
286 ref_length = sizeof(SPIDER_POSITION);
287 DBUG_VOID_RETURN;
288}
289
290ha_spider::~ha_spider()
291{
292 DBUG_ENTER("ha_spider::~ha_spider");
293 DBUG_PRINT("info",("spider this=%p", this));
294 spider_free_mem_calc(spider_current_trx, mem_calc_id, sizeof(*this));
295 DBUG_VOID_RETURN;
296}
297
298handler *ha_spider::clone(
299 const char *name,
300 MEM_ROOT *mem_root
301) {
302 ha_spider *spider;
303 DBUG_ENTER("ha_spider::clone");
304 DBUG_PRINT("info",("spider this=%p", this));
305 if (
306 !(spider = (ha_spider *)
307 get_new_handler(table->s, mem_root, spider_hton_ptr)) ||
308 !(spider->ref = (uchar*) alloc_root(mem_root, ALIGN_SIZE(ref_length) * 2))
309 )
310 DBUG_RETURN(NULL);
311 spider->is_clone = TRUE;
312 spider->pt_clone_source_handler = this;
313 if (spider->ha_open(table, name, table->db_stat,
314 HA_OPEN_IGNORE_IF_LOCKED))
315 DBUG_RETURN(NULL);
316 spider->sync_from_clone_source_base(this);
317 use_index_merge = TRUE;
318
319 DBUG_RETURN((handler *) spider);
320}
321
322static const char *ha_spider_exts[] = {
323 NullS
324};
325
326const char **ha_spider::bas_ext() const
327{
328 return ha_spider_exts;
329}
330
331int ha_spider::open(
332 const char* name,
333 int mode,
334 uint test_if_locked
335) {
336 THD *thd = ha_thd();
337 int error_num, roop_count;
338 int init_sql_alloc_size;
339#ifdef WITH_PARTITION_STORAGE_ENGINE
340 SPIDER_PARTITION_SHARE *partition_share;
341 uchar *idx_read_bitmap, *idx_write_bitmap,
342 *rnd_read_bitmap, *rnd_write_bitmap;
343 uint part_num;
344 bool create_pt_handler_share = FALSE, pt_handler_mutex = FALSE,
345 may_be_clone = FALSE;
346 ha_spider **pt_handler_share_handlers;
347#ifdef SPIDER_HAS_HASH_VALUE_TYPE
348 my_hash_value_type hash_value;
349#endif
350#endif
351 DBUG_ENTER("ha_spider::open");
352 DBUG_PRINT("info",("spider this=%p", this));
353
354 dup_key_idx = (uint) -1;
355 conn_kinds = SPIDER_CONN_KIND_MYSQL;
356 if (!spider_get_share(name, table, thd, this, &error_num))
357 goto error_get_share;
358 thr_lock_data_init(&share->lock,&lock,NULL);
359
360#ifdef WITH_PARTITION_STORAGE_ENGINE
361 partition_share = share->partition_share;
362 table->file->get_no_parts("", &part_num);
363 if (partition_share)
364 {
365 pt_handler_mutex = TRUE;
366 pthread_mutex_lock(&partition_share->pt_handler_mutex);
367/*
368 if (
369 !partition_share->partition_handler_share ||
370 partition_share->partition_handler_share->table != table
371 )
372 create_pt_handler_share = TRUE;
373*/
374#ifdef SPIDER_HAS_HASH_VALUE_TYPE
375 hash_value = my_calc_hash(&partition_share->pt_handler_hash,
376 (uchar*) &table, sizeof(TABLE *));
377 if (!(partition_handler_share = (SPIDER_PARTITION_HANDLER_SHARE*)
378 my_hash_search_using_hash_value(&partition_share->pt_handler_hash,
379 hash_value, (uchar*) &table, sizeof(TABLE *))))
380#else
381 if (!(partition_handler_share = (SPIDER_PARTITION_HANDLER_SHARE*)
382 my_hash_search(&partition_share->pt_handler_hash, (uchar*) &table,
383 sizeof(TABLE *))))
384#endif
385 {
386 create_pt_handler_share = TRUE;
387 }
388 }
389
390 if (create_pt_handler_share)
391 {
392 if (!(searched_bitmap = (uchar *)
393 spider_bulk_malloc(spider_current_trx, 15, MYF(MY_WME),
394 &searched_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
395 &ft_discard_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
396 &position_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
397 &partition_handler_share, sizeof(SPIDER_PARTITION_HANDLER_SHARE),
398 &idx_read_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
399 &idx_write_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
400 &rnd_read_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
401 &rnd_write_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
402 &pt_handler_share_handlers, sizeof(ha_spider *) * part_num,
403 NullS))
404 ) {
405 error_num = HA_ERR_OUT_OF_MEM;
406 goto error_searched_bitmap_alloc;
407 }
408 DBUG_PRINT("info",("spider create partition_handler_share"));
409 partition_handler_share->use_count = 1;
410/*
411 if (partition_handler_share->use_count < part_num)
412 partition_share->partition_handler_share = partition_handler_share;
413*/
414 DBUG_PRINT("info",("spider table=%p", table));
415 partition_handler_share->table = table;
416 partition_handler_share->searched_bitmap = NULL;
417 partition_handler_share->ft_discard_bitmap = NULL;
418 partition_handler_share->idx_read_bitmap = idx_read_bitmap;
419 partition_handler_share->idx_write_bitmap = idx_write_bitmap;
420 partition_handler_share->rnd_read_bitmap = rnd_read_bitmap;
421 partition_handler_share->rnd_write_bitmap = rnd_write_bitmap;
422 partition_handler_share->between_flg = FALSE;
423 partition_handler_share->idx_bitmap_is_set = FALSE;
424 partition_handler_share->rnd_bitmap_is_set = FALSE;
425 partition_handler_share->table_hash_value = hash_value;
426 partition_handler_share->creator = this;
427 partition_handler_share->parallel_search_query_id = 0;
428 pt_handler_share_creator = this;
429 if (part_num)
430 {
431 partition_handler_share->handlers = (void **) pt_handler_share_handlers;
432 partition_handler_share->handlers[0] = this;
433 } else
434 partition_handler_share->handlers = NULL;
435 uint old_elements = partition_share->pt_handler_hash.array.max_element;
436#ifdef HASH_UPDATE_WITH_HASH_VALUE
437 if (my_hash_insert_with_hash_value(&partition_share->pt_handler_hash,
438 hash_value, (uchar*) partition_handler_share))
439#else
440 if (my_hash_insert(&partition_share->pt_handler_hash,
441 (uchar*) partition_handler_share))
442#endif
443 {
444 error_num = HA_ERR_OUT_OF_MEM;
445 goto error_hash_insert;
446 }
447 if (partition_share->pt_handler_hash.array.max_element > old_elements)
448 {
449 spider_alloc_calc_mem(spider_current_trx,
450 partition_share->pt_handler_hash,
451 (partition_share->pt_handler_hash.array.max_element - old_elements) *
452 partition_share->pt_handler_hash.array.size_of_element);
453 }
454 pthread_mutex_unlock(&partition_share->pt_handler_mutex);
455 pt_handler_mutex = FALSE;
456 } else {
457#endif
458 if (!(searched_bitmap = (uchar *)
459 spider_bulk_malloc(spider_current_trx, 16, MYF(MY_WME),
460 &searched_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
461 &ft_discard_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
462 &position_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
463 NullS))
464 ) {
465 error_num = HA_ERR_OUT_OF_MEM;
466 goto error_searched_bitmap_alloc;
467 }
468#ifdef WITH_PARTITION_STORAGE_ENGINE
469 if (partition_share)
470 {
471 DBUG_PRINT("info",("spider copy partition_handler_share"));
472/*
473 partition_handler_share = (SPIDER_PARTITION_HANDLER_SHARE *)
474 partition_share->partition_handler_share;
475*/
476 if (part_num)
477 {
478 if (partition_handler_share->use_count >= part_num)
479 may_be_clone = TRUE;
480 else {
481 partition_handler_share->handlers[
482 partition_handler_share->use_count] = this;
483 partition_handler_share->use_count++;
484 }
485 }
486/*
487 if (partition_handler_share->use_count == part_num)
488 partition_share->partition_handler_share = NULL;
489*/
490 pthread_mutex_unlock(&partition_share->pt_handler_mutex);
491 pt_handler_mutex = FALSE;
492 }
493 }
494#endif
495 memset(ft_discard_bitmap, 0xFF, no_bytes_in_map(table->read_set));
496 memset(searched_bitmap, 0, no_bytes_in_map(table->read_set));
497
498 init_sql_alloc_size =
499 spider_param_init_sql_alloc_size(thd, share->init_sql_alloc_size);
500
501 result_list.table = table;
502 result_list.first = NULL;
503 result_list.last = NULL;
504 result_list.current = NULL;
505 result_list.record_num = 0;
506 if (
507 !(result_list.sqls = new spider_string[share->link_count]) ||
508 !(result_list.insert_sqls = new spider_string[share->link_count]) ||
509 !(result_list.update_sqls = new spider_string[share->link_count]) ||
510 !(result_list.tmp_sqls = new spider_string[share->link_count])
511 ) {
512 error_num = HA_ERR_OUT_OF_MEM;
513 goto error_init_result_list;
514 }
515 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
516 {
517 result_list.sqls[roop_count].init_calc_mem(80);
518 result_list.insert_sqls[roop_count].init_calc_mem(81);
519 result_list.update_sqls[roop_count].init_calc_mem(82);
520 result_list.tmp_sqls[roop_count].init_calc_mem(83);
521 uint all_link_idx = conn_link_idx[roop_count];
522 uint dbton_id = share->sql_dbton_ids[all_link_idx];
523 if (share->dbton_share[dbton_id]->need_change_db_table_name())
524 {
525 if (
526 result_list.sqls[roop_count].real_alloc(init_sql_alloc_size) ||
527 result_list.insert_sqls[roop_count].real_alloc(init_sql_alloc_size) ||
528 result_list.update_sqls[roop_count].real_alloc(init_sql_alloc_size) ||
529 result_list.tmp_sqls[roop_count].real_alloc(init_sql_alloc_size)
530 ) {
531 error_num = HA_ERR_OUT_OF_MEM;
532 goto error_init_result_list;
533 }
534 }
535 result_list.sqls[roop_count].set_charset(share->access_charset);
536 result_list.insert_sqls[roop_count].set_charset(share->access_charset);
537 result_list.update_sqls[roop_count].set_charset(share->access_charset);
538 result_list.tmp_sqls[roop_count].set_charset(share->access_charset);
539 }
540
541 DBUG_PRINT("info",("spider blob_fields=%d", table_share->blob_fields));
542 if (table_share->blob_fields)
543 {
544 if (!(blob_buff = new spider_string[table_share->fields]))
545 {
546 error_num = HA_ERR_OUT_OF_MEM;
547 goto error_init_blob_buff;
548 }
549 for (roop_count = 0; roop_count < (int) table_share->fields; roop_count++)
550 {
551 blob_buff[roop_count].init_calc_mem(84);
552 blob_buff[roop_count].set_charset(table->field[roop_count]->charset());
553 }
554 }
555
556#ifdef WITH_PARTITION_STORAGE_ENGINE
557 if (may_be_clone && thd_sql_command(thd) != SQLCOM_ALTER_TABLE)
558 is_clone = TRUE;
559#endif
560 if (is_clone)
561 {
562#ifdef WITH_PARTITION_STORAGE_ENGINE
563 if (part_num)
564 {
565 for (roop_count = 0; roop_count < (int) part_num; roop_count++)
566 {
567 if (((ha_spider *) partition_handler_share->handlers[roop_count])->
568 share == share)
569 {
570 pt_clone_source_handler =
571 (ha_spider *) partition_handler_share->handlers[roop_count];
572 break;
573 }
574 }
575 }
576#endif
577
578 sql_command = pt_clone_source_handler->sql_command;
579 result_list.lock_type = pt_clone_source_handler->result_list.lock_type;
580 lock_mode = pt_clone_source_handler->lock_mode;
581
582 if (!pt_clone_source_handler->clone_bitmap_init)
583 {
584 pt_clone_source_handler->set_select_column_mode();
585 pt_clone_source_handler->clone_bitmap_init = TRUE;
586 }
587 set_clone_searched_bitmap();
588 position_bitmap_init = FALSE;
589 }
590#ifdef HA_CAN_BULK_ACCESS
591 external_lock_cnt = 0;
592#endif
593
594 if (reset())
595 {
596 error_num = HA_ERR_OUT_OF_MEM;
597 goto error_reset;
598 }
599
600 DBUG_RETURN(0);
601
602error_reset:
603 delete [] blob_buff;
604 blob_buff = NULL;
605error_init_blob_buff:
606error_init_result_list:
607#ifdef WITH_PARTITION_STORAGE_ENGINE
608 if (
609 partition_handler_share &&
610 pt_handler_share_creator == this
611 ) {
612 partition_share = share->partition_share;
613 if (!pt_handler_mutex)
614 pthread_mutex_lock(&partition_share->pt_handler_mutex);
615/*
616 if (partition_share->partition_handler_share == partition_handler_share)
617 partition_share->partition_handler_share = NULL;
618*/
619#ifdef HASH_UPDATE_WITH_HASH_VALUE
620 my_hash_delete_with_hash_value(&partition_share->pt_handler_hash,
621 partition_handler_share->table_hash_value,
622 (uchar*) partition_handler_share);
623#else
624 my_hash_delete(&partition_share->pt_handler_hash,
625 (uchar*) partition_handler_share);
626#endif
627 pthread_mutex_unlock(&partition_share->pt_handler_mutex);
628 pt_handler_mutex = FALSE;
629 }
630error_hash_insert:
631 partition_handler_share = NULL;
632 pt_handler_share_creator = NULL;
633#endif
634 if (searched_bitmap)
635 {
636 spider_free(spider_current_trx, searched_bitmap, MYF(0));
637 searched_bitmap = NULL;
638 }
639error_searched_bitmap_alloc:
640#ifdef WITH_PARTITION_STORAGE_ENGINE
641 if (pt_handler_mutex)
642 pthread_mutex_unlock(&partition_share->pt_handler_mutex);
643#endif
644 spider_free_share(share);
645 share = NULL;
646error_get_share:
647 if (conn_keys)
648 {
649 spider_free(spider_current_trx, conn_keys, MYF(0));
650 conn_keys = NULL;
651 }
652 DBUG_RETURN(error_num);
653}
654
655int ha_spider::close()
656{
657 int error_num = 0, roop_count, error_num2;
658 THD *thd = ha_thd();
659#ifdef WITH_PARTITION_STORAGE_ENGINE
660 SPIDER_PARTITION_SHARE *partition_share;
661#endif
662 backup_error_status();
663 DBUG_ENTER("ha_spider::close");
664 DBUG_PRINT("info",("spider this=%p", this));
665
666#ifdef HA_MRR_USE_DEFAULT_IMPL
667 if (multi_range_keys)
668 {
669 DBUG_PRINT("info",("spider free multi_range_keys=%p", multi_range_keys));
670 spider_free(spider_current_trx, multi_range_keys, MYF(0));
671 multi_range_keys = NULL;
672 }
673 if (mrr_key_buff)
674 {
675 delete [] mrr_key_buff;
676 mrr_key_buff = NULL;
677 }
678#endif
679#ifdef HA_CAN_BULK_ACCESS
680 if (bulk_access_link_first)
681 {
682 do {
683 DBUG_PRINT("info",("spider bulk_access_link->spider=%p",
684 bulk_access_link_first->spider));
685 DBUG_PRINT("info",("spider bulk_access_link->spider->dbton_handler=%p",
686 bulk_access_link_first->spider->dbton_handler));
687 DBUG_PRINT("info",("spider ptr bulk_access_link->spider->dbton_handler=%p",
688 &bulk_access_link_first->spider->dbton_handler));
689 bulk_access_link_current = bulk_access_link_first->next;
690 delete_bulk_access_link(bulk_access_link_first);
691 bulk_access_link_first = bulk_access_link_current;
692 } while (bulk_access_link_first);
693 }
694#endif
695#ifdef HANDLER_HAS_DIRECT_AGGREGATE
696 while (direct_aggregate_item_first)
697 {
698 direct_aggregate_item_current = direct_aggregate_item_first->next;
699 if (direct_aggregate_item_first->item)
700 {
701 delete direct_aggregate_item_first->item;
702 }
703 spider_free(spider_current_trx, direct_aggregate_item_first, MYF(0));
704 direct_aggregate_item_first = direct_aggregate_item_current;
705 }
706#endif
707 if (is_clone)
708 {
709 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
710 {
711 if ((error_num2 = close_opened_handler(roop_count, FALSE)))
712 {
713 if (check_error_mode(error_num2))
714 error_num = error_num2;
715 }
716 }
717 }
718 for (roop_count = share->use_dbton_count - 1; roop_count >= 0; roop_count--)
719 {
720 uint dbton_id = share->use_dbton_ids[roop_count];
721 if (dbton_handler[dbton_id])
722 {
723 delete dbton_handler[dbton_id];
724 dbton_handler[dbton_id] = NULL;
725 }
726 }
727
728 if (!thd || !thd_get_ha_data(thd, spider_hton_ptr))
729 {
730 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
731 conns[roop_count] = NULL;
732 }
733
734 if (ft_first)
735 {
736 st_spider_ft_info *tmp_ft_info;
737 do {
738 tmp_ft_info = ft_first->next;
739 spider_free(spider_current_trx, ft_first, MYF(0));
740 ft_first = tmp_ft_info;
741 } while (ft_first);
742 }
743
744 spider_db_free_result(this, TRUE);
745 if (conn_keys)
746 {
747 spider_free(spider_current_trx, conn_keys, MYF(0));
748 conn_keys = NULL;
749 }
750#ifdef WITH_PARTITION_STORAGE_ENGINE
751 if (
752 partition_handler_share &&
753 pt_handler_share_creator == this
754 ) {
755 partition_share = share->partition_share;
756 pthread_mutex_lock(&partition_share->pt_handler_mutex);
757/*
758 if (partition_share->partition_handler_share == partition_handler_share)
759 partition_share->partition_handler_share = NULL;
760*/
761#ifdef HASH_UPDATE_WITH_HASH_VALUE
762 my_hash_delete_with_hash_value(&partition_share->pt_handler_hash,
763 partition_handler_share->table_hash_value,
764 (uchar*) partition_handler_share);
765#else
766 my_hash_delete(&partition_share->pt_handler_hash,
767 (uchar*) partition_handler_share);
768#endif
769 pthread_mutex_unlock(&partition_share->pt_handler_mutex);
770 }
771 partition_handler_share = NULL;
772 pt_handler_share_creator = NULL;
773#endif
774 if (searched_bitmap)
775 {
776 spider_free(spider_current_trx, searched_bitmap, MYF(0));
777 searched_bitmap = NULL;
778 }
779 if (blob_buff)
780 {
781 delete [] blob_buff;
782 blob_buff = NULL;
783 }
784 if (result_list.sqls)
785 {
786 delete [] result_list.sqls;
787 result_list.sqls = NULL;
788 }
789 if (result_list.insert_sqls)
790 {
791 delete [] result_list.insert_sqls;
792 result_list.insert_sqls = NULL;
793 }
794 if (result_list.update_sqls)
795 {
796 delete [] result_list.update_sqls;
797 result_list.update_sqls = NULL;
798 }
799 if (result_list.tmp_sqls)
800 {
801 delete [] result_list.tmp_sqls;
802 result_list.tmp_sqls = NULL;
803 }
804#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
805 if (result_list.hs_result_buf)
806 {
807 delete result_list.hs_result_buf;
808 result_list.hs_result_buf = NULL;
809 }
810#endif
811
812 spider_free_share(share);
813#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
814#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
815 if (hs_pushed_ret_fields)
816 {
817 spider_free(spider_current_trx, hs_pushed_ret_fields, MYF(0));
818 hs_pushed_ret_fields = NULL;
819 hs_pushed_ret_fields_size = 0;
820 }
821#endif
822#endif
823#ifdef HA_CAN_BULK_ACCESS
824/*
825 if (init_ha_mem_root)
826 {
827 free_root(&ha_mem_root, MYF(0));
828 init_ha_mem_root = FALSE;
829 }
830*/
831#endif
832 is_clone = FALSE;
833 pt_clone_source_handler = NULL;
834 share = NULL;
835 trx = NULL;
836 conns = NULL;
837
838 DBUG_RETURN(error_num);
839}
840
841int ha_spider::check_access_kind(
842 THD *thd,
843 bool write_request
844) {
845 int error_num, roop_count;
846 DBUG_ENTER("ha_spider::check_access_kind");
847 DBUG_PRINT("info",("spider this=%p", this));
848 sql_command = thd_sql_command(thd);
849 conn_kinds = 0;
850 switch (sql_command)
851 {
852#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
853 case SQLCOM_HS_READ:
854 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
855 {
856 if (!write_request)
857 {
858 DBUG_PRINT("info",("spider spider_use_hs_read=%d",
859 spider_param_use_hs_read(thd, share->use_hs_reads[roop_count])));
860 DBUG_PRINT("info",("spider use_hs_reads[%d]=%ld", roop_count,
861 share->use_hs_reads[roop_count]));
862 if (spider_param_use_hs_read(thd, share->use_hs_reads[roop_count]))
863 {
864 DBUG_PRINT("info",("spider set %d to HS_READ", roop_count));
865 conn_kinds |= SPIDER_CONN_KIND_HS_READ;
866 conn_kind[roop_count] = SPIDER_CONN_KIND_HS_READ;
867 } else {
868 conn_kinds |= SPIDER_CONN_KIND_MYSQL;
869 conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL;
870 }
871 } else if (share->hs_write_to_reads[roop_count])
872 {
873 DBUG_PRINT("info",("spider spider_use_hs_write=%d",
874 spider_param_use_hs_write(thd, share->use_hs_writes[roop_count])));
875 DBUG_PRINT("info",("spider use_hs_write[%d]=%ld", roop_count,
876 share->use_hs_writes[roop_count]));
877 if (spider_param_use_hs_write(thd, share->use_hs_writes[roop_count]))
878 {
879 DBUG_PRINT("info",("spider set %d to HS_WRITE", roop_count));
880 conn_kinds |= SPIDER_CONN_KIND_HS_READ;
881 conn_kind[roop_count] = SPIDER_CONN_KIND_HS_READ;
882 } else {
883 conn_kinds |= SPIDER_CONN_KIND_MYSQL;
884 conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL;
885 }
886 } else {
887 DBUG_PRINT("info",("spider spider_use_hs_write=%d",
888 spider_param_use_hs_write(thd, share->use_hs_writes[roop_count])));
889 DBUG_PRINT("info",("spider use_hs_write[%d]=%ld", roop_count,
890 share->use_hs_writes[roop_count]));
891 if (spider_param_use_hs_write(thd, share->use_hs_writes[roop_count]))
892 {
893 DBUG_PRINT("info",("spider set %d to HS_WRITE", roop_count));
894 conn_kinds |= SPIDER_CONN_KIND_HS_WRITE;
895 conn_kind[roop_count] = SPIDER_CONN_KIND_HS_WRITE;
896 } else {
897 conn_kinds |= SPIDER_CONN_KIND_MYSQL;
898 conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL;
899 }
900 }
901 }
902 break;
903 case SQLCOM_HS_UPDATE:
904 case SQLCOM_HS_DELETE:
905 conn_kinds |= SPIDER_CONN_KIND_MYSQL;
906 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
907 {
908 conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL;
909 }
910 break;
911 case SQLCOM_HS_INSERT:
912 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
913 {
914 DBUG_PRINT("info",("spider spider_use_hs_write=%d",
915 spider_param_use_hs_write(thd, share->use_hs_writes[roop_count])));
916 DBUG_PRINT("info",("spider use_hs_write[%d]=%ld", roop_count,
917 share->use_hs_writes[roop_count]));
918 if (spider_param_use_hs_write(thd, share->use_hs_writes[roop_count]))
919 {
920 DBUG_PRINT("info",("spider set %d to HS_WRITE", roop_count));
921 conn_kinds |= SPIDER_CONN_KIND_HS_WRITE;
922 conn_kind[roop_count] = SPIDER_CONN_KIND_HS_WRITE;
923 } else {
924 conn_kinds |= SPIDER_CONN_KIND_MYSQL;
925 conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL;
926 }
927 }
928 break;
929#endif
930 case SQLCOM_UPDATE:
931 case SQLCOM_UPDATE_MULTI:
932 case SQLCOM_DELETE:
933 case SQLCOM_DELETE_MULTI:
934 default:
935 conn_kinds |= SPIDER_CONN_KIND_MYSQL;
936 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
937 {
938 conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL;
939 }
940 break;
941 }
942#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
943 if ((error_num = reset_hs_strs_pos(SPIDER_SQL_TYPE_UPDATE_HS)))
944 {
945 DBUG_RETURN(error_num);
946 }
947#endif
948 if ((error_num = spider_check_trx_and_get_conn(thd, this, TRUE)))
949 {
950 DBUG_RETURN(error_num);
951 }
952 DBUG_PRINT("info",("spider sql_command=%u", sql_command));
953 DBUG_PRINT("info",("spider thd->query_id=%lld", thd->query_id));
954#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
955#ifdef HS_HAS_SQLCOM
956 if (sql_command == SQLCOM_HS_UPDATE)
957 update_request = TRUE;
958 else
959#endif
960 update_request = FALSE;
961#else
962 if (
963#ifdef HS_HAS_SQLCOM
964 sql_command == SQLCOM_HS_UPDATE ||
965#endif
966 sql_command == SQLCOM_UPDATE ||
967 sql_command == SQLCOM_UPDATE_MULTI ||
968 /* for triggers */
969 sql_command == SQLCOM_INSERT ||
970 sql_command == SQLCOM_INSERT_SELECT ||
971 sql_command == SQLCOM_DELETE ||
972 sql_command == SQLCOM_DELETE_MULTI
973 )
974 update_request = TRUE;
975 else
976 update_request = FALSE;
977#endif
978 DBUG_RETURN(0);
979}
980
981#ifdef HA_CAN_BULK_ACCESS
982int ha_spider::additional_lock(
983 THD *thd,
984 enum thr_lock_type lock_type
985) {
986 DBUG_ENTER("ha_spider::additional_lock");
987 DBUG_PRINT("info",("spider this=%p", this));
988 if (bulk_access_executing)
989 {
990 if (is_bulk_access_clone)
991 {
992 DBUG_RETURN(check_access_kind(thd, (lock_type >= TL_WRITE_ALLOW_WRITE)));
993 } else if (bulk_access_link_exec_tgt->called)
994 {
995 DBUG_RETURN(bulk_access_link_exec_tgt->spider->check_access_kind(
996 thd, (lock_type >= TL_WRITE_ALLOW_WRITE)));
997 }
998 }
999 DBUG_RETURN(check_access_kind(thd, (lock_type >= TL_WRITE_ALLOW_WRITE)));
1000}
1001#endif
1002
1003THR_LOCK_DATA **ha_spider::store_lock(
1004 THD *thd,
1005 THR_LOCK_DATA **to,
1006 enum thr_lock_type lock_type
1007) {
1008 int error_num, roop_count;
1009 DBUG_ENTER("ha_spider::store_lock");
1010 DBUG_PRINT("info",("spider this=%p", this));
1011 if (lock_type == TL_IGNORE)
1012 {
1013 *to++ = &lock;
1014 DBUG_RETURN(to);
1015 }
1016 if ((error_num = check_access_kind(thd,
1017 (lock_type >= TL_WRITE_ALLOW_WRITE))))
1018 {
1019 store_error_num = error_num;
1020 DBUG_RETURN(to);
1021 }
1022 DBUG_PRINT("info",("spider sql_command=%u", sql_command));
1023 DBUG_PRINT("info",("spider lock_type=%d", lock_type));
1024 DBUG_PRINT("info",("spider thd->query_id=%lld", thd->query_id));
1025 if (sql_command == SQLCOM_ALTER_TABLE)
1026 {
1027 if (trx->query_id != thd->query_id)
1028 {
1029 spider_free_trx_alter_table(trx);
1030 trx->query_id = thd->query_id;
1031 trx->tmp_flg = FALSE;
1032 }
1033 if (!(SPIDER_ALTER_TABLE*) my_hash_search(&trx->trx_alter_table_hash,
1034 (uchar*) share->table_name, share->table_name_length))
1035 {
1036 if (spider_create_trx_alter_table(trx, share, FALSE))
1037 {
1038 store_error_num = HA_ERR_OUT_OF_MEM;
1039 DBUG_RETURN(to);
1040 }
1041 }
1042 }
1043
1044 this->lock_type = lock_type;
1045 selupd_lock_mode = spider_param_selupd_lock_mode(thd,
1046 share->selupd_lock_mode);
1047 if (
1048 sql_command != SQLCOM_DROP_TABLE &&
1049 sql_command != SQLCOM_ALTER_TABLE
1050 ) {
1051 SPIDER_SET_CONNS_PARAM(semi_trx_chk, FALSE, conns, share->link_statuses,
1052 conn_link_idx, (int) share->link_count, SPIDER_LINK_STATUS_RECOVERY);
1053 }
1054 switch (sql_command)
1055 {
1056 case SQLCOM_SELECT:
1057 case SQLCOM_HA_READ:
1058#ifdef HS_HAS_SQLCOM
1059 case SQLCOM_HS_READ:
1060#endif
1061 if (lock_type == TL_READ_WITH_SHARED_LOCKS)
1062 lock_mode = 1;
1063 else if (lock_type <= TL_READ_NO_INSERT)
1064 {
1065 lock_mode = 0;
1066 SPIDER_SET_CONNS_PARAM(semi_trx_isolation_chk, TRUE, conns,
1067 share->link_statuses, conn_link_idx, (int) share->link_count,
1068 SPIDER_LINK_STATUS_RECOVERY);
1069 } else
1070 lock_mode = -1;
1071 SPIDER_SET_CONNS_PARAM(semi_trx_chk, TRUE, conns, share->link_statuses,
1072 conn_link_idx, (int) share->link_count, SPIDER_LINK_STATUS_RECOVERY);
1073 break;
1074 case SQLCOM_UPDATE:
1075 case SQLCOM_UPDATE_MULTI:
1076#ifdef HS_HAS_SQLCOM
1077 case SQLCOM_HS_UPDATE:
1078#endif
1079 case SQLCOM_CREATE_TABLE:
1080 case SQLCOM_INSERT:
1081 case SQLCOM_INSERT_SELECT:
1082 case SQLCOM_DELETE:
1083 case SQLCOM_LOAD:
1084 case SQLCOM_REPLACE:
1085 case SQLCOM_REPLACE_SELECT:
1086 case SQLCOM_DELETE_MULTI:
1087#ifdef HS_HAS_SQLCOM
1088 case SQLCOM_HS_INSERT:
1089 case SQLCOM_HS_DELETE:
1090#endif
1091 if (lock_type >= TL_READ && lock_type <= TL_READ_NO_INSERT)
1092 {
1093 lock_mode = selupd_lock_mode;
1094 SPIDER_SET_CONNS_PARAM(semi_trx_isolation_chk, TRUE, conns,
1095 share->link_statuses, conn_link_idx, (int) share->link_count,
1096 SPIDER_LINK_STATUS_RECOVERY);
1097 } else
1098 lock_mode = -1;
1099 SPIDER_SET_CONNS_PARAM(semi_trx_chk, TRUE, conns, share->link_statuses,
1100 conn_link_idx, (int) share->link_count, SPIDER_LINK_STATUS_RECOVERY);
1101 break;
1102 default:
1103 lock_mode = -1;
1104 }
1105 switch (lock_type)
1106 {
1107 case TL_READ_HIGH_PRIORITY:
1108 high_priority = TRUE;
1109 break;
1110 case TL_WRITE_DELAYED:
1111 insert_delayed = TRUE;
1112 break;
1113 case TL_WRITE_LOW_PRIORITY:
1114 low_priority = TRUE;
1115 break;
1116 default:
1117 break;
1118 }
1119
1120 if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK)
1121 {
1122 if (
1123 sql_command == SQLCOM_DROP_TABLE ||
1124 sql_command == SQLCOM_ALTER_TABLE ||
1125 sql_command == SQLCOM_SHOW_CREATE
1126 ) {
1127 if (
1128 lock_type == TL_READ_NO_INSERT &&
1129 !thd->in_lock_tables
1130 )
1131 lock_type = TL_READ;
1132 if (
1133 lock_type >= TL_WRITE_CONCURRENT_INSERT && lock_type <= TL_WRITE &&
1134 !thd->in_lock_tables && !thd_tablespace_op(thd)
1135 )
1136 lock_type = TL_WRITE_ALLOW_WRITE;
1137 } else if (
1138 sql_command == SQLCOM_LOCK_TABLES ||
1139 (spider_param_lock_exchange(thd) == 1 && share->semi_table_lock))
1140 {
1141 DBUG_PRINT("info",("spider lock exchange route"));
1142 DBUG_PRINT("info",("spider lock_type=%u", this->lock_type));
1143 if (
1144 (
1145 this->lock_type == TL_READ ||
1146 this->lock_type == TL_READ_NO_INSERT ||
1147 this->lock_type == TL_WRITE_LOW_PRIORITY ||
1148 this->lock_type == TL_WRITE
1149 ) &&
1150 !spider_param_local_lock_table(thd)
1151 ) {
1152 for (
1153 roop_count = spider_conn_link_idx_next(share->link_statuses,
1154 conn_link_idx, -1, share->link_count,
1155 SPIDER_LINK_STATUS_RECOVERY);
1156 roop_count < (int) share->link_count;
1157 roop_count = spider_conn_link_idx_next(share->link_statuses,
1158 conn_link_idx, roop_count, share->link_count,
1159 SPIDER_LINK_STATUS_RECOVERY)
1160 ) {
1161 SPIDER_CONN *conn = conns[roop_count];
1162 int appended = 0;
1163 if ((error_num = dbton_handler[conn->dbton_id]->
1164 append_lock_tables_list(conn, roop_count, &appended)))
1165 {
1166 store_error_num = error_num;
1167 DBUG_RETURN(to);
1168 }
1169 if (appended)
1170 {
1171 conn->table_lock = 2;
1172 }
1173 }
1174 }
1175 } else {
1176 DBUG_PRINT("info",("spider default lock route"));
1177 DBUG_PRINT("info",("spider lock_type=%u", this->lock_type));
1178 if (
1179 this->lock_type == TL_READ ||
1180 this->lock_type == TL_READ_NO_INSERT ||
1181 this->lock_type == TL_WRITE_LOW_PRIORITY ||
1182 this->lock_type == TL_WRITE
1183 ) {
1184 for (
1185 roop_count = spider_conn_link_idx_next(share->link_statuses,
1186 conn_link_idx, -1, share->link_count,
1187 SPIDER_LINK_STATUS_RECOVERY);
1188 roop_count < (int) share->link_count;
1189 roop_count = spider_conn_link_idx_next(share->link_statuses,
1190 conn_link_idx, roop_count, share->link_count,
1191 SPIDER_LINK_STATUS_RECOVERY)
1192 ) {
1193 if (
1194 conns[roop_count] &&
1195 conns[roop_count]->table_lock != 1 &&
1196 spider_param_semi_table_lock(thd, share->semi_table_lock) &&
1197 !spider_param_local_lock_table(thd)
1198 ) {
1199 SPIDER_CONN *conn = conns[roop_count];
1200 int appended = 0;
1201 if ((error_num = dbton_handler[conn->dbton_id]->
1202 append_lock_tables_list(conn, roop_count, &appended)))
1203 {
1204 store_error_num = error_num;
1205 DBUG_RETURN(to);
1206 }
1207 if (appended)
1208 {
1209 conn->table_lock = 3;
1210 }
1211 }
1212 }
1213 }
1214 if (
1215 lock_type == TL_READ_NO_INSERT &&
1216 !thd->in_lock_tables
1217 )
1218 lock_type = TL_READ;
1219 if (
1220 lock_type >= TL_WRITE_CONCURRENT_INSERT && lock_type <= TL_WRITE &&
1221 lock_type != TL_WRITE_DELAYED &&
1222 !thd->in_lock_tables && !thd_tablespace_op(thd)
1223 )
1224 lock_type = TL_WRITE_ALLOW_WRITE;
1225 }
1226 lock.type = lock_type;
1227 }
1228 *to++ = &lock;
1229 DBUG_RETURN(to);
1230}
1231
1232int ha_spider::external_lock(
1233 THD *thd,
1234 int lock_type
1235) {
1236 int error_num, roop_count;
1237 bool sync_trx_isolation = spider_param_sync_trx_isolation(thd);
1238 backup_error_status();
1239 DBUG_ENTER("ha_spider::external_lock");
1240 DBUG_PRINT("info",("spider this=%p", this));
1241 DBUG_PRINT("info",("spider lock_type=%x", lock_type));
1242#if MYSQL_VERSION_ID < 50500
1243 DBUG_PRINT("info",("spider thd->options=%x", (int) thd->options));
1244#endif
1245#ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC
1246 info_auto_called = FALSE;
1247#endif
1248
1249 sql_command = thd_sql_command(thd);
1250 if (sql_command == SQLCOM_BEGIN)
1251 sql_command = SQLCOM_UNLOCK_TABLES;
1252 if (
1253 sql_command == SQLCOM_UNLOCK_TABLES &&
1254 (error_num = spider_check_trx_and_get_conn(thd, this,
1255 FALSE))
1256 ) {
1257 DBUG_RETURN(error_num);
1258 }
1259
1260 DBUG_PRINT("info",("spider sql_command=%d", sql_command));
1261 DBUG_ASSERT(trx == spider_get_trx(thd, TRUE, &error_num));
1262#ifdef HA_CAN_BULK_ACCESS
1263 external_lock_cnt++;
1264#endif
1265 if (
1266 lock_type == F_UNLCK &&
1267 sql_command != SQLCOM_UNLOCK_TABLES
1268 )
1269 DBUG_RETURN(0);
1270 if (store_error_num)
1271 DBUG_RETURN(store_error_num);
1272#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1273 if ((conn_kinds & SPIDER_CONN_KIND_MYSQL))
1274 {
1275#endif
1276 if (
1277 /* SQLCOM_RENAME_TABLE and SQLCOM_DROP_DB don't come here */
1278 sql_command == SQLCOM_DROP_TABLE ||
1279 sql_command == SQLCOM_ALTER_TABLE
1280 ) {
1281 if (trx->locked_connections)
1282 {
1283 my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM,
1284 ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0));
1285 DBUG_RETURN(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM);
1286 }
1287 DBUG_RETURN(0);
1288 }
1289 if (!conns[search_link_idx])
1290 {
1291 my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM,
1292 ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0));
1293 DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM);
1294 }
1295 for (
1296 roop_count = spider_conn_link_idx_next(share->link_statuses,
1297 conn_link_idx, -1, share->link_count,
1298 SPIDER_LINK_STATUS_RECOVERY);
1299 roop_count < (int) share->link_count;
1300 roop_count = spider_conn_link_idx_next(share->link_statuses,
1301 conn_link_idx, roop_count, share->link_count,
1302 SPIDER_LINK_STATUS_RECOVERY)
1303 ) {
1304 if (sql_command == SQLCOM_TRUNCATE)
1305 DBUG_RETURN(0);
1306 else if (sql_command != SQLCOM_UNLOCK_TABLES)
1307 {
1308 DBUG_PRINT("info",("spider conns[%d]->join_trx=%u",
1309 roop_count, conns[roop_count]->join_trx));
1310 if (
1311 (!conns[roop_count]->join_trx &&
1312 (error_num = spider_internal_start_trx(this, conns[roop_count],
1313 roop_count)))
1314 ) {
1315 if (
1316 share->monitoring_kind[roop_count] &&
1317 need_mons[roop_count]
1318 ) {
1319 error_num = spider_ping_table_mon_from_table(
1320 trx,
1321 trx->thd,
1322 share,
1323 roop_count,
1324 (uint32) share->monitoring_sid[roop_count],
1325 share->table_name,
1326 share->table_name_length,
1327 conn_link_idx[roop_count],
1328 NULL,
1329 0,
1330 share->monitoring_kind[roop_count],
1331 share->monitoring_limit[roop_count],
1332 share->monitoring_flag[roop_count],
1333 TRUE
1334 );
1335 }
1336 DBUG_RETURN(check_error_mode(error_num));
1337 }
1338 result_list.lock_type = lock_type;
1339 reset_first_link_idx();
1340 if (
1341 conns[roop_count]->semi_trx_isolation == -2 &&
1342 conns[roop_count]->semi_trx_isolation_chk == TRUE &&
1343 sync_trx_isolation &&
1344 spider_param_semi_trx_isolation(trx->thd) >= 0
1345 ) {
1346/*
1347 if (conns[roop_count]->trx_isolation !=
1348 spider_param_semi_trx_isolation(trx->thd))
1349 {
1350*/
1351 spider_conn_queue_semi_trx_isolation(conns[roop_count],
1352 spider_param_semi_trx_isolation(trx->thd));
1353/*
1354 }
1355 conns[roop_count]->semi_trx_isolation =
1356 spider_param_semi_trx_isolation(trx->thd);
1357 conns[roop_count]->trx_isolation =
1358 thd_tx_isolation(conns[roop_count]->thd);
1359 DBUG_PRINT("info",("spider conn=%p", conns[roop_count]));
1360 DBUG_PRINT("info",("spider conn->trx_isolation=%d",
1361 conns[roop_count]->trx_isolation));
1362*/
1363 } else {
1364 if (sync_trx_isolation)
1365 {
1366 if ((error_num = spider_check_and_set_trx_isolation(
1367 conns[roop_count], &need_mons[roop_count])))
1368 {
1369 if (
1370 share->monitoring_kind[roop_count] &&
1371 need_mons[roop_count]
1372 ) {
1373 error_num = spider_ping_table_mon_from_table(
1374 trx,
1375 trx->thd,
1376 share,
1377 roop_count,
1378 (uint32) share->monitoring_sid[roop_count],
1379 share->table_name,
1380 share->table_name_length,
1381 conn_link_idx[roop_count],
1382 NULL,
1383 0,
1384 share->monitoring_kind[roop_count],
1385 share->monitoring_limit[roop_count],
1386 share->monitoring_flag[roop_count],
1387 TRUE
1388 );
1389 }
1390 DBUG_RETURN(check_error_mode(error_num));
1391 }
1392 }
1393 conns[roop_count]->semi_trx_isolation = -1;
1394 }
1395 }
1396 if (conns[roop_count]->table_lock >= 2)
1397 {
1398 if (
1399 conns[roop_count]->db_conn->have_lock_table_list() &&
1400 (error_num = spider_db_lock_tables(this, roop_count))
1401 ) {
1402 if (
1403 share->monitoring_kind[roop_count] &&
1404 need_mons[roop_count]
1405 ) {
1406 error_num = spider_ping_table_mon_from_table(
1407 trx,
1408 trx->thd,
1409 share,
1410 roop_count,
1411 (uint32) share->monitoring_sid[roop_count],
1412 share->table_name,
1413 share->table_name_length,
1414 conn_link_idx[roop_count],
1415 NULL,
1416 0,
1417 share->monitoring_kind[roop_count],
1418 share->monitoring_limit[roop_count],
1419 share->monitoring_flag[roop_count],
1420 TRUE
1421 );
1422 }
1423 conns[roop_count]->table_lock = 0;
1424 DBUG_RETURN(check_error_mode(error_num));
1425 }
1426 if (conns[roop_count]->table_lock == 2)
1427 conns[roop_count]->table_lock = 1;
1428 } else if (sql_command == SQLCOM_UNLOCK_TABLES ||
1429 spider_param_internal_unlock(thd) == 1)
1430 {
1431 if (conns[roop_count]->table_lock == 1)
1432 {
1433 conns[roop_count]->table_lock = 0;
1434 if (!conns[roop_count]->trx_start)
1435 conns[roop_count]->disable_reconnect = FALSE;
1436 if ((error_num = spider_db_unlock_tables(this, roop_count)))
1437 {
1438 if (
1439 share->monitoring_kind[roop_count] &&
1440 need_mons[roop_count]
1441 ) {
1442 error_num = spider_ping_table_mon_from_table(
1443 trx,
1444 trx->thd,
1445 share,
1446 roop_count,
1447 (uint32) share->monitoring_sid[roop_count],
1448 share->table_name,
1449 share->table_name_length,
1450 conn_link_idx[roop_count],
1451 NULL,
1452 0,
1453 share->monitoring_kind[roop_count],
1454 share->monitoring_limit[roop_count],
1455 share->monitoring_flag[roop_count],
1456 TRUE
1457 );
1458 }
1459 DBUG_RETURN(check_error_mode(error_num));
1460 }
1461 }
1462 }
1463 }
1464#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1465 } else {
1466 result_list.lock_type = lock_type;
1467 reset_first_link_idx();
1468 trans_register_ha(trx->thd, FALSE, spider_hton_ptr);
1469 if (thd_test_options(trx->thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
1470 trans_register_ha(trx->thd, TRUE, spider_hton_ptr);
1471 }
1472
1473 if ((conn_kinds & SPIDER_CONN_KIND_HS_READ))
1474 {
1475 SPIDER_CONN *hs_conn;
1476 for (
1477 roop_count = spider_conn_link_idx_next(share->link_statuses,
1478 conn_link_idx, -1, share->link_count,
1479 SPIDER_LINK_STATUS_RECOVERY);
1480 roop_count < (int) share->link_count;
1481 roop_count = spider_conn_link_idx_next(share->link_statuses,
1482 conn_link_idx, roop_count, share->link_count,
1483 SPIDER_LINK_STATUS_RECOVERY)
1484 ) {
1485 hs_conn = hs_r_conns[roop_count];
1486 if (
1487 hs_conn &&
1488 hs_conn->hsc_query_id != thd->query_id &&
1489 hs_conn->hs_pre_age == hs_conn->hs_age
1490 ) {
1491 double interval = spider_param_hs_ping_interval(thd);
1492 time_t tmp_time = (time_t) time((time_t*) 0);
1493 DBUG_PRINT("info",
1494 ("spider difftime=%f", difftime(tmp_time, hs_conn->ping_time)));
1495 DBUG_PRINT("info", ("spider interval=%f", interval));
1496 if (
1497 hs_conn->server_lost ||
1498 difftime(tmp_time, hs_conn->ping_time) >= interval
1499 ) {
1500 DBUG_PRINT("info", ("spider hsr[%d] need reconnect", roop_count));
1501 hs_conn->hs_pre_age++;
1502 hs_conn->ping_time = tmp_time;
1503 }
1504 hs_conn->hsc_query_id = thd->query_id;
1505 }
1506 }
1507 }
1508 if (
1509#if defined(HS_HAS_SQLCOM) && defined(HANDLER_HAS_DIRECT_UPDATE_ROWS)
1510 (
1511#endif
1512 conn_kinds & SPIDER_CONN_KIND_HS_WRITE
1513#if defined(HS_HAS_SQLCOM) && defined(HANDLER_HAS_DIRECT_UPDATE_ROWS)
1514 ) ||
1515 /* for direct_update */
1516 sql_command == SQLCOM_HS_UPDATE ||
1517 sql_command == SQLCOM_HS_DELETE
1518#endif
1519 ) {
1520 SPIDER_CONN *hs_conn;
1521 for (
1522 roop_count = spider_conn_link_idx_next(share->link_statuses,
1523 conn_link_idx, -1, share->link_count,
1524 SPIDER_LINK_STATUS_RECOVERY);
1525 roop_count < (int) share->link_count;
1526 roop_count = spider_conn_link_idx_next(share->link_statuses,
1527 conn_link_idx, roop_count, share->link_count,
1528 SPIDER_LINK_STATUS_RECOVERY)
1529 ) {
1530 hs_conn = hs_w_conns[roop_count];
1531 if (
1532 hs_conn &&
1533 hs_conn->hsc_query_id != thd->query_id &&
1534 hs_conn->hs_pre_age == hs_conn->hs_age
1535 ) {
1536 double interval = spider_param_hs_ping_interval(thd);
1537 time_t tmp_time = (time_t) time((time_t*) 0);
1538 DBUG_PRINT("info",
1539 ("spider difftime=%f", difftime(tmp_time, hs_conn->ping_time)));
1540 DBUG_PRINT("info", ("spider interval=%f", interval));
1541 if (
1542 hs_conn->server_lost ||
1543 difftime(tmp_time, hs_conn->ping_time) >= interval
1544 ) {
1545 DBUG_PRINT("info", ("spider hsw[%d] need reconnect", roop_count));
1546 hs_conn->hs_pre_age++;
1547 hs_conn->ping_time = tmp_time;
1548 }
1549 hs_conn->hsc_query_id = thd->query_id;
1550 }
1551 }
1552 }
1553#endif
1554
1555 DBUG_PRINT("info",("spider trx_start=%s", trx->trx_start ? "TRUE" : "FALSE"));
1556 /* need to check after spider_internal_start_trx() */
1557 if (trx->trx_start)
1558 {
1559 switch (sql_command)
1560 {
1561 case SQLCOM_SELECT:
1562 case SQLCOM_HA_READ:
1563#ifdef HS_HAS_SQLCOM
1564 case SQLCOM_HS_READ:
1565#endif
1566 /* nothing to do */
1567 break;
1568 case SQLCOM_UPDATE:
1569 case SQLCOM_UPDATE_MULTI:
1570#ifdef HS_HAS_SQLCOM
1571 case SQLCOM_HS_UPDATE:
1572#endif
1573 case SQLCOM_CREATE_TABLE:
1574 case SQLCOM_INSERT:
1575 case SQLCOM_INSERT_SELECT:
1576 case SQLCOM_DELETE:
1577 case SQLCOM_LOAD:
1578 case SQLCOM_REPLACE:
1579 case SQLCOM_REPLACE_SELECT:
1580 case SQLCOM_DELETE_MULTI:
1581#ifdef HS_HAS_SQLCOM
1582 case SQLCOM_HS_INSERT:
1583 case SQLCOM_HS_DELETE:
1584#endif
1585 default:
1586 trx->updated_in_this_trx = TRUE;
1587 DBUG_PRINT("info",("spider trx->updated_in_this_trx=TRUE"));
1588 break;
1589 }
1590 }
1591 DBUG_RETURN(0);
1592}
1593
1594int ha_spider::reset()
1595{
1596 int error_num = 0, error_num2, roop_count;
1597 THD *thd = ha_thd();
1598 SPIDER_TRX *tmp_trx, *trx_bak;
1599 SPIDER_CONDITION *tmp_cond;
1600/*
1601 char first_byte, first_byte_bak;
1602*/
1603 backup_error_status();
1604 DBUG_ENTER("ha_spider::reset");
1605 DBUG_PRINT("info",("spider this=%p", this));
1606#ifdef HA_CAN_BULK_ACCESS
1607 SPIDER_BULK_ACCESS_LINK *tmp_bulk_access_link = bulk_access_link_first;
1608 while (tmp_bulk_access_link)
1609 {
1610 DBUG_PRINT("info",("spider bulk_access_link->spider->dbton_handler=%p",
1611 tmp_bulk_access_link->spider->dbton_handler));
1612 DBUG_PRINT("info",("spider ptr bulk_access_link->spider->dbton_handler=%p",
1613 &tmp_bulk_access_link->spider->dbton_handler));
1614 if (!tmp_bulk_access_link->used)
1615 break;
1616 if ((error_num2 = tmp_bulk_access_link->spider->ha_reset()))
1617 error_num = error_num2;
1618 tmp_bulk_access_link->used = FALSE;
1619 tmp_bulk_access_link = tmp_bulk_access_link->next;
1620 }
1621 synced_from_clone_source = FALSE;
1622 bulk_access_started = FALSE;
1623 bulk_access_executing = FALSE;
1624 bulk_access_pre_called = FALSE;
1625 if (
1626 bulk_access_link_first &&
1627 !spider_param_bulk_access_free(share->bulk_access_free)
1628 ) {
1629 do {
1630 DBUG_PRINT("info",("spider bulk_access_link->spider->dbton_handler=%p",
1631 bulk_access_link_first->spider->dbton_handler));
1632 DBUG_PRINT("info",("spider ptr bulk_access_link->spider->dbton_handler=%p",
1633 &bulk_access_link_first->spider->dbton_handler));
1634 bulk_access_link_current = bulk_access_link_first->next;
1635 delete_bulk_access_link(bulk_access_link_first);
1636 bulk_access_link_first = bulk_access_link_current;
1637 } while (bulk_access_link_first);
1638 }
1639#endif
1640#ifdef HANDLER_HAS_DIRECT_AGGREGATE
1641 direct_aggregate_item_current = direct_aggregate_item_first;
1642 while (direct_aggregate_item_current)
1643 {
1644 if (direct_aggregate_item_current->item)
1645 {
1646 delete direct_aggregate_item_current->item;
1647 direct_aggregate_item_current->item = NULL;
1648#ifdef SPIDER_ITEM_STRING_WITHOUT_SET_STR_WITH_COPY_AND_THDPTR
1649 if (direct_aggregate_item_current->init_mem_root)
1650 {
1651 free_root(&direct_aggregate_item_current->mem_root, MYF(0));
1652 direct_aggregate_item_current->init_mem_root = FALSE;
1653 }
1654#endif
1655 }
1656 direct_aggregate_item_current = direct_aggregate_item_current->next;
1657 }
1658 result_list.direct_aggregate = FALSE;
1659 result_list.snap_direct_aggregate = FALSE;
1660#endif
1661 result_list.direct_distinct = FALSE;
1662 store_error_num = 0;
1663#ifdef WITH_PARTITION_STORAGE_ENGINE
1664 if (
1665 partition_handler_share &&
1666 partition_handler_share->searched_bitmap
1667 ) {
1668 if (!is_clone)
1669 {
1670 partition_handler_share->searched_bitmap = NULL;
1671 partition_handler_share->ft_discard_bitmap = NULL;
1672 }
1673 partition_handler_share->between_flg = FALSE;
1674 partition_handler_share->idx_bitmap_is_set = FALSE;
1675 partition_handler_share->rnd_bitmap_is_set = FALSE;
1676 }
1677#endif
1678 if (!is_clone)
1679 {
1680 memset(ft_discard_bitmap, 0xFF, no_bytes_in_map(table->read_set));
1681 memset(searched_bitmap, 0, no_bytes_in_map(table->read_set));
1682 }
1683 if (!(tmp_trx = spider_get_trx(thd, TRUE, &error_num2)))
1684 {
1685 DBUG_PRINT("info",("spider get trx error"));
1686 if (check_error_mode(error_num2))
1687 error_num = error_num2;
1688 }
1689 if (share)
1690 {
1691 trx_bak = trx;
1692 trx = tmp_trx;
1693 if ((error_num2 = spider_db_free_result(this, FALSE)))
1694 error_num = error_num2;
1695 trx = trx_bak;
1696/*
1697 int semi_table_lock_conn = spider_param_semi_table_lock_connection(thd,
1698 share->semi_table_lock_conn);
1699 if (semi_table_lock_conn)
1700 first_byte = '0' +
1701 spider_param_semi_table_lock(thd, share->semi_table_lock);
1702 else
1703 first_byte = '0';
1704 DBUG_PRINT("info",("spider semi_table_lock_conn = %d",
1705 semi_table_lock_conn));
1706 DBUG_PRINT("info",("spider semi_table_lock = %d",
1707 spider_param_semi_table_lock(thd, share->semi_table_lock)));
1708 DBUG_PRINT("info",("spider first_byte = %d", first_byte));
1709 if (tmp_trx->spider_thread_id != spider_thread_id ||
1710 (tmp_trx->trx_conn_adjustment != trx_conn_adjustment &&
1711 tmp_trx->trx_conn_adjustment - 1 != trx_conn_adjustment) ||
1712 first_byte != *conn_keys[0]
1713 ) {
1714 DBUG_PRINT("info",(first_byte != *conn_keys[0] ?
1715 "spider change conn type" : tmp_trx != trx ? "spider change thd" :
1716 "spider next trx"));
1717 trx = tmp_trx;
1718 spider_thread_id = tmp_trx->spider_thread_id;
1719 trx_conn_adjustment = tmp_trx->trx_conn_adjustment;
1720
1721 first_byte_bak = *conn_keys[0];
1722 *conn_keys[0] = first_byte;
1723 for (
1724 roop_count = spider_conn_link_idx_next(share->link_statuses,
1725 conn_link_idx, -1, share->link_count,
1726 SPIDER_LINK_STATUS_RECOVERY);
1727 roop_count < share->link_count;
1728 roop_count = spider_conn_link_idx_next(share->link_statuses,
1729 conn_link_idx, roop_count, share->link_count,
1730 SPIDER_LINK_STATUS_RECOVERY)
1731 ) {
1732 *conn_keys[roop_count] = first_byte;
1733 if (
1734 !(conns[roop_count] =
1735 spider_get_conn(share, roop_count, conn_keys[roop_count], trx,
1736 this, FALSE, TRUE, SPIDER_CONN_KIND_MYSQL, &error_num))
1737 ) {
1738 if (
1739 share->monitoring_kind[roop_count] &&
1740 need_mons[roop_count]
1741 ) {
1742 error_num = spider_ping_table_mon_from_table(
1743 trx,
1744 trx->thd,
1745 share,
1746 roop_count,
1747 (uint32) share->monitoring_sid[roop_count],
1748 share->table_name,
1749 share->table_name_length,
1750 conn_link_idx[roop_count],
1751 NULL,
1752 0,
1753 share->monitoring_kind[roop_count],
1754 share->monitoring_limit[roop_count],
1755 share->monitoring_flag[roop_count],
1756 TRUE
1757 );
1758 }
1759 DBUG_PRINT("info",("spider get conn error"));
1760 *conn_keys[0] = first_byte_bak;
1761 conns[0] = NULL;
1762 DBUG_RETURN(error_num);
1763 }
1764 }
1765 }
1766*/
1767 memset(need_mons, 0, sizeof(int) * share->link_count);
1768 memset(result_list.casual_read, 0, sizeof(int) * share->link_count);
1769 rm_bulk_tmp_table();
1770 for (roop_count = share->link_count - 1; roop_count >= 0; roop_count--)
1771 {
1772 result_list.update_sqls[roop_count].length(0);
1773
1774 if ((error_num2 = close_opened_handler(roop_count, TRUE)))
1775 {
1776 if (check_error_mode(error_num2))
1777 error_num = error_num2;
1778 }
1779
1780 conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL;
1781 }
1782 result_list.bulk_update_mode = 0;
1783 result_list.bulk_update_size = 0;
1784 result_list.bulk_update_start = SPD_BU_NOT_START;
1785 for (roop_count = 0; roop_count < (int) share->use_dbton_count;
1786 roop_count++)
1787 {
1788 uint dbton_id = share->use_dbton_ids[roop_count];
1789 if ((error_num2 = dbton_handler[dbton_id]->reset()))
1790 {
1791 if (check_error_mode(error_num2))
1792 error_num = error_num2;
1793 }
1794 }
1795 }
1796 quick_mode = FALSE;
1797 keyread = FALSE;
1798 ignore_dup_key = FALSE;
1799 write_can_replace = FALSE;
1800 insert_with_update = FALSE;
1801 low_priority = FALSE;
1802 high_priority = FALSE;
1803 insert_delayed = FALSE;
1804 use_pre_call = FALSE;
1805 use_pre_records = FALSE;
1806 pre_bitmap_checked = FALSE;
1807 bulk_insert = FALSE;
1808 clone_bitmap_init = FALSE;
1809 result_list.tmp_table_join = FALSE;
1810 result_list.use_union = FALSE;
1811 result_list.use_both_key = FALSE;
1812 pt_clone_last_searcher = NULL;
1813 conn_kinds = SPIDER_CONN_KIND_MYSQL;
1814 use_index_merge = FALSE;
1815 init_rnd_handler = FALSE;
1816 while (condition)
1817 {
1818 tmp_cond = condition->next;
1819 spider_free(spider_current_trx, condition, MYF(0));
1820 condition = tmp_cond;
1821 }
1822 cond_check = FALSE;
1823#ifdef HA_MRR_USE_DEFAULT_IMPL
1824 if (multi_range_keys)
1825 {
1826 DBUG_PRINT("info",("spider free multi_range_keys=%p", multi_range_keys));
1827 spider_free(spider_current_trx, multi_range_keys, MYF(0));
1828 multi_range_keys = NULL;
1829 }
1830#endif
1831 ft_handler = NULL;
1832 ft_current = NULL;
1833 ft_count = 0;
1834 ft_init_without_index_init = FALSE;
1835 sql_kinds = 0;
1836#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1837#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
1838 hs_pushed_ret_fields_num = MAX_FIELDS;
1839 hs_increment = FALSE;
1840 hs_decrement = FALSE;
1841#endif
1842#endif
1843#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
1844 do_direct_update = FALSE;
1845 direct_update_fields = NULL;
1846#endif
1847#ifdef INFO_KIND_FORCE_LIMIT_BEGIN
1848 info_limit = 9223372036854775807LL;
1849#endif
1850 prev_index_rnd_init = SPD_NONE;
1851 result_list.have_sql_kind_backup = FALSE;
1852 result_list.direct_order_limit = FALSE;
1853 result_list.direct_limit_offset = FALSE;
1854#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1855 if ((error_num2 = reset_hs_strs(SPIDER_SQL_TYPE_UPDATE_HS)))
1856 error_num = error_num2;
1857#endif
1858 result_list.set_split_read = FALSE;
1859 result_list.insert_dup_update_pushdown = FALSE;
1860 use_spatial_index = FALSE;
1861#ifdef SPIDER_HAS_GROUP_BY_HANDLER
1862 use_fields = FALSE;
1863#endif
1864 error_mode = 0;
1865#ifdef HA_CAN_BULK_ACCESS
1866#ifndef DBUG_OFF
1867 if (bulk_access_link_first)
1868 {
1869 DBUG_PRINT("info",("spider bulk_access_link->spider->dbton_handler=%p",
1870 bulk_access_link_first->spider->dbton_handler));
1871 DBUG_PRINT("info",("spider ptr bulk_access_link->spider->dbton_handler=%p",
1872 &bulk_access_link_first->spider->dbton_handler));
1873 }
1874#endif
1875#endif
1876 DBUG_RETURN(error_num);
1877}
1878
1879int ha_spider::extra(
1880 enum ha_extra_function operation
1881) {
1882 int error_num;
1883 DBUG_ENTER("ha_spider::extra");
1884 DBUG_PRINT("info",("spider this=%p", this));
1885 DBUG_PRINT("info",("spider operation=%d", (int) operation));
1886 switch (operation)
1887 {
1888 case HA_EXTRA_QUICK:
1889 quick_mode = TRUE;
1890 break;
1891 case HA_EXTRA_KEYREAD:
1892 if (!is_clone)
1893 {
1894 keyread = TRUE;
1895#ifdef WITH_PARTITION_STORAGE_ENGINE
1896 if (update_request)
1897 {
1898 if (check_partitioned())
1899 keyread = FALSE;
1900 }
1901#endif
1902 }
1903 break;
1904 case HA_EXTRA_NO_KEYREAD:
1905 keyread = FALSE;
1906 break;
1907 case HA_EXTRA_IGNORE_DUP_KEY:
1908 ignore_dup_key = TRUE;
1909 break;
1910 case HA_EXTRA_NO_IGNORE_DUP_KEY:
1911 ignore_dup_key = FALSE;
1912 break;
1913 case HA_EXTRA_WRITE_CAN_REPLACE:
1914 write_can_replace = TRUE;
1915 break;
1916 case HA_EXTRA_WRITE_CANNOT_REPLACE:
1917 write_can_replace = FALSE;
1918 break;
1919#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
1920 case HA_EXTRA_INSERT_WITH_UPDATE:
1921 insert_with_update = TRUE;
1922 check_insert_dup_update_pushdown();
1923 break;
1924#endif
1925 case HA_EXTRA_ATTACH_CHILDREN:
1926 DBUG_PRINT("info",("spider HA_EXTRA_ATTACH_CHILDREN"));
1927 if (!(trx = spider_get_trx(ha_thd(), TRUE, &error_num)))
1928 DBUG_RETURN(error_num);
1929 break;
1930#if MYSQL_VERSION_ID < 50500
1931#else
1932 case HA_EXTRA_ADD_CHILDREN_LIST:
1933 DBUG_PRINT("info",("spider HA_EXTRA_ADD_CHILDREN_LIST"));
1934 if (!(trx = spider_get_trx(ha_thd(), TRUE, &error_num)))
1935 DBUG_RETURN(error_num);
1936 break;
1937#endif
1938#if defined(HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN) || defined(HA_EXTRA_HAS_HA_EXTRA_USE_CMP_REF)
1939#ifdef HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN
1940 case HA_EXTRA_STARTING_ORDERED_INDEX_SCAN:
1941#endif
1942#ifdef HA_EXTRA_HAS_HA_EXTRA_USE_CMP_REF
1943 case HA_EXTRA_USE_CMP_REF:
1944#endif
1945 DBUG_PRINT("info",("spider HA_EXTRA_STARTING_ORDERED_INDEX_SCAN"));
1946 if (table_share->primary_key != MAX_KEY)
1947 {
1948 DBUG_PRINT("info",("spider need primary key columns"));
1949 KEY *key_info = &table->key_info[table->s->primary_key];
1950 KEY_PART_INFO *key_part;
1951 uint part_num;
1952 for (
1953 key_part = key_info->key_part, part_num = 0;
1954 part_num < spider_user_defined_key_parts(key_info);
1955 key_part++, part_num++
1956 ) {
1957 spider_set_bit(searched_bitmap, key_part->field->field_index);
1958 }
1959 } else {
1960 DBUG_PRINT("info",("spider need all columns"));
1961 Field **field;
1962 for (
1963 field = table->field;
1964 *field;
1965 field++
1966 ) {
1967 spider_set_bit(searched_bitmap, (*field)->field_index);
1968 }
1969 }
1970 break;
1971#endif
1972 default:
1973 break;
1974 }
1975 DBUG_RETURN(0);
1976}
1977
1978int ha_spider::index_init(
1979 uint idx,
1980 bool sorted
1981) {
1982 int error_num;
1983 DBUG_ENTER("ha_spider::index_init");
1984 DBUG_PRINT("info",("spider this=%p", this));
1985 DBUG_PRINT("info",("spider idx=%u", idx));
1986#ifdef HA_CAN_BULK_ACCESS
1987 DBUG_ASSERT(!bulk_access_started);
1988 if (bulk_access_executing)
1989 {
1990 if (
1991 !is_bulk_access_clone &&
1992 bulk_access_link_exec_tgt->called
1993 ) {
1994 DBUG_RETURN(bulk_access_link_exec_tgt->spider->ha_index_init(
1995 idx, sorted));
1996 }
1997 }
1998#endif
1999 pushed_pos = NULL;
2000 active_index = idx;
2001 result_list.sorted = sorted;
2002 spider_set_result_list_param(this);
2003 mrr_with_cnt = FALSE;
2004 init_index_handler = FALSE;
2005 use_spatial_index = FALSE;
2006
2007 if (pre_bitmap_checked)
2008 pre_bitmap_checked = FALSE;
2009 else {
2010 if (result_list.lock_type == F_WRLCK)
2011 {
2012 pk_update = FALSE;
2013/*
2014 check_and_start_bulk_update(SPD_BU_START_BY_INDEX_OR_RND_INIT);
2015*/
2016 if (
2017 update_request &&
2018 share->have_recovery_link &&
2019 (pk_update = spider_check_pk_update(table))
2020 ) {
2021 bitmap_set_all(table->read_set);
2022 if (is_clone)
2023 memset(searched_bitmap, 0xFF, no_bytes_in_map(table->read_set));
2024 }
2025 }
2026
2027 if (!is_clone)
2028 set_select_column_mode();
2029 }
2030
2031 if ((error_num = reset_sql_sql(
2032 SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER)))
2033 DBUG_RETURN(error_num);
2034#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2035 if ((error_num = reset_hs_sql(SPIDER_SQL_TYPE_SELECT_HS)))
2036 DBUG_RETURN(error_num);
2037 if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS)))
2038 DBUG_RETURN(error_num);
2039#endif
2040 result_list.check_direct_order_limit = FALSE;
2041 prev_index_rnd_init = SPD_INDEX;
2042 DBUG_RETURN(0);
2043}
2044
2045#ifdef HA_CAN_BULK_ACCESS
2046int ha_spider::pre_index_init(
2047 uint idx,
2048 bool sorted
2049) {
2050 DBUG_ENTER("ha_spider::pre_index_init");
2051 DBUG_PRINT("info",("spider this=%p", this));
2052 DBUG_RETURN(bulk_access_link_current->spider->ha_index_init(idx, sorted));
2053}
2054#endif
2055
2056int ha_spider::index_end()
2057{
2058 int error_num;
2059 backup_error_status();
2060 DBUG_ENTER("ha_spider::index_end");
2061 DBUG_PRINT("info",("spider this=%p", this));
2062#ifdef HA_CAN_BULK_ACCESS
2063 DBUG_ASSERT(!bulk_access_started);
2064 if (bulk_access_executing)
2065 {
2066 if (
2067 !is_bulk_access_clone &&
2068 bulk_access_link_exec_tgt->called
2069 ) {
2070 error_num = bulk_access_link_exec_tgt->spider->ha_index_end();
2071 if (error_num)
2072 DBUG_RETURN(check_error_mode(error_num));
2073 DBUG_RETURN(0);
2074 }
2075 }
2076#endif
2077 active_index = MAX_KEY;
2078/*
2079#ifdef INFO_KIND_FORCE_LIMIT_BEGIN
2080 info_limit = 9223372036854775807LL;
2081#endif
2082 if (
2083 (error_num = drop_tmp_tables()) ||
2084 (error_num = check_and_end_bulk_update(
2085 SPD_BU_START_BY_INDEX_OR_RND_INIT)) ||
2086 (error_num = spider_trx_check_link_idx_failed(this))
2087 )
2088 DBUG_RETURN(check_error_mode(error_num));
2089*/
2090 if ((error_num = drop_tmp_tables()))
2091 DBUG_RETURN(check_error_mode(error_num));
2092 result_list.use_union = FALSE;
2093 DBUG_RETURN(0);
2094}
2095
2096#ifdef HA_CAN_BULK_ACCESS
2097int ha_spider::pre_index_end()
2098{
2099 DBUG_ENTER("ha_spider::pre_index_end");
2100 DBUG_PRINT("info",("spider this=%p", this));
2101 DBUG_RETURN(bulk_access_link_current->spider->ha_index_end());
2102}
2103#endif
2104
2105int ha_spider::index_read_map_internal(
2106 uchar *buf,
2107 const uchar *key,
2108 key_part_map keypart_map,
2109 enum ha_rkey_function find_flag
2110) {
2111 int error_num, roop_count;
2112 key_range start_key;
2113 SPIDER_CONN *conn;
2114 backup_error_status();
2115 DBUG_ENTER("ha_spider::index_read_map_internal");
2116 DBUG_PRINT("info",("spider this=%p", this));
2117 if (trx->thd->killed)
2118 {
2119 my_error(ER_QUERY_INTERRUPTED, MYF(0));
2120 DBUG_RETURN(ER_QUERY_INTERRUPTED);
2121 }
2122#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
2123 do_direct_update = FALSE;
2124#endif
2125 if (
2126 find_flag >= HA_READ_MBR_CONTAIN &&
2127 find_flag <= HA_READ_MBR_EQUAL
2128 )
2129 use_spatial_index = TRUE;
2130
2131 if ((error_num = index_handler_init()))
2132 DBUG_RETURN(check_error_mode_eof(error_num));
2133 if (is_clone)
2134 {
2135 DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p",
2136 pt_clone_source_handler));
2137 pt_clone_source_handler->pt_clone_last_searcher = this;
2138 }
2139 spider_db_free_one_result_for_start_next(this);
2140 spider_set_result_list_param(this);
2141 check_direct_order_limit();
2142 start_key.key = key;
2143 start_key.keypart_map = keypart_map;
2144 start_key.flag = find_flag;
2145 if ((error_num = reset_sql_sql(
2146 SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER)))
2147 DBUG_RETURN(error_num);
2148#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2149 if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS)))
2150 DBUG_RETURN(error_num);
2151#endif
2152#ifndef WITHOUT_SPIDER_BG_SEARCH
2153 if ((error_num = spider_set_conn_bg_param(this)))
2154 DBUG_RETURN(error_num);
2155#endif
2156#ifdef WITH_PARTITION_STORAGE_ENGINE
2157 check_select_column(FALSE);
2158#endif
2159 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
2160 result_list.finish_flg = FALSE;
2161 result_list.record_num = 0;
2162 if (keyread)
2163 result_list.keyread = TRUE;
2164 else
2165 result_list.keyread = FALSE;
2166 if (
2167 (error_num = spider_db_append_select(this)) ||
2168 (error_num = spider_db_append_select_columns(this))
2169 )
2170 DBUG_RETURN(error_num);
2171 if (
2172 share->key_hint &&
2173 (error_num = append_hint_after_table_sql_part(
2174 SPIDER_SQL_TYPE_SELECT_SQL))
2175 )
2176 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
2177 set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
2178 result_list.desc_flg = FALSE;
2179 result_list.sorted = TRUE;
2180 result_list.key_info = &table->key_info[active_index];
2181 check_distinct_key_query();
2182 result_list.limit_num =
2183 result_list.internal_limit >= result_list.split_read ?
2184 result_list.split_read : result_list.internal_limit;
2185 DBUG_PRINT("info",("spider result_list.internal_limit=%lld",
2186 result_list.internal_limit));
2187 DBUG_PRINT("info",("spider result_list.split_read=%lld",
2188 result_list.split_read));
2189 DBUG_PRINT("info",("spider result_list.limit_num=%lld",
2190 result_list.limit_num));
2191 if (
2192 (error_num = spider_db_append_key_where(
2193 &start_key, NULL, this))
2194 )
2195 DBUG_RETURN(error_num);
2196 DBUG_PRINT("info",("spider result_list.internal_limit=%lld",
2197 result_list.internal_limit));
2198 DBUG_PRINT("info",("spider result_list.split_read=%lld",
2199 result_list.split_read));
2200 DBUG_PRINT("info",("spider result_list.limit_num=%lld",
2201 result_list.limit_num));
2202 if (sql_kinds & SPIDER_SQL_KIND_SQL)
2203 {
2204 if (result_list.direct_order_limit)
2205 {
2206 if ((error_num =
2207 append_key_order_for_direct_order_limit_with_alias_sql_part(
2208 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
2209 DBUG_RETURN(error_num);
2210 } else {
2211 if ((error_num = append_key_order_with_alias_sql_part(
2212 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
2213 DBUG_RETURN(error_num);
2214 }
2215 if ((error_num = append_limit_sql_part(
2216 result_list.internal_offset,
2217 result_list.limit_num,
2218 SPIDER_SQL_TYPE_SELECT_SQL)))
2219 {
2220 DBUG_RETURN(error_num);
2221 }
2222 if (
2223 (error_num = append_select_lock_sql_part(
2224 SPIDER_SQL_TYPE_SELECT_SQL))
2225 ) {
2226 DBUG_RETURN(error_num);
2227 }
2228 }
2229 if (sql_kinds & SPIDER_SQL_KIND_HANDLER)
2230 {
2231 if ((error_num = append_limit_sql_part(
2232 result_list.internal_offset,
2233 result_list.limit_num,
2234 SPIDER_SQL_TYPE_HANDLER)))
2235 {
2236 DBUG_RETURN(error_num);
2237 }
2238 }
2239#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2240 if (sql_kinds & SPIDER_SQL_KIND_HS)
2241 {
2242 if ((error_num = append_limit_hs_part(
2243 result_list.internal_offset,
2244 result_list.limit_num,
2245 SPIDER_SQL_TYPE_SELECT_HS)))
2246 {
2247 DBUG_RETURN(error_num);
2248 }
2249 }
2250#endif
2251
2252 int roop_start, roop_end, lock_mode, link_ok;
2253 lock_mode = spider_conn_lock_mode(this);
2254 if (lock_mode)
2255 {
2256 /* "for update" or "lock in share mode" */
2257 link_ok = spider_conn_link_idx_next(share->link_statuses,
2258 conn_link_idx, -1, share->link_count,
2259 SPIDER_LINK_STATUS_OK);
2260 roop_start = spider_conn_link_idx_next(share->link_statuses,
2261 conn_link_idx, -1, share->link_count,
2262 SPIDER_LINK_STATUS_RECOVERY);
2263 roop_end = share->link_count;
2264 } else {
2265 link_ok = search_link_idx;
2266 roop_start = search_link_idx;
2267 roop_end = search_link_idx + 1;
2268 }
2269 for (roop_count = roop_start; roop_count < roop_end;
2270 roop_count = spider_conn_link_idx_next(share->link_statuses,
2271 conn_link_idx, roop_count, share->link_count,
2272 SPIDER_LINK_STATUS_RECOVERY)
2273 ) {
2274#ifndef WITHOUT_SPIDER_BG_SEARCH
2275 if (result_list.bgs_phase > 0)
2276 {
2277 if ((error_num = spider_check_and_init_casual_read(trx->thd, this,
2278 roop_count)))
2279 DBUG_RETURN(error_num);
2280 if ((error_num = spider_bg_conn_search(this, roop_count, roop_start,
2281 TRUE, FALSE, (roop_count != link_ok))))
2282 {
2283 if (
2284 error_num != HA_ERR_END_OF_FILE &&
2285 share->monitoring_kind[roop_count] &&
2286 need_mons[roop_count]
2287 ) {
2288 error_num = spider_ping_table_mon_from_table(
2289 trx,
2290 trx->thd,
2291 share,
2292 roop_count,
2293 (uint32) share->monitoring_sid[roop_count],
2294 share->table_name,
2295 share->table_name_length,
2296 conn_link_idx[roop_count],
2297 NULL,
2298 0,
2299 share->monitoring_kind[roop_count],
2300 share->monitoring_limit[roop_count],
2301 share->monitoring_flag[roop_count],
2302 TRUE
2303 );
2304 }
2305 DBUG_RETURN(check_error_mode_eof(error_num));
2306 }
2307 } else {
2308#endif
2309 ulong sql_type;
2310#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2311 if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL)
2312 {
2313#endif
2314 conn = conns[roop_count];
2315 if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL)
2316 {
2317 sql_type = SPIDER_SQL_TYPE_SELECT_SQL;
2318 } else {
2319 sql_type = SPIDER_SQL_TYPE_HANDLER;
2320 }
2321#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2322 } else {
2323 if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ)
2324 conn = hs_r_conns[roop_count];
2325 else
2326 conn = hs_w_conns[roop_count];
2327 sql_type = SPIDER_SQL_TYPE_SELECT_HS;
2328 }
2329#endif
2330 spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id];
2331 if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
2332 {
2333 pthread_mutex_lock(&conn->mta_conn_mutex);
2334 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
2335 }
2336 if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count)))
2337 {
2338 DBUG_RETURN(error_num);
2339 }
2340 if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
2341 {
2342 pthread_mutex_lock(&conn->mta_conn_mutex);
2343 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
2344 }
2345 DBUG_PRINT("info",("spider sql_type=%lu", sql_type));
2346#ifdef HA_CAN_BULK_ACCESS
2347 if (
2348 is_bulk_access_clone &&
2349 !bulk_access_executing &&
2350 conn_kind[roop_count] != SPIDER_CONN_KIND_MYSQL
2351 ) {
2352 connection_ids[roop_count] = conn->connection_id;
2353 spider_trx_add_bulk_access_conn(trx, conn);
2354 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
2355 pthread_mutex_unlock(&conn->mta_conn_mutex);
2356 } else {
2357#endif
2358 conn->need_mon = &need_mons[roop_count];
2359 conn->mta_conn_mutex_lock_already = TRUE;
2360 conn->mta_conn_mutex_unlock_later = TRUE;
2361 if ((error_num = spider_db_set_names(this, conn,
2362 roop_count)))
2363 {
2364 conn->mta_conn_mutex_lock_already = FALSE;
2365 conn->mta_conn_mutex_unlock_later = FALSE;
2366 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
2367 pthread_mutex_unlock(&conn->mta_conn_mutex);
2368 if (
2369 share->monitoring_kind[roop_count] &&
2370 need_mons[roop_count]
2371 ) {
2372 error_num = spider_ping_table_mon_from_table(
2373 trx,
2374 trx->thd,
2375 share,
2376 roop_count,
2377 (uint32) share->monitoring_sid[roop_count],
2378 share->table_name,
2379 share->table_name_length,
2380 conn_link_idx[roop_count],
2381 NULL,
2382 0,
2383 share->monitoring_kind[roop_count],
2384 share->monitoring_limit[roop_count],
2385 share->monitoring_flag[roop_count],
2386 TRUE
2387 );
2388 }
2389 DBUG_RETURN(check_error_mode_eof(error_num));
2390 }
2391 spider_conn_set_timeout_from_share(conn, roop_count,
2392 trx->thd, share);
2393 if (dbton_hdl->execute_sql(
2394 sql_type,
2395 conn,
2396 result_list.quick_mode,
2397 &need_mons[roop_count])
2398 ) {
2399 conn->mta_conn_mutex_lock_already = FALSE;
2400 conn->mta_conn_mutex_unlock_later = FALSE;
2401 error_num = spider_db_errorno(conn);
2402 if (
2403 share->monitoring_kind[roop_count] &&
2404 need_mons[roop_count]
2405 ) {
2406 error_num = spider_ping_table_mon_from_table(
2407 trx,
2408 trx->thd,
2409 share,
2410 roop_count,
2411 (uint32) share->monitoring_sid[roop_count],
2412 share->table_name,
2413 share->table_name_length,
2414 conn_link_idx[roop_count],
2415 NULL,
2416 0,
2417 share->monitoring_kind[roop_count],
2418 share->monitoring_limit[roop_count],
2419 share->monitoring_flag[roop_count],
2420 TRUE
2421 );
2422 }
2423 DBUG_RETURN(check_error_mode_eof(error_num));
2424 }
2425 connection_ids[roop_count] = conn->connection_id;
2426 conn->mta_conn_mutex_lock_already = FALSE;
2427 conn->mta_conn_mutex_unlock_later = FALSE;
2428 if (roop_count == link_ok)
2429 {
2430 if ((error_num = spider_db_store_result(this, roop_count, table)))
2431 {
2432 if (
2433 error_num != HA_ERR_END_OF_FILE &&
2434 share->monitoring_kind[roop_count] &&
2435 need_mons[roop_count]
2436 ) {
2437 error_num = spider_ping_table_mon_from_table(
2438 trx,
2439 trx->thd,
2440 share,
2441 roop_count,
2442 (uint32) share->monitoring_sid[roop_count],
2443 share->table_name,
2444 share->table_name_length,
2445 conn_link_idx[roop_count],
2446 NULL,
2447 0,
2448 share->monitoring_kind[roop_count],
2449 share->monitoring_limit[roop_count],
2450 share->monitoring_flag[roop_count],
2451 TRUE
2452 );
2453 }
2454 DBUG_RETURN(check_error_mode_eof(error_num));
2455 }
2456 result_link_idx = link_ok;
2457 } else {
2458 spider_db_discard_result(this, roop_count, conn);
2459 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
2460 pthread_mutex_unlock(&conn->mta_conn_mutex);
2461 }
2462#ifdef HA_CAN_BULK_ACCESS
2463 }
2464#endif
2465#ifndef WITHOUT_SPIDER_BG_SEARCH
2466 }
2467#endif
2468 }
2469 if (buf && (error_num = spider_db_fetch(buf, this, table)))
2470 DBUG_RETURN(check_error_mode_eof(error_num));
2471 DBUG_RETURN(0);
2472}
2473
2474int ha_spider::pre_index_read_map(
2475 const uchar *key,
2476 key_part_map keypart_map,
2477 enum ha_rkey_function find_flag,
2478 bool use_parallel
2479) {
2480#ifdef HA_CAN_BULK_ACCESS
2481 int error_num;
2482#endif
2483 DBUG_ENTER("ha_spider::pre_index_read_map");
2484 DBUG_PRINT("info",("spider this=%p", this));
2485#ifdef HA_CAN_BULK_ACCESS
2486 if (bulk_access_started)
2487 {
2488 error_num = bulk_access_link_current->spider->pre_index_read_map(key,
2489 keypart_map, find_flag, TRUE);
2490 bulk_access_link_current->spider->bulk_access_pre_called = TRUE;
2491 bulk_access_link_current->called = TRUE;
2492 DBUG_RETURN(error_num);
2493 } else if (
2494 bulk_access_executing && !is_bulk_access_clone &&
2495 bulk_access_link_exec_tgt->called
2496 ) {
2497 DBUG_RETURN(bulk_access_link_exec_tgt->spider->pre_index_read_map(key,
2498 keypart_map, find_flag, TRUE));
2499 }
2500#endif
2501 check_pre_call(use_parallel);
2502 if (use_pre_call)
2503 {
2504 store_error_num =
2505 index_read_map_internal(NULL, key, keypart_map, find_flag);
2506#ifdef HA_CAN_BULK_ACCESS
2507 if (
2508 !store_error_num &&
2509 bulk_access_executing &&
2510 is_bulk_access_clone &&
2511 !bulk_access_pre_called
2512 ) {
2513 bulk_req_exec();
2514 }
2515#endif
2516 DBUG_RETURN(store_error_num);
2517 }
2518 DBUG_RETURN(0);
2519}
2520
2521int ha_spider::index_read_map(
2522 uchar *buf,
2523 const uchar *key,
2524 key_part_map keypart_map,
2525 enum ha_rkey_function find_flag
2526) {
2527 int error_num;
2528 DBUG_ENTER("ha_spider::index_read_map");
2529 DBUG_PRINT("info",("spider this=%p", this));
2530#ifdef HA_CAN_BULK_ACCESS
2531 DBUG_ASSERT(!bulk_access_started);
2532 if (bulk_access_executing)
2533 {
2534 if (is_bulk_access_clone)
2535 {
2536 if (bulk_access_pre_called)
2537 {
2538 SPIDER_CONN *conn;
2539 int roop_count, roop_start, roop_end, tmp_lock_mode, link_ok,
2540 tmp_error_num;
2541 tmp_lock_mode = spider_conn_lock_mode(this);
2542 if (tmp_lock_mode)
2543 {
2544 /* "for update" or "lock in share mode" */
2545 link_ok = spider_conn_link_idx_next(share->link_statuses,
2546 conn_link_idx, -1, share->link_count,
2547 SPIDER_LINK_STATUS_OK);
2548 roop_start = spider_conn_link_idx_next(share->link_statuses,
2549 conn_link_idx, -1, share->link_count,
2550 SPIDER_LINK_STATUS_RECOVERY);
2551 roop_end = share->link_count;
2552 } else {
2553 link_ok = search_link_idx;
2554 roop_start = search_link_idx;
2555 roop_end = search_link_idx + 1;
2556 }
2557 for (roop_count = roop_start; roop_count < roop_end;
2558 roop_count = spider_conn_link_idx_next(share->link_statuses,
2559 conn_link_idx, roop_count, share->link_count,
2560 SPIDER_LINK_STATUS_RECOVERY)
2561 ) {
2562#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2563 if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL)
2564 {
2565#endif
2566 conn = conns[roop_count];
2567#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2568 } else {
2569 if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ)
2570 conn = hs_r_conns[roop_count];
2571 else
2572 conn = hs_w_conns[roop_count];
2573 }
2574#endif
2575 if ((tmp_error_num = spider_db_bulk_store_result(this, conn,
2576 roop_count, (roop_count != link_ok))))
2577 {
2578 store_error_num = tmp_error_num;
2579 } else {
2580 result_link_idx = link_ok;
2581 }
2582 }
2583 use_pre_call = TRUE;
2584 bulk_access_pre_called = FALSE;
2585 } else {
2586 /* do access normally */
2587 }
2588 } else if (bulk_access_link_exec_tgt->called)
2589 {
2590 DBUG_RETURN(bulk_access_link_exec_tgt->spider->index_read_map(buf, key,
2591 keypart_map, find_flag));
2592 }
2593 }
2594#endif
2595 if (use_pre_call)
2596 {
2597 if (store_error_num)
2598 {
2599 if (store_error_num == HA_ERR_END_OF_FILE)
2600 table->status = STATUS_NOT_FOUND;
2601 DBUG_RETURN(store_error_num);
2602 }
2603 if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx)))
2604 DBUG_RETURN(error_num);
2605 use_pre_call = FALSE;
2606 if (
2607 result_list.sorted &&
2608 result_list.desc_flg
2609 ) {
2610 DBUG_RETURN(index_prev(buf));
2611 }
2612 DBUG_RETURN(index_next(buf));
2613 }
2614 DBUG_RETURN(index_read_map_internal(buf, key, keypart_map, find_flag));
2615}
2616
2617int ha_spider::index_read_last_map_internal(
2618 uchar *buf,
2619 const uchar *key,
2620 key_part_map keypart_map
2621) {
2622 int error_num;
2623 key_range start_key;
2624 SPIDER_CONN *conn;
2625 backup_error_status();
2626 DBUG_ENTER("ha_spider::index_read_last_map_internal");
2627 DBUG_PRINT("info",("spider this=%p", this));
2628 if (trx->thd->killed)
2629 {
2630 my_error(ER_QUERY_INTERRUPTED, MYF(0));
2631 DBUG_RETURN(ER_QUERY_INTERRUPTED);
2632 }
2633#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
2634 do_direct_update = FALSE;
2635#endif
2636 if ((error_num = index_handler_init()))
2637 DBUG_RETURN(check_error_mode_eof(error_num));
2638 if (is_clone)
2639 {
2640 DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p",
2641 pt_clone_source_handler));
2642 pt_clone_source_handler->pt_clone_last_searcher = this;
2643 }
2644/*
2645 spider_db_free_one_result_for_start_next(this);
2646*/
2647 if (
2648#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2649 (
2650 result_list.hs_has_result ||
2651#endif
2652 result_list.current
2653#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2654 )
2655#endif
2656 &&
2657 (error_num = spider_db_free_result(this, FALSE))
2658 )
2659 DBUG_RETURN(error_num);
2660
2661 check_direct_order_limit();
2662 start_key.key = key;
2663 start_key.keypart_map = keypart_map;
2664 start_key.flag = HA_READ_KEY_EXACT;
2665 if ((error_num = reset_sql_sql(
2666 SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER)))
2667 DBUG_RETURN(error_num);
2668#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2669 if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS)))
2670 DBUG_RETURN(error_num);
2671#endif
2672#ifndef WITHOUT_SPIDER_BG_SEARCH
2673 if ((error_num = spider_set_conn_bg_param(this)))
2674 DBUG_RETURN(error_num);
2675#endif
2676#ifdef WITH_PARTITION_STORAGE_ENGINE
2677 check_select_column(FALSE);
2678#endif
2679 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
2680 result_list.finish_flg = FALSE;
2681 result_list.record_num = 0;
2682 if (keyread)
2683 result_list.keyread = TRUE;
2684 else
2685 result_list.keyread = FALSE;
2686 if (
2687 (error_num = spider_db_append_select(this)) ||
2688 (error_num = spider_db_append_select_columns(this))
2689 )
2690 DBUG_RETURN(error_num);
2691 if (
2692 share->key_hint &&
2693 (error_num = append_hint_after_table_sql_part(
2694 SPIDER_SQL_TYPE_SELECT_SQL))
2695 )
2696 DBUG_RETURN(error_num);
2697 set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
2698 result_list.desc_flg = TRUE;
2699 result_list.sorted = TRUE;
2700 result_list.key_info = &table->key_info[active_index];
2701 check_distinct_key_query();
2702 result_list.limit_num =
2703 result_list.internal_limit >= result_list.split_read ?
2704 result_list.split_read : result_list.internal_limit;
2705 if (
2706 (error_num = spider_db_append_key_where(
2707 &start_key, NULL, this))
2708 )
2709 DBUG_RETURN(error_num);
2710 if (sql_kinds & SPIDER_SQL_KIND_SQL)
2711 {
2712 if (result_list.direct_order_limit)
2713 {
2714 if ((error_num =
2715 append_key_order_for_direct_order_limit_with_alias_sql_part(
2716 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
2717 DBUG_RETURN(error_num);
2718 } else {
2719 if ((error_num = append_key_order_with_alias_sql_part(
2720 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
2721 DBUG_RETURN(error_num);
2722 }
2723 if ((error_num = append_limit_sql_part(
2724 result_list.internal_offset,
2725 result_list.limit_num,
2726 SPIDER_SQL_TYPE_SELECT_SQL)))
2727 {
2728 DBUG_RETURN(error_num);
2729 }
2730 if (
2731 (error_num = append_select_lock_sql_part(
2732 SPIDER_SQL_TYPE_SELECT_SQL))
2733 ) {
2734 DBUG_RETURN(error_num);
2735 }
2736 }
2737 if (sql_kinds & SPIDER_SQL_KIND_HANDLER)
2738 {
2739 if ((error_num = append_limit_sql_part(
2740 result_list.internal_offset,
2741 result_list.limit_num,
2742 SPIDER_SQL_TYPE_HANDLER)))
2743 {
2744 DBUG_RETURN(error_num);
2745 }
2746 }
2747
2748 int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok;
2749 tmp_lock_mode = spider_conn_lock_mode(this);
2750 if (tmp_lock_mode)
2751 {
2752 /* "for update" or "lock in share mode" */
2753 link_ok = spider_conn_link_idx_next(share->link_statuses,
2754 conn_link_idx, -1, share->link_count,
2755 SPIDER_LINK_STATUS_OK);
2756 roop_start = spider_conn_link_idx_next(share->link_statuses,
2757 conn_link_idx, -1, share->link_count,
2758 SPIDER_LINK_STATUS_RECOVERY);
2759 roop_end = share->link_count;
2760 } else {
2761 link_ok = search_link_idx;
2762 roop_start = search_link_idx;
2763 roop_end = search_link_idx + 1;
2764 }
2765 for (roop_count = roop_start; roop_count < roop_end;
2766 roop_count = spider_conn_link_idx_next(share->link_statuses,
2767 conn_link_idx, roop_count, share->link_count,
2768 SPIDER_LINK_STATUS_RECOVERY)
2769 ) {
2770#ifndef WITHOUT_SPIDER_BG_SEARCH
2771 if (result_list.bgs_phase > 0)
2772 {
2773 if ((error_num = spider_check_and_init_casual_read(trx->thd, this,
2774 roop_count)))
2775 DBUG_RETURN(error_num);
2776 if ((error_num = spider_bg_conn_search(this, roop_count, roop_start,
2777 TRUE, FALSE, (roop_count != link_ok))))
2778 {
2779 if (
2780 error_num != HA_ERR_END_OF_FILE &&
2781 share->monitoring_kind[roop_count] &&
2782 need_mons[roop_count]
2783 ) {
2784 error_num = spider_ping_table_mon_from_table(
2785 trx,
2786 trx->thd,
2787 share,
2788 roop_count,
2789 (uint32) share->monitoring_sid[roop_count],
2790 share->table_name,
2791 share->table_name_length,
2792 conn_link_idx[roop_count],
2793 NULL,
2794 0,
2795 share->monitoring_kind[roop_count],
2796 share->monitoring_limit[roop_count],
2797 share->monitoring_flag[roop_count],
2798 TRUE
2799 );
2800 }
2801 DBUG_RETURN(check_error_mode_eof(error_num));
2802 }
2803 } else {
2804#endif
2805 ulong sql_type;
2806#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2807 if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL)
2808 {
2809#endif
2810 conn = conns[roop_count];
2811 if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL)
2812 {
2813 sql_type = SPIDER_SQL_TYPE_SELECT_SQL;
2814 } else {
2815 sql_type = SPIDER_SQL_TYPE_HANDLER;
2816 }
2817#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2818 } else {
2819 if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ)
2820 conn = hs_r_conns[roop_count];
2821 else
2822 conn = hs_w_conns[roop_count];
2823 sql_type = SPIDER_SQL_TYPE_SELECT_HS;
2824 }
2825#endif
2826 spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id];
2827 if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
2828 {
2829 pthread_mutex_lock(&conn->mta_conn_mutex);
2830 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
2831 }
2832 if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count)))
2833 {
2834 DBUG_RETURN(error_num);
2835 }
2836 if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
2837 {
2838 pthread_mutex_lock(&conn->mta_conn_mutex);
2839 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
2840 }
2841 DBUG_PRINT("info",("spider sql_type=%lu", sql_type));
2842#ifdef HA_CAN_BULK_ACCESS
2843 if (is_bulk_access_clone)
2844 {
2845 connection_ids[roop_count] = conn->connection_id;
2846 spider_trx_add_bulk_access_conn(trx, conn);
2847 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
2848 pthread_mutex_unlock(&conn->mta_conn_mutex);
2849 } else {
2850#endif
2851 conn->need_mon = &need_mons[roop_count];
2852 conn->mta_conn_mutex_lock_already = TRUE;
2853 conn->mta_conn_mutex_unlock_later = TRUE;
2854 if ((error_num = spider_db_set_names(this, conn,
2855 roop_count)))
2856 {
2857 conn->mta_conn_mutex_lock_already = FALSE;
2858 conn->mta_conn_mutex_unlock_later = FALSE;
2859 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
2860 pthread_mutex_unlock(&conn->mta_conn_mutex);
2861 if (
2862 share->monitoring_kind[roop_count] &&
2863 need_mons[roop_count]
2864 ) {
2865 error_num = spider_ping_table_mon_from_table(
2866 trx,
2867 trx->thd,
2868 share,
2869 roop_count,
2870 (uint32) share->monitoring_sid[roop_count],
2871 share->table_name,
2872 share->table_name_length,
2873 conn_link_idx[roop_count],
2874 NULL,
2875 0,
2876 share->monitoring_kind[roop_count],
2877 share->monitoring_limit[roop_count],
2878 share->monitoring_flag[roop_count],
2879 TRUE
2880 );
2881 }
2882 DBUG_RETURN(check_error_mode_eof(error_num));
2883 }
2884 spider_conn_set_timeout_from_share(conn, roop_count,
2885 trx->thd, share);
2886 if (dbton_hdl->execute_sql(
2887 sql_type,
2888 conn,
2889 result_list.quick_mode,
2890 &need_mons[roop_count])
2891 ) {
2892 conn->mta_conn_mutex_lock_already = FALSE;
2893 conn->mta_conn_mutex_unlock_later = FALSE;
2894 error_num = spider_db_errorno(conn);
2895 if (
2896 share->monitoring_kind[roop_count] &&
2897 need_mons[roop_count]
2898 ) {
2899 error_num = spider_ping_table_mon_from_table(
2900 trx,
2901 trx->thd,
2902 share,
2903 roop_count,
2904 (uint32) share->monitoring_sid[roop_count],
2905 share->table_name,
2906 share->table_name_length,
2907 conn_link_idx[roop_count],
2908 NULL,
2909 0,
2910 share->monitoring_kind[roop_count],
2911 share->monitoring_limit[roop_count],
2912 share->monitoring_flag[roop_count],
2913 TRUE
2914 );
2915 }
2916 DBUG_RETURN(check_error_mode_eof(error_num));
2917 }
2918 connection_ids[roop_count] = conn->connection_id;
2919 conn->mta_conn_mutex_lock_already = FALSE;
2920 conn->mta_conn_mutex_unlock_later = FALSE;
2921 if (roop_count == link_ok)
2922 {
2923 if ((error_num = spider_db_store_result(this, roop_count, table)))
2924 {
2925 if (
2926 error_num != HA_ERR_END_OF_FILE &&
2927 share->monitoring_kind[roop_count] &&
2928 need_mons[roop_count]
2929 ) {
2930 error_num = spider_ping_table_mon_from_table(
2931 trx,
2932 trx->thd,
2933 share,
2934 roop_count,
2935 (uint32) share->monitoring_sid[roop_count],
2936 share->table_name,
2937 share->table_name_length,
2938 conn_link_idx[roop_count],
2939 NULL,
2940 0,
2941 share->monitoring_kind[roop_count],
2942 share->monitoring_limit[roop_count],
2943 share->monitoring_flag[roop_count],
2944 TRUE
2945 );
2946 }
2947 DBUG_RETURN(check_error_mode_eof(error_num));
2948 }
2949 result_link_idx = link_ok;
2950 } else {
2951 spider_db_discard_result(this, roop_count, conn);
2952 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
2953 pthread_mutex_unlock(&conn->mta_conn_mutex);
2954 }
2955#ifdef HA_CAN_BULK_ACCESS
2956 }
2957#endif
2958#ifndef WITHOUT_SPIDER_BG_SEARCH
2959 }
2960#endif
2961 }
2962 if (buf && (error_num = spider_db_fetch(buf, this, table)))
2963 DBUG_RETURN(check_error_mode_eof(error_num));
2964 DBUG_RETURN(0);
2965}
2966
2967int ha_spider::pre_index_read_last_map(
2968 const uchar *key,
2969 key_part_map keypart_map,
2970 bool use_parallel
2971) {
2972 DBUG_ENTER("ha_spider::pre_index_read_last_map");
2973 DBUG_PRINT("info",("spider this=%p", this));
2974 check_pre_call(use_parallel);
2975 if (use_pre_call)
2976 {
2977 store_error_num =
2978 index_read_last_map_internal(NULL, key, keypart_map);
2979 DBUG_RETURN(store_error_num);
2980 }
2981 DBUG_RETURN(0);
2982}
2983
2984int ha_spider::index_read_last_map(
2985 uchar *buf,
2986 const uchar *key,
2987 key_part_map keypart_map
2988) {
2989 int error_num;
2990 DBUG_ENTER("ha_spider::index_read_last_map");
2991 DBUG_PRINT("info",("spider this=%p", this));
2992 if (use_pre_call)
2993 {
2994 if (store_error_num)
2995 {
2996 if (store_error_num == HA_ERR_END_OF_FILE)
2997 table->status = STATUS_NOT_FOUND;
2998 DBUG_RETURN(store_error_num);
2999 }
3000 if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx)))
3001 DBUG_RETURN(error_num);
3002 use_pre_call = FALSE;
3003 DBUG_RETURN(index_prev(buf));
3004 }
3005 DBUG_RETURN(index_read_last_map_internal(buf, key, keypart_map));
3006}
3007
3008int ha_spider::index_next(
3009 uchar *buf
3010) {
3011 int error_num;
3012 backup_error_status();
3013 DBUG_ENTER("ha_spider::index_next");
3014 DBUG_PRINT("info",("spider this=%p", this));
3015 if (trx->thd->killed)
3016 {
3017 my_error(ER_QUERY_INTERRUPTED, MYF(0));
3018 DBUG_RETURN(ER_QUERY_INTERRUPTED);
3019 }
3020#ifdef HA_CAN_BULK_ACCESS
3021 DBUG_ASSERT(!bulk_access_started);
3022 if (bulk_access_executing)
3023 {
3024 if (
3025 !is_bulk_access_clone &&
3026 bulk_access_link_exec_tgt->called
3027 ) {
3028 error_num = bulk_access_link_exec_tgt->spider->index_next(buf);
3029 if (error_num)
3030 DBUG_RETURN(check_error_mode(error_num));
3031 DBUG_RETURN(0);
3032 }
3033 }
3034#endif
3035 if (is_clone)
3036 {
3037 DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p",
3038 pt_clone_source_handler));
3039 pt_clone_source_handler->pt_clone_last_searcher = this;
3040 }
3041 if (
3042 result_list.sorted &&
3043 result_list.desc_flg
3044 ) {
3045 if ((error_num = spider_db_seek_prev(buf, this, table)))
3046 DBUG_RETURN(check_error_mode_eof(error_num));
3047 DBUG_RETURN(0);
3048 }
3049 if ((error_num = spider_db_seek_next(buf, this, search_link_idx, table)))
3050 DBUG_RETURN(check_error_mode_eof(error_num));
3051 DBUG_RETURN(0);
3052}
3053
3054int ha_spider::index_prev(
3055 uchar *buf
3056) {
3057 int error_num;
3058 backup_error_status();
3059 DBUG_ENTER("ha_spider::index_prev");
3060 DBUG_PRINT("info",("spider this=%p", this));
3061 if (trx->thd->killed)
3062 {
3063 my_error(ER_QUERY_INTERRUPTED, MYF(0));
3064 DBUG_RETURN(ER_QUERY_INTERRUPTED);
3065 }
3066#ifdef HA_CAN_BULK_ACCESS
3067 DBUG_ASSERT(!bulk_access_started);
3068 if (bulk_access_executing)
3069 {
3070 if (
3071 !is_bulk_access_clone &&
3072 bulk_access_link_exec_tgt->called
3073 ) {
3074 error_num = bulk_access_link_exec_tgt->spider->index_prev(buf);
3075 if (error_num)
3076 DBUG_RETURN(check_error_mode(error_num));
3077 DBUG_RETURN(0);
3078 }
3079 }
3080#endif
3081 if (is_clone)
3082 {
3083 DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p",
3084 pt_clone_source_handler));
3085 pt_clone_source_handler->pt_clone_last_searcher = this;
3086 }
3087 if (
3088 result_list.sorted &&
3089 result_list.desc_flg
3090 ) {
3091 if ((error_num = spider_db_seek_next(buf, this, search_link_idx, table)))
3092 DBUG_RETURN(check_error_mode_eof(error_num));
3093 DBUG_RETURN(0);
3094 }
3095 if ((error_num = spider_db_seek_prev(buf, this, table)))
3096 DBUG_RETURN(check_error_mode_eof(error_num));
3097 DBUG_RETURN(0);
3098}
3099
3100int ha_spider::index_first_internal(
3101 uchar *buf
3102) {
3103 int error_num;
3104 SPIDER_CONN *conn;
3105 backup_error_status();
3106 DBUG_ENTER("ha_spider::index_first_internal");
3107 DBUG_PRINT("info",("spider this=%p", this));
3108 if (trx->thd->killed)
3109 {
3110 my_error(ER_QUERY_INTERRUPTED, MYF(0));
3111 DBUG_RETURN(ER_QUERY_INTERRUPTED);
3112 }
3113#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
3114 do_direct_update = FALSE;
3115#endif
3116 if ((error_num = index_handler_init()))
3117 DBUG_RETURN(check_error_mode_eof(error_num));
3118 if (is_clone)
3119 {
3120 DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p",
3121 pt_clone_source_handler));
3122 pt_clone_source_handler->pt_clone_last_searcher = this;
3123 }
3124 if (
3125#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
3126 result_list.hs_has_result ||
3127#endif
3128 sql_is_empty(SPIDER_SQL_TYPE_HANDLER) ||
3129 sql_is_empty(SPIDER_SQL_TYPE_SELECT_SQL)
3130 ) {
3131/*
3132 spider_db_free_one_result_for_start_next(this);
3133*/
3134 if ((error_num = spider_db_free_result(this, FALSE)))
3135 DBUG_RETURN(error_num);
3136 if ((error_num = reset_sql_sql(
3137 SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER)))
3138 DBUG_RETURN(error_num);
3139
3140 check_direct_order_limit();
3141#ifndef WITHOUT_SPIDER_BG_SEARCH
3142 if ((error_num = spider_set_conn_bg_param(this)))
3143 DBUG_RETURN(error_num);
3144#endif
3145#ifdef WITH_PARTITION_STORAGE_ENGINE
3146 check_select_column(FALSE);
3147#endif
3148 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
3149 result_list.finish_flg = FALSE;
3150 result_list.record_num = 0;
3151 if (keyread)
3152 result_list.keyread = TRUE;
3153 else
3154 result_list.keyread = FALSE;
3155 if (
3156 (error_num = spider_db_append_select(this)) ||
3157 (error_num = spider_db_append_select_columns(this))
3158 )
3159 DBUG_RETURN(error_num);
3160 if (
3161 share->key_hint &&
3162 (error_num = append_hint_after_table_sql_part(
3163 SPIDER_SQL_TYPE_SELECT_SQL))
3164 )
3165 DBUG_RETURN(error_num);
3166 set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
3167 result_list.desc_flg = FALSE;
3168 result_list.sorted = TRUE;
3169 result_list.key_info = &table->key_info[active_index];
3170 result_list.key_order = 0;
3171 check_distinct_key_query();
3172 result_list.limit_num =
3173 result_list.internal_limit >= result_list.split_read ?
3174 result_list.split_read : result_list.internal_limit;
3175 if (
3176 (error_num = spider_db_append_key_where(
3177 NULL, NULL, this))
3178 )
3179 DBUG_RETURN(error_num);
3180 if (sql_kinds & SPIDER_SQL_KIND_SQL)
3181 {
3182 if (result_list.direct_order_limit)
3183 {
3184 if ((error_num =
3185 append_key_order_for_direct_order_limit_with_alias_sql_part(
3186 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
3187 DBUG_RETURN(error_num);
3188 } else {
3189 if ((error_num = append_key_order_with_alias_sql_part(
3190 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
3191 DBUG_RETURN(error_num);
3192 }
3193 if ((error_num = append_limit_sql_part(
3194 result_list.internal_offset,
3195 result_list.limit_num,
3196 SPIDER_SQL_TYPE_SELECT_SQL)))
3197 {
3198 DBUG_RETURN(error_num);
3199 }
3200 if (
3201 (error_num = append_select_lock_sql_part(
3202 SPIDER_SQL_TYPE_SELECT_SQL))
3203 ) {
3204 DBUG_RETURN(error_num);
3205 }
3206 }
3207 if (sql_kinds & SPIDER_SQL_KIND_HANDLER)
3208 {
3209 if ((error_num = append_limit_sql_part(
3210 result_list.internal_offset,
3211 result_list.limit_num,
3212 SPIDER_SQL_TYPE_HANDLER)))
3213 {
3214 DBUG_RETURN(error_num);
3215 }
3216 }
3217
3218 int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok;
3219 tmp_lock_mode = spider_conn_lock_mode(this);
3220 if (tmp_lock_mode)
3221 {
3222 /* "for update" or "lock in share mode" */
3223 link_ok = spider_conn_link_idx_next(share->link_statuses,
3224 conn_link_idx, -1, share->link_count,
3225 SPIDER_LINK_STATUS_OK);
3226 roop_start = spider_conn_link_idx_next(share->link_statuses,
3227 conn_link_idx, -1, share->link_count,
3228 SPIDER_LINK_STATUS_RECOVERY);
3229 roop_end = share->link_count;
3230 } else {
3231 link_ok = search_link_idx;
3232 roop_start = search_link_idx;
3233 roop_end = search_link_idx + 1;
3234 }
3235 for (roop_count = roop_start; roop_count < roop_end;
3236 roop_count = spider_conn_link_idx_next(share->link_statuses,
3237 conn_link_idx, roop_count, share->link_count,
3238 SPIDER_LINK_STATUS_RECOVERY)
3239 ) {
3240#ifndef WITHOUT_SPIDER_BG_SEARCH
3241 if (result_list.bgs_phase > 0)
3242 {
3243 if ((error_num = spider_check_and_init_casual_read(trx->thd, this,
3244 roop_count)))
3245 DBUG_RETURN(error_num);
3246 if ((error_num = spider_bg_conn_search(this, roop_count, roop_start,
3247 TRUE, FALSE, (roop_count != link_ok))))
3248 {
3249 if (
3250 error_num != HA_ERR_END_OF_FILE &&
3251 share->monitoring_kind[roop_count] &&
3252 need_mons[roop_count]
3253 ) {
3254 error_num = spider_ping_table_mon_from_table(
3255 trx,
3256 trx->thd,
3257 share,
3258 roop_count,
3259 (uint32) share->monitoring_sid[roop_count],
3260 share->table_name,
3261 share->table_name_length,
3262 conn_link_idx[roop_count],
3263 NULL,
3264 0,
3265 share->monitoring_kind[roop_count],
3266 share->monitoring_limit[roop_count],
3267 share->monitoring_flag[roop_count],
3268 TRUE
3269 );
3270 }
3271 DBUG_RETURN(check_error_mode_eof(error_num));
3272 }
3273 } else {
3274#endif
3275 ulong sql_type;
3276#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
3277 if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL)
3278 {
3279#endif
3280 conn = conns[roop_count];
3281 if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL)
3282 {
3283 sql_type = SPIDER_SQL_TYPE_SELECT_SQL;
3284 } else {
3285 sql_type = SPIDER_SQL_TYPE_HANDLER;
3286 }
3287#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
3288 } else {
3289 if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ)
3290 conn = hs_r_conns[roop_count];
3291 else
3292 conn = hs_w_conns[roop_count];
3293 sql_type = SPIDER_SQL_TYPE_SELECT_HS;
3294 }
3295#endif
3296 spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id];
3297 if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
3298 {
3299 pthread_mutex_lock(&conn->mta_conn_mutex);
3300 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
3301 }
3302 if ((error_num =
3303 dbton_hdl->set_sql_for_exec(sql_type, roop_count)))
3304 {
3305 DBUG_RETURN(error_num);
3306 }
3307 if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
3308 {
3309 pthread_mutex_lock(&conn->mta_conn_mutex);
3310 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
3311 }
3312 DBUG_PRINT("info",("spider sql_type=%lu", sql_type));
3313#ifdef HA_CAN_BULK_ACCESS
3314 if (is_bulk_access_clone)
3315 {
3316 connection_ids[roop_count] = conn->connection_id;
3317 spider_trx_add_bulk_access_conn(trx, conn);
3318 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
3319 pthread_mutex_unlock(&conn->mta_conn_mutex);
3320 } else {
3321#endif
3322 conn->need_mon = &need_mons[roop_count];
3323 conn->mta_conn_mutex_lock_already = TRUE;
3324 conn->mta_conn_mutex_unlock_later = TRUE;
3325 if ((error_num = spider_db_set_names(this, conn,
3326 roop_count)))
3327 {
3328 conn->mta_conn_mutex_lock_already = FALSE;
3329 conn->mta_conn_mutex_unlock_later = FALSE;
3330 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
3331 pthread_mutex_unlock(&conn->mta_conn_mutex);
3332 if (
3333 share->monitoring_kind[roop_count] &&
3334 need_mons[roop_count]
3335 ) {
3336 error_num = spider_ping_table_mon_from_table(
3337 trx,
3338 trx->thd,
3339 share,
3340 roop_count,
3341 (uint32) share->monitoring_sid[roop_count],
3342 share->table_name,
3343 share->table_name_length,
3344 conn_link_idx[roop_count],
3345 NULL,
3346 0,
3347 share->monitoring_kind[roop_count],
3348 share->monitoring_limit[roop_count],
3349 share->monitoring_flag[roop_count],
3350 TRUE
3351 );
3352 }
3353 DBUG_RETURN(check_error_mode_eof(error_num));
3354 }
3355 spider_conn_set_timeout_from_share(conn, roop_count,
3356 trx->thd, share);
3357 if (dbton_hdl->execute_sql(
3358 sql_type,
3359 conn,
3360 result_list.quick_mode,
3361 &need_mons[roop_count])
3362 ) {
3363 conn->mta_conn_mutex_lock_already = FALSE;
3364 conn->mta_conn_mutex_unlock_later = FALSE;
3365 error_num = spider_db_errorno(conn);
3366 if (
3367 share->monitoring_kind[roop_count] &&
3368 need_mons[roop_count]
3369 ) {
3370 error_num = spider_ping_table_mon_from_table(
3371 trx,
3372 trx->thd,
3373 share,
3374 roop_count,
3375 (uint32) share->monitoring_sid[roop_count],
3376 share->table_name,
3377 share->table_name_length,
3378 conn_link_idx[roop_count],
3379 NULL,
3380 0,
3381 share->monitoring_kind[roop_count],
3382 share->monitoring_limit[roop_count],
3383 share->monitoring_flag[roop_count],
3384 TRUE
3385 );
3386 }
3387 DBUG_RETURN(check_error_mode_eof(error_num));
3388 }
3389 connection_ids[roop_count] = conn->connection_id;
3390 conn->mta_conn_mutex_lock_already = FALSE;
3391 conn->mta_conn_mutex_unlock_later = FALSE;
3392 if (roop_count == link_ok)
3393 {
3394 if ((error_num = spider_db_store_result(this, roop_count, table)))
3395 {
3396 if (
3397 error_num != HA_ERR_END_OF_FILE &&
3398 share->monitoring_kind[roop_count] &&
3399 need_mons[roop_count]
3400 ) {
3401 error_num = spider_ping_table_mon_from_table(
3402 trx,
3403 trx->thd,
3404 share,
3405 roop_count,
3406 (uint32) share->monitoring_sid[roop_count],
3407 share->table_name,
3408 share->table_name_length,
3409 conn_link_idx[roop_count],
3410 NULL,
3411 0,
3412 share->monitoring_kind[roop_count],
3413 share->monitoring_limit[roop_count],
3414 share->monitoring_flag[roop_count],
3415 TRUE
3416 );
3417 }
3418 DBUG_RETURN(check_error_mode_eof(error_num));
3419 }
3420 result_link_idx = link_ok;
3421 } else {
3422 spider_db_discard_result(this, roop_count, conn);
3423 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
3424 pthread_mutex_unlock(&conn->mta_conn_mutex);
3425 }
3426#ifdef HA_CAN_BULK_ACCESS
3427 }
3428#endif
3429#ifndef WITHOUT_SPIDER_BG_SEARCH
3430 }
3431#endif
3432 }
3433 }
3434
3435 if (buf)
3436 {
3437 if (
3438 result_list.sorted &&
3439 result_list.desc_flg
3440 ) {
3441 if ((error_num = spider_db_seek_last(buf, this, search_link_idx, table)))
3442 DBUG_RETURN(check_error_mode_eof(error_num));
3443 DBUG_RETURN(0);
3444 }
3445 if ((error_num = spider_db_seek_first(buf, this, table)))
3446 DBUG_RETURN(check_error_mode_eof(error_num));
3447 }
3448 DBUG_RETURN(0);
3449}
3450
3451int ha_spider::pre_index_first(
3452 bool use_parallel
3453) {
3454 DBUG_ENTER("ha_spider::pre_index_first");
3455 DBUG_PRINT("info",("spider this=%p", this));
3456 check_pre_call(use_parallel);
3457 if (use_pre_call)
3458 {
3459 store_error_num =
3460 index_first_internal(NULL);
3461 DBUG_RETURN(store_error_num);
3462 }
3463 DBUG_RETURN(0);
3464}
3465
3466int ha_spider::index_first(
3467 uchar *buf
3468) {
3469 int error_num;
3470 DBUG_ENTER("ha_spider::index_first");
3471 DBUG_PRINT("info",("spider this=%p", this));
3472 if (use_pre_call)
3473 {
3474 if (store_error_num)
3475 {
3476 if (store_error_num == HA_ERR_END_OF_FILE)
3477 table->status = STATUS_NOT_FOUND;
3478 DBUG_RETURN(store_error_num);
3479 }
3480 if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx)))
3481 DBUG_RETURN(error_num);
3482 use_pre_call = FALSE;
3483 DBUG_RETURN(index_next(buf));
3484 }
3485 DBUG_RETURN(index_first_internal(buf));
3486}
3487
3488int ha_spider::index_last_internal(
3489 uchar *buf
3490) {
3491 int error_num;
3492 SPIDER_CONN *conn;
3493 backup_error_status();
3494 DBUG_ENTER("ha_spider::index_last_internal");
3495 DBUG_PRINT("info",("spider this=%p", this));
3496 if (trx->thd->killed)
3497 {
3498 my_error(ER_QUERY_INTERRUPTED, MYF(0));
3499 DBUG_RETURN(ER_QUERY_INTERRUPTED);
3500 }
3501#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
3502 do_direct_update = FALSE;
3503#endif
3504 if ((error_num = index_handler_init()))
3505 DBUG_RETURN(check_error_mode_eof(error_num));
3506 if (is_clone)
3507 {
3508 DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p",
3509 pt_clone_source_handler));
3510 pt_clone_source_handler->pt_clone_last_searcher = this;
3511 }
3512 if (
3513#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
3514 result_list.hs_has_result ||
3515#endif
3516 sql_is_empty(SPIDER_SQL_TYPE_HANDLER) ||
3517 sql_is_empty(SPIDER_SQL_TYPE_SELECT_SQL)
3518 ) {
3519/*
3520 spider_db_free_one_result_for_start_next(this);
3521*/
3522 if ((error_num = spider_db_free_result(this, FALSE)))
3523 DBUG_RETURN(error_num);
3524 if ((error_num = reset_sql_sql(
3525 SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER)))
3526 DBUG_RETURN(error_num);
3527
3528 check_direct_order_limit();
3529#ifndef WITHOUT_SPIDER_BG_SEARCH
3530 if ((error_num = spider_set_conn_bg_param(this)))
3531 DBUG_RETURN(error_num);
3532#endif
3533#ifdef WITH_PARTITION_STORAGE_ENGINE
3534 check_select_column(FALSE);
3535#endif
3536 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
3537 result_list.finish_flg = FALSE;
3538 result_list.record_num = 0;
3539 if (keyread)
3540 result_list.keyread = TRUE;
3541 else
3542 result_list.keyread = FALSE;
3543 if (
3544 (error_num = spider_db_append_select(this)) ||
3545 (error_num = spider_db_append_select_columns(this))
3546 )
3547 DBUG_RETURN(error_num);
3548 if (
3549 share->key_hint &&
3550 (error_num = append_hint_after_table_sql_part(
3551 SPIDER_SQL_TYPE_SELECT_SQL))
3552 )
3553 DBUG_RETURN(error_num);
3554 set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
3555 result_list.desc_flg = TRUE;
3556 result_list.sorted = TRUE;
3557 result_list.key_info = &table->key_info[active_index];
3558 result_list.key_order = 0;
3559 check_distinct_key_query();
3560 result_list.limit_num =
3561 result_list.internal_limit >= result_list.split_read ?
3562 result_list.split_read : result_list.internal_limit;
3563 if (
3564 (error_num = spider_db_append_key_where(
3565 NULL, NULL, this))
3566 )
3567 DBUG_RETURN(error_num);
3568 if (sql_kinds & SPIDER_SQL_KIND_SQL)
3569 {
3570 if (result_list.direct_order_limit)
3571 {
3572 if ((error_num =
3573 append_key_order_for_direct_order_limit_with_alias_sql_part(
3574 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
3575 DBUG_RETURN(error_num);
3576 } else {
3577 if ((error_num = append_key_order_with_alias_sql_part(
3578 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
3579 DBUG_RETURN(error_num);
3580 }
3581 if ((error_num = append_limit_sql_part(
3582 result_list.internal_offset,
3583 result_list.limit_num,
3584 SPIDER_SQL_TYPE_SELECT_SQL)))
3585 {
3586 DBUG_RETURN(error_num);
3587 }
3588 if (
3589 (error_num = append_select_lock_sql_part(
3590 SPIDER_SQL_TYPE_SELECT_SQL))
3591 ) {
3592 DBUG_RETURN(error_num);
3593 }
3594 }
3595 if (sql_kinds & SPIDER_SQL_KIND_HANDLER)
3596 {
3597 if ((error_num = append_limit_sql_part(
3598 result_list.internal_offset,
3599 result_list.limit_num,
3600 SPIDER_SQL_TYPE_HANDLER)))
3601 {
3602 DBUG_RETURN(error_num);
3603 }
3604 }
3605
3606 int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok;
3607 tmp_lock_mode = spider_conn_lock_mode(this);
3608 if (tmp_lock_mode)
3609 {
3610 /* "for update" or "lock in share mode" */
3611 link_ok = spider_conn_link_idx_next(share->link_statuses,
3612 conn_link_idx, -1, share->link_count,
3613 SPIDER_LINK_STATUS_OK);
3614 roop_start = spider_conn_link_idx_next(share->link_statuses,
3615 conn_link_idx, -1, share->link_count,
3616 SPIDER_LINK_STATUS_RECOVERY);
3617 roop_end = share->link_count;
3618 } else {
3619 link_ok = search_link_idx;
3620 roop_start = search_link_idx;
3621 roop_end = search_link_idx + 1;
3622 }
3623 for (roop_count = roop_start; roop_count < roop_end;
3624 roop_count = spider_conn_link_idx_next(share->link_statuses,
3625 conn_link_idx, roop_count, share->link_count,
3626 SPIDER_LINK_STATUS_RECOVERY)
3627 ) {
3628#ifndef WITHOUT_SPIDER_BG_SEARCH
3629 if (result_list.bgs_phase > 0)
3630 {
3631 if ((error_num = spider_check_and_init_casual_read(trx->thd, this,
3632 roop_count)))
3633 DBUG_RETURN(error_num);
3634 if ((error_num = spider_bg_conn_search(this, roop_count, roop_start,
3635 TRUE, FALSE, (roop_count != link_ok))))
3636 {
3637 if (
3638 error_num != HA_ERR_END_OF_FILE &&
3639 share->monitoring_kind[roop_count] &&
3640 need_mons[roop_count]
3641 ) {
3642 error_num = spider_ping_table_mon_from_table(
3643 trx,
3644 trx->thd,
3645 share,
3646 roop_count,
3647 (uint32) share->monitoring_sid[roop_count],
3648 share->table_name,
3649 share->table_name_length,
3650 conn_link_idx[roop_count],
3651 NULL,
3652 0,
3653 share->monitoring_kind[roop_count],
3654 share->monitoring_limit[roop_count],
3655 share->monitoring_flag[roop_count],
3656 TRUE
3657 );
3658 }
3659 DBUG_RETURN(check_error_mode_eof(error_num));
3660 }
3661 } else {
3662#endif
3663 ulong sql_type;
3664#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
3665 if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL)
3666 {
3667#endif
3668 conn = conns[roop_count];
3669 if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL)
3670 {
3671 sql_type = SPIDER_SQL_TYPE_SELECT_SQL;
3672 } else {
3673 sql_type = SPIDER_SQL_TYPE_HANDLER;
3674 }
3675#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
3676 } else {
3677 if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ)
3678 conn = hs_r_conns[roop_count];
3679 else
3680 conn = hs_w_conns[roop_count];
3681 sql_type = SPIDER_SQL_TYPE_SELECT_HS;
3682 }
3683#endif
3684 spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id];
3685 if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
3686 {
3687 pthread_mutex_lock(&conn->mta_conn_mutex);
3688 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
3689 }
3690 if ((error_num =
3691 dbton_hdl->set_sql_for_exec(sql_type, roop_count)))
3692 {
3693 DBUG_RETURN(error_num);
3694 }
3695 if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
3696 {
3697 pthread_mutex_lock(&conn->mta_conn_mutex);
3698 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
3699 }
3700 DBUG_PRINT("info",("spider sql_type=%lu", sql_type));
3701#ifdef HA_CAN_BULK_ACCESS
3702 if (is_bulk_access_clone)
3703 {
3704 connection_ids[roop_count] = conn->connection_id;
3705 spider_trx_add_bulk_access_conn(trx, conn);
3706 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
3707 pthread_mutex_unlock(&conn->mta_conn_mutex);
3708 } else {
3709#endif
3710 conn->need_mon = &need_mons[roop_count];
3711 conn->mta_conn_mutex_lock_already = TRUE;
3712 conn->mta_conn_mutex_unlock_later = TRUE;
3713 if ((error_num = spider_db_set_names(this, conn,
3714 roop_count)))
3715 {
3716 conn->mta_conn_mutex_lock_already = FALSE;
3717 conn->mta_conn_mutex_unlock_later = FALSE;
3718 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
3719 pthread_mutex_unlock(&conn->mta_conn_mutex);
3720 if (
3721 share->monitoring_kind[roop_count] &&
3722 need_mons[roop_count]
3723 ) {
3724 error_num = spider_ping_table_mon_from_table(
3725 trx,
3726 trx->thd,
3727 share,
3728 roop_count,
3729 (uint32) share->monitoring_sid[roop_count],
3730 share->table_name,
3731 share->table_name_length,
3732 conn_link_idx[roop_count],
3733 NULL,
3734 0,
3735 share->monitoring_kind[roop_count],
3736 share->monitoring_limit[roop_count],
3737 share->monitoring_flag[roop_count],
3738 TRUE
3739 );
3740 }
3741 DBUG_RETURN(check_error_mode_eof(error_num));
3742 }
3743 spider_conn_set_timeout_from_share(conn, roop_count,
3744 trx->thd, share);
3745 if (dbton_hdl->execute_sql(
3746 sql_type,
3747 conn,
3748 result_list.quick_mode,
3749 &need_mons[roop_count])
3750 ) {
3751 conn->mta_conn_mutex_lock_already = FALSE;
3752 conn->mta_conn_mutex_unlock_later = FALSE;
3753 error_num = spider_db_errorno(conn);
3754 if (
3755 share->monitoring_kind[roop_count] &&
3756 need_mons[roop_count]
3757 ) {
3758 error_num = spider_ping_table_mon_from_table(
3759 trx,
3760 trx->thd,
3761 share,
3762 roop_count,
3763 (uint32) share->monitoring_sid[roop_count],
3764 share->table_name,
3765 share->table_name_length,
3766 conn_link_idx[roop_count],
3767 NULL,
3768 0,
3769 share->monitoring_kind[roop_count],
3770 share->monitoring_limit[roop_count],
3771 share->monitoring_flag[roop_count],
3772 TRUE
3773 );
3774 }
3775 DBUG_RETURN(check_error_mode_eof(error_num));
3776 }
3777 connection_ids[roop_count] = conn->connection_id;
3778 conn->mta_conn_mutex_lock_already = FALSE;
3779 conn->mta_conn_mutex_unlock_later = FALSE;
3780 if (roop_count == link_ok)
3781 {
3782 if ((error_num = spider_db_store_result(this, roop_count, table)))
3783 {
3784 if (
3785 error_num != HA_ERR_END_OF_FILE &&
3786 share->monitoring_kind[roop_count] &&
3787 need_mons[roop_count]
3788 ) {
3789 error_num = spider_ping_table_mon_from_table(
3790 trx,
3791 trx->thd,
3792 share,
3793 roop_count,
3794 (uint32) share->monitoring_sid[roop_count],
3795 share->table_name,
3796 share->table_name_length,
3797 conn_link_idx[roop_count],
3798 NULL,
3799 0,
3800 share->monitoring_kind[roop_count],
3801 share->monitoring_limit[roop_count],
3802 share->monitoring_flag[roop_count],
3803 TRUE
3804 );
3805 }
3806 DBUG_RETURN(check_error_mode_eof(error_num));
3807 }
3808 result_link_idx = link_ok;
3809 } else {
3810 spider_db_discard_result(this, roop_count, conn);
3811 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
3812 pthread_mutex_unlock(&conn->mta_conn_mutex);
3813 }
3814#ifdef HA_CAN_BULK_ACCESS
3815 }
3816#endif
3817#ifndef WITHOUT_SPIDER_BG_SEARCH
3818 }
3819#endif
3820 }
3821 }
3822
3823 if (buf)
3824 {
3825 if (
3826 result_list.sorted &&
3827 result_list.desc_flg
3828 ) {
3829 if ((error_num = spider_db_seek_first(buf, this, table)))
3830 DBUG_RETURN(check_error_mode_eof(error_num));
3831 DBUG_RETURN(0);
3832 }
3833 if ((error_num = spider_db_seek_last(buf, this, search_link_idx, table)))
3834 DBUG_RETURN(check_error_mode_eof(error_num));
3835 }
3836 DBUG_RETURN(0);
3837}
3838
3839int ha_spider::pre_index_last(
3840 bool use_parallel
3841) {
3842 DBUG_ENTER("ha_spider::pre_index_last");
3843 DBUG_PRINT("info",("spider this=%p", this));
3844 check_pre_call(use_parallel);
3845 if (use_pre_call)
3846 {
3847 store_error_num =
3848 index_last_internal(NULL);
3849 DBUG_RETURN(store_error_num);
3850 }
3851 DBUG_RETURN(0);
3852}
3853
3854int ha_spider::index_last(
3855 uchar *buf
3856) {
3857 int error_num;
3858 DBUG_ENTER("ha_spider::index_last");
3859 DBUG_PRINT("info",("spider this=%p", this));
3860 if (use_pre_call)
3861 {
3862 if (store_error_num)
3863 {
3864 if (store_error_num == HA_ERR_END_OF_FILE)
3865 table->status = STATUS_NOT_FOUND;
3866 DBUG_RETURN(store_error_num);
3867 }
3868 if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx)))
3869 DBUG_RETURN(error_num);
3870 use_pre_call = FALSE;
3871 DBUG_RETURN(index_prev(buf));
3872 }
3873 DBUG_RETURN(index_last_internal(buf));
3874}
3875
3876int ha_spider::index_next_same(
3877 uchar *buf,
3878 const uchar *key,
3879 uint keylen
3880) {
3881 int error_num;
3882 backup_error_status();
3883 DBUG_ENTER("ha_spider::index_next_same");
3884 DBUG_PRINT("info",("spider this=%p", this));
3885 if (trx->thd->killed)
3886 {
3887 my_error(ER_QUERY_INTERRUPTED, MYF(0));
3888 DBUG_RETURN(ER_QUERY_INTERRUPTED);
3889 }
3890#ifdef HA_CAN_BULK_ACCESS
3891 DBUG_ASSERT(!bulk_access_started);
3892 if (bulk_access_executing)
3893 {
3894 if (
3895 !is_bulk_access_clone &&
3896 bulk_access_link_exec_tgt->called
3897 ) {
3898 error_num = bulk_access_link_exec_tgt->spider->index_next_same(buf, key,
3899 keylen);
3900 if (error_num)
3901 DBUG_RETURN(check_error_mode(error_num));
3902 DBUG_RETURN(0);
3903 }
3904 }
3905#endif
3906 if (is_clone)
3907 {
3908 DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p",
3909 pt_clone_source_handler));
3910 pt_clone_source_handler->pt_clone_last_searcher = this;
3911 }
3912 if (
3913 result_list.sorted &&
3914 result_list.desc_flg
3915 ) {
3916 if ((error_num = spider_db_seek_prev(buf, this, table)))
3917 DBUG_RETURN(check_error_mode_eof(error_num));
3918 DBUG_RETURN(0);
3919 }
3920 if ((error_num = spider_db_seek_next(buf, this, search_link_idx, table)))
3921 DBUG_RETURN(check_error_mode_eof(error_num));
3922 DBUG_RETURN(0);
3923}
3924
3925int ha_spider::read_range_first_internal(
3926 uchar *buf,
3927 const key_range *start_key,
3928 const key_range *end_key,
3929 bool eq_range,
3930 bool sorted
3931) {
3932 int error_num;
3933 SPIDER_CONN *conn;
3934 backup_error_status();
3935 DBUG_ENTER("ha_spider::read_range_first_internal");
3936 DBUG_PRINT("info",("spider this=%p", this));
3937 if (trx->thd->killed)
3938 {
3939 my_error(ER_QUERY_INTERRUPTED, MYF(0));
3940 DBUG_RETURN(ER_QUERY_INTERRUPTED);
3941 }
3942#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
3943 do_direct_update = FALSE;
3944#endif
3945 if (
3946 start_key &&
3947 start_key->flag >= HA_READ_MBR_CONTAIN &&
3948 start_key->flag <= HA_READ_MBR_EQUAL
3949 )
3950 use_spatial_index = TRUE;
3951
3952 if (end_key)
3953 {
3954 key_compare_result_on_equal =
3955 ((end_key->flag == HA_READ_BEFORE_KEY) ? 1 :
3956 (end_key->flag == HA_READ_AFTER_KEY) ? -1 : 0);
3957 }
3958 range_key_part = table->key_info[active_index].key_part;
3959
3960 if ((error_num = index_handler_init()))
3961 DBUG_RETURN(check_error_mode_eof(error_num));
3962 if (is_clone)
3963 {
3964 DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p",
3965 pt_clone_source_handler));
3966 pt_clone_source_handler->pt_clone_last_searcher = this;
3967 }
3968 spider_db_free_one_result_for_start_next(this);
3969 check_direct_order_limit();
3970 if ((error_num = reset_sql_sql(
3971 SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER)))
3972 DBUG_RETURN(error_num);
3973#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
3974 if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS)))
3975 DBUG_RETURN(error_num);
3976#endif
3977#ifndef WITHOUT_SPIDER_BG_SEARCH
3978 if ((error_num = spider_set_conn_bg_param(this)))
3979 DBUG_RETURN(error_num);
3980#endif
3981#ifdef WITH_PARTITION_STORAGE_ENGINE
3982 check_select_column(FALSE);
3983#endif
3984 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
3985 result_list.finish_flg = FALSE;
3986 result_list.record_num = 0;
3987 if (keyread)
3988 result_list.keyread = TRUE;
3989 else
3990 result_list.keyread = FALSE;
3991 if (
3992 (error_num = spider_db_append_select(this)) ||
3993 (error_num = spider_db_append_select_columns(this))
3994 )
3995 DBUG_RETURN(error_num);
3996 if (
3997 share->key_hint &&
3998 (error_num = append_hint_after_table_sql_part(
3999 SPIDER_SQL_TYPE_SELECT_SQL))
4000 )
4001 DBUG_RETURN(error_num);
4002 set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
4003 result_list.desc_flg = FALSE;
4004 result_list.sorted = sorted;
4005 result_list.key_info = &table->key_info[active_index];
4006 check_distinct_key_query();
4007 result_list.limit_num =
4008 result_list.internal_limit >= result_list.split_read ?
4009 result_list.split_read : result_list.internal_limit;
4010 DBUG_PRINT("info",("spider limit_num=%lld", result_list.limit_num));
4011 if (
4012 (error_num = spider_db_append_key_where(
4013 start_key, eq_range ? NULL : end_key, this))
4014 )
4015 DBUG_RETURN(error_num);
4016 if (sql_kinds & SPIDER_SQL_KIND_SQL)
4017 {
4018 if (result_list.direct_order_limit)
4019 {
4020 if ((error_num =
4021 append_key_order_for_direct_order_limit_with_alias_sql_part(
4022 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
4023 DBUG_RETURN(error_num);
4024 } else {
4025 if ((error_num = append_key_order_with_alias_sql_part(
4026 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
4027 DBUG_RETURN(error_num);
4028 }
4029 if ((error_num = append_limit_sql_part(
4030 result_list.internal_offset,
4031 result_list.limit_num,
4032 SPIDER_SQL_TYPE_SELECT_SQL)))
4033 {
4034 DBUG_RETURN(error_num);
4035 }
4036 if (
4037 (error_num = append_select_lock_sql_part(
4038 SPIDER_SQL_TYPE_SELECT_SQL))
4039 ) {
4040 DBUG_RETURN(error_num);
4041 }
4042 }
4043 if (sql_kinds & SPIDER_SQL_KIND_HANDLER)
4044 {
4045 if ((error_num = append_limit_sql_part(
4046 result_list.internal_offset,
4047 result_list.limit_num,
4048 SPIDER_SQL_TYPE_HANDLER)))
4049 {
4050 DBUG_RETURN(error_num);
4051 }
4052 }
4053
4054 int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok;
4055 tmp_lock_mode = spider_conn_lock_mode(this);
4056 if (tmp_lock_mode)
4057 {
4058 /* "for update" or "lock in share mode" */
4059 link_ok = spider_conn_link_idx_next(share->link_statuses,
4060 conn_link_idx, -1, share->link_count,
4061 SPIDER_LINK_STATUS_OK);
4062 roop_start = spider_conn_link_idx_next(share->link_statuses,
4063 conn_link_idx, -1, share->link_count,
4064 SPIDER_LINK_STATUS_RECOVERY);
4065 roop_end = share->link_count;
4066 } else {
4067 link_ok = search_link_idx;
4068 roop_start = search_link_idx;
4069 roop_end = search_link_idx + 1;
4070 }
4071 for (roop_count = roop_start; roop_count < roop_end;
4072 roop_count = spider_conn_link_idx_next(share->link_statuses,
4073 conn_link_idx, roop_count, share->link_count,
4074 SPIDER_LINK_STATUS_RECOVERY)
4075 ) {
4076#ifndef WITHOUT_SPIDER_BG_SEARCH
4077 if (result_list.bgs_phase > 0)
4078 {
4079 if ((error_num = spider_check_and_init_casual_read(trx->thd, this,
4080 roop_count)))
4081 DBUG_RETURN(error_num);
4082 if ((error_num = spider_bg_conn_search(this, roop_count, roop_start,
4083 TRUE, FALSE, (roop_count != link_ok))))
4084 {
4085 if (
4086 error_num != HA_ERR_END_OF_FILE &&
4087 share->monitoring_kind[roop_count] &&
4088 need_mons[roop_count]
4089 ) {
4090 error_num = spider_ping_table_mon_from_table(
4091 trx,
4092 trx->thd,
4093 share,
4094 roop_count,
4095 (uint32) share->monitoring_sid[roop_count],
4096 share->table_name,
4097 share->table_name_length,
4098 conn_link_idx[roop_count],
4099 NULL,
4100 0,
4101 share->monitoring_kind[roop_count],
4102 share->monitoring_limit[roop_count],
4103 share->monitoring_flag[roop_count],
4104 TRUE
4105 );
4106 }
4107 DBUG_RETURN(check_error_mode_eof(error_num));
4108 }
4109 } else {
4110#endif
4111 ulong sql_type;
4112#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4113 if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL)
4114 {
4115#endif
4116 conn = conns[roop_count];
4117 if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL)
4118 {
4119 sql_type = SPIDER_SQL_TYPE_SELECT_SQL;
4120 } else {
4121 sql_type = SPIDER_SQL_TYPE_HANDLER;
4122 }
4123#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4124 } else {
4125 if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ)
4126 conn = hs_r_conns[roop_count];
4127 else
4128 conn = hs_w_conns[roop_count];
4129 sql_type = SPIDER_SQL_TYPE_SELECT_HS;
4130 }
4131#endif
4132 spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id];
4133 if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
4134 {
4135 pthread_mutex_lock(&conn->mta_conn_mutex);
4136 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
4137 }
4138 if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count)))
4139 {
4140 DBUG_RETURN(error_num);
4141 }
4142 if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
4143 {
4144 pthread_mutex_lock(&conn->mta_conn_mutex);
4145 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
4146 }
4147 DBUG_PRINT("info",("spider sql_type=%lu", sql_type));
4148#ifdef HA_CAN_BULK_ACCESS
4149 if (is_bulk_access_clone)
4150 {
4151 connection_ids[roop_count] = conn->connection_id;
4152 spider_trx_add_bulk_access_conn(trx, conn);
4153 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
4154 pthread_mutex_unlock(&conn->mta_conn_mutex);
4155 } else {
4156#endif
4157 conn->need_mon = &need_mons[roop_count];
4158 conn->mta_conn_mutex_lock_already = TRUE;
4159 conn->mta_conn_mutex_unlock_later = TRUE;
4160 if ((error_num = spider_db_set_names(this, conn,
4161 roop_count)))
4162 {
4163 conn->mta_conn_mutex_lock_already = FALSE;
4164 conn->mta_conn_mutex_unlock_later = FALSE;
4165 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
4166 pthread_mutex_unlock(&conn->mta_conn_mutex);
4167 if (
4168 share->monitoring_kind[roop_count] &&
4169 need_mons[roop_count]
4170 ) {
4171 error_num = spider_ping_table_mon_from_table(
4172 trx,
4173 trx->thd,
4174 share,
4175 roop_count,
4176 (uint32) share->monitoring_sid[roop_count],
4177 share->table_name,
4178 share->table_name_length,
4179 conn_link_idx[roop_count],
4180 NULL,
4181 0,
4182 share->monitoring_kind[roop_count],
4183 share->monitoring_limit[roop_count],
4184 share->monitoring_flag[roop_count],
4185 TRUE
4186 );
4187 }
4188 DBUG_RETURN(check_error_mode_eof(error_num));
4189 }
4190 spider_conn_set_timeout_from_share(conn, roop_count,
4191 trx->thd, share);
4192 if (dbton_hdl->execute_sql(
4193 sql_type,
4194 conn,
4195 result_list.quick_mode,
4196 &need_mons[roop_count])
4197 ) {
4198 conn->mta_conn_mutex_lock_already = FALSE;
4199 conn->mta_conn_mutex_unlock_later = FALSE;
4200 error_num = spider_db_errorno(conn);
4201 if (
4202 share->monitoring_kind[roop_count] &&
4203 need_mons[roop_count]
4204 ) {
4205 error_num = spider_ping_table_mon_from_table(
4206 trx,
4207 trx->thd,
4208 share,
4209 roop_count,
4210 (uint32) share->monitoring_sid[roop_count],
4211 share->table_name,
4212 share->table_name_length,
4213 conn_link_idx[roop_count],
4214 NULL,
4215 0,
4216 share->monitoring_kind[roop_count],
4217 share->monitoring_limit[roop_count],
4218 share->monitoring_flag[roop_count],
4219 TRUE
4220 );
4221 }
4222 DBUG_RETURN(check_error_mode_eof(error_num));
4223 }
4224 connection_ids[roop_count] = conn->connection_id;
4225 conn->mta_conn_mutex_lock_already = FALSE;
4226 conn->mta_conn_mutex_unlock_later = FALSE;
4227 if (roop_count == link_ok)
4228 {
4229 if ((error_num = spider_db_store_result(this, roop_count, table)))
4230 {
4231 if (
4232 error_num != HA_ERR_END_OF_FILE &&
4233 share->monitoring_kind[roop_count] &&
4234 need_mons[roop_count]
4235 ) {
4236 error_num = spider_ping_table_mon_from_table(
4237 trx,
4238 trx->thd,
4239 share,
4240 roop_count,
4241 (uint32) share->monitoring_sid[roop_count],
4242 share->table_name,
4243 share->table_name_length,
4244 conn_link_idx[roop_count],
4245 NULL,
4246 0,
4247 share->monitoring_kind[roop_count],
4248 share->monitoring_limit[roop_count],
4249 share->monitoring_flag[roop_count],
4250 TRUE
4251 );
4252 }
4253 DBUG_RETURN(check_error_mode_eof(error_num));
4254 }
4255 result_link_idx = link_ok;
4256 } else {
4257 spider_db_discard_result(this, roop_count, conn);
4258 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
4259 pthread_mutex_unlock(&conn->mta_conn_mutex);
4260 }
4261#ifdef HA_CAN_BULK_ACCESS
4262 }
4263#endif
4264#ifndef WITHOUT_SPIDER_BG_SEARCH
4265 }
4266#endif
4267 }
4268 if (buf && (error_num = spider_db_fetch(buf, this, table)))
4269 DBUG_RETURN(check_error_mode_eof(error_num));
4270 DBUG_RETURN(0);
4271}
4272
4273int ha_spider::pre_read_range_first(
4274 const key_range *start_key,
4275 const key_range *end_key,
4276 bool eq_range,
4277 bool sorted,
4278 bool use_parallel
4279) {
4280 DBUG_ENTER("ha_spider::pre_read_range_first");
4281 DBUG_PRINT("info",("spider this=%p", this));
4282 check_pre_call(use_parallel);
4283 if (use_pre_call)
4284 {
4285 store_error_num =
4286 read_range_first_internal(NULL, start_key, end_key, eq_range, sorted);
4287 DBUG_RETURN(store_error_num);
4288 }
4289 DBUG_RETURN(0);
4290}
4291
4292int ha_spider::read_range_first(
4293 const key_range *start_key,
4294 const key_range *end_key,
4295 bool eq_range,
4296 bool sorted
4297) {
4298 int error_num;
4299 DBUG_ENTER("ha_spider::read_range_first");
4300 DBUG_PRINT("info",("spider this=%p", this));
4301 if (use_pre_call)
4302 {
4303 if (store_error_num)
4304 {
4305 if (store_error_num == HA_ERR_END_OF_FILE)
4306 table->status = STATUS_NOT_FOUND;
4307 DBUG_RETURN(store_error_num);
4308 }
4309 if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx)))
4310 DBUG_RETURN(error_num);
4311 use_pre_call = FALSE;
4312 if ((error_num = read_range_next()))
4313 DBUG_RETURN(error_num);
4314 DBUG_RETURN(check_ha_range_eof());
4315 }
4316 if ((error_num = read_range_first_internal(table->record[0], start_key,
4317 end_key, eq_range, sorted)))
4318 DBUG_RETURN(error_num);
4319 DBUG_RETURN(check_ha_range_eof());
4320}
4321
4322int ha_spider::read_range_next()
4323{
4324 int error_num;
4325 backup_error_status();
4326 DBUG_ENTER("ha_spider::read_range_next");
4327 DBUG_PRINT("info",("spider this=%p", this));
4328 if (trx->thd->killed)
4329 {
4330 my_error(ER_QUERY_INTERRUPTED, MYF(0));
4331 DBUG_RETURN(ER_QUERY_INTERRUPTED);
4332 }
4333 if (is_clone)
4334 {
4335 DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p",
4336 pt_clone_source_handler));
4337 pt_clone_source_handler->pt_clone_last_searcher = this;
4338 }
4339 if (
4340 result_list.sorted &&
4341 result_list.desc_flg
4342 ) {
4343 if ((error_num = spider_db_seek_prev(table->record[0], this, table)))
4344 DBUG_RETURN(check_error_mode_eof(error_num));
4345 DBUG_RETURN(0);
4346 }
4347 if ((error_num = spider_db_seek_next(table->record[0], this, search_link_idx,
4348 table)))
4349 DBUG_RETURN(check_error_mode_eof(error_num));
4350 DBUG_RETURN(check_ha_range_eof());
4351}
4352
4353#ifdef HA_MRR_USE_DEFAULT_IMPL
4354#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
4355ha_rows ha_spider::multi_range_read_info_const(
4356 uint keyno,
4357 RANGE_SEQ_IF *seq,
4358 void *seq_init_param,
4359 uint n_ranges,
4360 uint *bufsz,
4361 uint *flags,
4362 Cost_estimate *cost
4363)
4364#else
4365ha_rows ha_spider::multi_range_read_info_const(
4366 uint keyno,
4367 RANGE_SEQ_IF *seq,
4368 void *seq_init_param,
4369 uint n_ranges,
4370 uint *bufsz,
4371 uint *flags,
4372 COST_VECT *cost
4373)
4374#endif
4375{
4376 DBUG_ENTER("ha_spider::multi_range_read_info_const");
4377 DBUG_PRINT("info",("spider this=%p", this));
4378 if (!pre_bitmap_checked)
4379 {
4380 if (result_list.lock_type == F_WRLCK)
4381 {
4382 pk_update = FALSE;
4383 if (
4384 update_request &&
4385 share->have_recovery_link &&
4386 (pk_update = spider_check_pk_update(table))
4387 ) {
4388 bitmap_set_all(table->read_set);
4389 if (is_clone)
4390 memset(searched_bitmap, 0xFF, no_bytes_in_map(table->read_set));
4391 }
4392 }
4393
4394 if (!is_clone)
4395 set_select_column_mode();
4396
4397 pre_bitmap_checked = TRUE;
4398 }
4399/*
4400 multi_range_num = n_ranges;
4401 mrr_have_range = FALSE;
4402*/
4403 ha_rows rows =
4404 handler::multi_range_read_info_const(
4405 keyno,
4406 seq,
4407 seq_init_param,
4408 n_ranges,
4409 bufsz,
4410 flags,
4411 cost
4412 );
4413 *flags &= ~HA_MRR_USE_DEFAULT_IMPL;
4414 DBUG_PRINT("info",("spider rows=%llu", rows));
4415 DBUG_RETURN(rows);
4416}
4417
4418#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
4419ha_rows ha_spider::multi_range_read_info(
4420 uint keyno,
4421 uint n_ranges,
4422 uint keys,
4423 uint key_parts,
4424 uint *bufsz,
4425 uint *flags,
4426 Cost_estimate *cost
4427)
4428#else
4429ha_rows ha_spider::multi_range_read_info(
4430 uint keyno,
4431 uint n_ranges,
4432 uint keys,
4433 uint key_parts,
4434 uint *bufsz,
4435 uint *flags,
4436 COST_VECT *cost
4437)
4438#endif
4439{
4440 DBUG_ENTER("ha_spider::multi_range_read_info");
4441 DBUG_PRINT("info",("spider this=%p", this));
4442 if (!pre_bitmap_checked)
4443 {
4444 if (result_list.lock_type == F_WRLCK)
4445 {
4446 pk_update = FALSE;
4447 if (
4448 update_request &&
4449 share->have_recovery_link &&
4450 (pk_update = spider_check_pk_update(table))
4451 ) {
4452 bitmap_set_all(table->read_set);
4453 if (is_clone)
4454 memset(searched_bitmap, 0xFF, no_bytes_in_map(table->read_set));
4455 }
4456 }
4457
4458 if (!is_clone)
4459 set_select_column_mode();
4460
4461 pre_bitmap_checked = TRUE;
4462 }
4463/*
4464 multi_range_num = n_ranges;
4465 mrr_have_range = FALSE;
4466*/
4467 ha_rows rows =
4468 handler::multi_range_read_info(
4469 keyno,
4470 n_ranges,
4471 keys,
4472 key_parts,
4473 bufsz,
4474 flags,
4475 cost
4476 );
4477 *flags &= ~HA_MRR_USE_DEFAULT_IMPL;
4478 DBUG_PRINT("info",("spider rows=%llu", rows));
4479 DBUG_RETURN(rows);
4480}
4481
4482int ha_spider::multi_range_read_init(
4483 RANGE_SEQ_IF *seq,
4484 void *seq_init_param,
4485 uint n_ranges,
4486 uint mode,
4487 HANDLER_BUFFER *buf
4488) {
4489 bka_mode = spider_param_bka_mode(trx->thd, share->bka_mode);
4490 backup_error_status();
4491 DBUG_ENTER("ha_spider::multi_range_read_init");
4492 DBUG_PRINT("info",("spider this=%p", this));
4493 DBUG_PRINT("info",("spider n_ranges=%u", n_ranges));
4494 multi_range_num = n_ranges;
4495 mrr_have_range = FALSE;
4496 DBUG_RETURN(
4497 handler::multi_range_read_init(
4498 seq,
4499 seq_init_param,
4500 n_ranges,
4501 mode,
4502 buf
4503 )
4504 );
4505}
4506#endif
4507
4508#ifdef HA_MRR_USE_DEFAULT_IMPL
4509#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
4510int ha_spider::multi_range_read_next_first(
4511 range_id_t *range_info
4512)
4513#else
4514int ha_spider::multi_range_read_next_first(
4515 char **range_info
4516)
4517#endif
4518#else
4519int ha_spider::read_multi_range_first_internal(
4520 uchar *buf,
4521 KEY_MULTI_RANGE **found_range_p,
4522 KEY_MULTI_RANGE *ranges,
4523 uint range_count,
4524 bool sorted,
4525 HANDLER_BUFFER *buffer
4526)
4527#endif
4528{
4529 int error_num, roop_count;
4530 SPIDER_CONN *conn;
4531#ifdef HA_MRR_USE_DEFAULT_IMPL
4532 int range_res;
4533 backup_error_status();
4534 DBUG_ENTER("ha_spider::multi_range_read_next_first");
4535#else
4536 bka_mode = spider_param_bka_mode(trx->thd, share->bka_mode);
4537 backup_error_status();
4538 DBUG_ENTER("ha_spider::read_multi_range_first_internal");
4539#endif
4540 DBUG_PRINT("info",("spider this=%p", this));
4541 if (trx->thd->killed)
4542 {
4543 my_error(ER_QUERY_INTERRUPTED, MYF(0));
4544 DBUG_RETURN(ER_QUERY_INTERRUPTED);
4545 }
4546#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
4547 do_direct_update = FALSE;
4548#endif
4549 if ((error_num = index_handler_init()))
4550 DBUG_RETURN(check_error_mode_eof(error_num));
4551 if (is_clone)
4552 {
4553 DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p",
4554 pt_clone_source_handler));
4555 pt_clone_source_handler->pt_clone_last_searcher = this;
4556 }
4557#ifdef HA_MRR_USE_DEFAULT_IMPL
4558#else
4559 multi_range_sorted = sorted;
4560 multi_range_buffer = buffer;
4561#endif
4562
4563 spider_db_free_one_result_for_start_next(this);
4564 check_direct_order_limit();
4565#ifndef WITHOUT_SPIDER_BG_SEARCH
4566 if ((error_num = spider_set_conn_bg_param(this)))
4567 DBUG_RETURN(error_num);
4568#endif
4569#ifdef WITH_PARTITION_STORAGE_ENGINE
4570 check_select_column(FALSE);
4571#endif
4572 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
4573 result_list.finish_flg = FALSE;
4574 result_list.record_num = 0;
4575 if ((error_num = reset_sql_sql(
4576 SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER)))
4577 DBUG_RETURN(error_num);
4578#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4579 if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS)))
4580 DBUG_RETURN(error_num);
4581#endif
4582 result_list.desc_flg = FALSE;
4583#ifdef HA_MRR_USE_DEFAULT_IMPL
4584 result_list.sorted = mrr_is_output_sorted;
4585#else
4586 result_list.sorted = sorted;
4587#endif
4588 result_list.key_info = &table->key_info[active_index];
4589 if (
4590#ifdef HA_MRR_USE_DEFAULT_IMPL
4591 multi_range_num == 1 ||
4592#endif
4593 result_list.multi_split_read <= 1 ||
4594 (sql_kinds & SPIDER_SQL_KIND_HANDLER)
4595 ) {
4596 if (keyread)
4597 result_list.keyread = TRUE;
4598 else
4599 result_list.keyread = FALSE;
4600 mrr_with_cnt = FALSE;
4601 if (
4602 (error_num = spider_db_append_select(this)) ||
4603 (error_num = spider_db_append_select_columns(this))
4604 )
4605 DBUG_RETURN(error_num);
4606 if (
4607 share->key_hint &&
4608 (error_num = append_hint_after_table_sql_part(
4609 SPIDER_SQL_TYPE_SELECT_SQL))
4610 )
4611 DBUG_RETURN(error_num);
4612 set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
4613#ifdef HA_MRR_USE_DEFAULT_IMPL
4614 error_num = HA_ERR_END_OF_FILE;
4615 while (!(range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range)))
4616#else
4617 for (
4618 multi_range_curr = ranges,
4619 multi_range_end = ranges + range_count;
4620 multi_range_curr < multi_range_end;
4621 multi_range_curr++
4622 )
4623#endif
4624 {
4625#ifdef HA_MRR_USE_DEFAULT_IMPL
4626 DBUG_PRINT("info",("spider range_res1=%d", range_res));
4627#endif
4628 result_list.limit_num =
4629 result_list.internal_limit - result_list.record_num >=
4630 result_list.split_read ?
4631 result_list.split_read :
4632 result_list.internal_limit - result_list.record_num;
4633 DBUG_PRINT("info",("spider limit_num=%lld", result_list.limit_num));
4634 if (
4635#ifdef HA_MRR_USE_DEFAULT_IMPL
4636 (error_num = spider_db_append_key_where(
4637 &mrr_cur_range.start_key,
4638 SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) ?
4639 NULL : &mrr_cur_range.end_key, this))
4640#else
4641 (error_num = spider_db_append_key_where(
4642 &multi_range_curr->start_key,
4643 SPIDER_TEST(multi_range_curr->range_flag & EQ_RANGE) ?
4644 NULL : &multi_range_curr->end_key, this))
4645#endif
4646 )
4647 DBUG_RETURN(error_num);
4648 if (sql_kinds & SPIDER_SQL_KIND_SQL)
4649 {
4650 if (result_list.direct_order_limit)
4651 {
4652 if ((error_num =
4653 append_key_order_for_direct_order_limit_with_alias_sql_part(
4654 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
4655 DBUG_RETURN(error_num);
4656 } else {
4657 if ((error_num = append_key_order_with_alias_sql_part(
4658 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
4659 DBUG_RETURN(error_num);
4660 }
4661 if ((error_num = append_limit_sql_part(
4662 result_list.internal_offset + result_list.record_num,
4663 result_list.limit_num,
4664 SPIDER_SQL_TYPE_SELECT_SQL)))
4665 {
4666 DBUG_RETURN(error_num);
4667 }
4668 if (
4669 (error_num = append_select_lock_sql_part(
4670 SPIDER_SQL_TYPE_SELECT_SQL))
4671 ) {
4672 DBUG_RETURN(error_num);
4673 }
4674 }
4675 if (sql_kinds & SPIDER_SQL_KIND_HANDLER)
4676 {
4677 if ((error_num = append_limit_sql_part(
4678 result_list.internal_offset + result_list.record_num,
4679 result_list.limit_num,
4680 SPIDER_SQL_TYPE_HANDLER)))
4681 {
4682 DBUG_RETURN(error_num);
4683 }
4684 }
4685
4686 int roop_start, roop_end, tmp_lock_mode, link_ok;
4687 tmp_lock_mode = spider_conn_lock_mode(this);
4688 if (tmp_lock_mode)
4689 {
4690 /* "for update" or "lock in share mode" */
4691 link_ok = spider_conn_link_idx_next(share->link_statuses,
4692 conn_link_idx, -1, share->link_count,
4693 SPIDER_LINK_STATUS_OK);
4694 roop_start = spider_conn_link_idx_next(share->link_statuses,
4695 conn_link_idx, -1, share->link_count,
4696 SPIDER_LINK_STATUS_RECOVERY);
4697 roop_end = share->link_count;
4698 } else {
4699 link_ok = search_link_idx;
4700 roop_start = search_link_idx;
4701 roop_end = search_link_idx + 1;
4702 }
4703 for (roop_count = roop_start; roop_count < roop_end;
4704 roop_count = spider_conn_link_idx_next(share->link_statuses,
4705 conn_link_idx, roop_count, share->link_count,
4706 SPIDER_LINK_STATUS_RECOVERY)
4707 ) {
4708#ifndef WITHOUT_SPIDER_BG_SEARCH
4709 if (result_list.bgs_phase > 0)
4710 {
4711 if ((error_num = spider_check_and_init_casual_read(trx->thd, this,
4712 roop_count)))
4713 DBUG_RETURN(error_num);
4714 error_num = spider_bg_conn_search(this, roop_count, roop_start,
4715 TRUE, FALSE, (roop_count != link_ok));
4716 if (
4717 error_num &&
4718 error_num != HA_ERR_END_OF_FILE &&
4719 share->monitoring_kind[roop_count] &&
4720 need_mons[roop_count]
4721 ) {
4722 error_num = spider_ping_table_mon_from_table(
4723 trx,
4724 trx->thd,
4725 share,
4726 roop_count,
4727 (uint32) share->monitoring_sid[roop_count],
4728 share->table_name,
4729 share->table_name_length,
4730 conn_link_idx[roop_count],
4731 NULL,
4732 0,
4733 share->monitoring_kind[roop_count],
4734 share->monitoring_limit[roop_count],
4735 share->monitoring_flag[roop_count],
4736 TRUE
4737 );
4738 }
4739 } else {
4740#endif
4741 ulong sql_type;
4742#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4743 if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL)
4744 {
4745#endif
4746 conn = conns[roop_count];
4747 if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL)
4748 {
4749 sql_type = SPIDER_SQL_TYPE_SELECT_SQL;
4750 } else {
4751 sql_type = SPIDER_SQL_TYPE_HANDLER;
4752 }
4753#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4754 } else {
4755 if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ)
4756 conn = hs_r_conns[roop_count];
4757 else
4758 conn = hs_w_conns[roop_count];
4759 sql_type = SPIDER_SQL_TYPE_SELECT_HS;
4760 }
4761#endif
4762 spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id];
4763 if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
4764 {
4765 pthread_mutex_lock(&conn->mta_conn_mutex);
4766 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
4767 }
4768 if ((error_num =
4769 dbton_hdl->set_sql_for_exec(sql_type, roop_count)))
4770 {
4771 DBUG_RETURN(error_num);
4772 }
4773 if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
4774 {
4775 pthread_mutex_lock(&conn->mta_conn_mutex);
4776 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
4777 }
4778 DBUG_PRINT("info",("spider sql_type=%lu", sql_type));
4779#ifdef HA_CAN_BULK_ACCESS
4780 if (is_bulk_access_clone)
4781 {
4782 connection_ids[roop_count] = conn->connection_id;
4783 spider_trx_add_bulk_access_conn(trx, conn);
4784 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
4785 pthread_mutex_unlock(&conn->mta_conn_mutex);
4786#ifdef HA_MRR_USE_DEFAULT_IMPL
4787 *range_info = (char *) mrr_cur_range.ptr;
4788#else
4789 *found_range_p = multi_range_curr;
4790#endif
4791 DBUG_RETURN(0);
4792 } else {
4793#endif
4794 conn->need_mon = &need_mons[roop_count];
4795 conn->mta_conn_mutex_lock_already = TRUE;
4796 conn->mta_conn_mutex_unlock_later = TRUE;
4797 if ((error_num = spider_db_set_names(this, conn,
4798 roop_count)))
4799 {
4800 conn->mta_conn_mutex_lock_already = FALSE;
4801 conn->mta_conn_mutex_unlock_later = FALSE;
4802 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
4803 pthread_mutex_unlock(&conn->mta_conn_mutex);
4804 if (
4805 share->monitoring_kind[roop_count] &&
4806 need_mons[roop_count]
4807 ) {
4808 error_num = spider_ping_table_mon_from_table(
4809 trx,
4810 trx->thd,
4811 share,
4812 roop_count,
4813 (uint32) share->monitoring_sid[roop_count],
4814 share->table_name,
4815 share->table_name_length,
4816 conn_link_idx[roop_count],
4817 NULL,
4818 0,
4819 share->monitoring_kind[roop_count],
4820 share->monitoring_limit[roop_count],
4821 share->monitoring_flag[roop_count],
4822 TRUE
4823 );
4824 }
4825 }
4826 if (!error_num)
4827 {
4828 spider_conn_set_timeout_from_share(conn, roop_count,
4829 trx->thd, share);
4830 if (dbton_hdl->execute_sql(
4831 sql_type,
4832 conn,
4833 result_list.quick_mode,
4834 &need_mons[roop_count])
4835 ) {
4836 conn->mta_conn_mutex_lock_already = FALSE;
4837 conn->mta_conn_mutex_unlock_later = FALSE;
4838 error_num = spider_db_errorno(conn);
4839 if (
4840 share->monitoring_kind[roop_count] &&
4841 need_mons[roop_count]
4842 ) {
4843 error_num = spider_ping_table_mon_from_table(
4844 trx,
4845 trx->thd,
4846 share,
4847 roop_count,
4848 (uint32) share->monitoring_sid[roop_count],
4849 share->table_name,
4850 share->table_name_length,
4851 conn_link_idx[roop_count],
4852 NULL,
4853 0,
4854 share->monitoring_kind[roop_count],
4855 share->monitoring_limit[roop_count],
4856 share->monitoring_flag[roop_count],
4857 TRUE
4858 );
4859 }
4860 }
4861 }
4862 if (!error_num)
4863 {
4864 connection_ids[roop_count] = conn->connection_id;
4865 conn->mta_conn_mutex_lock_already = FALSE;
4866 conn->mta_conn_mutex_unlock_later = FALSE;
4867 if (roop_count == link_ok)
4868 {
4869 error_num = spider_db_store_result(this, roop_count, table);
4870 if (
4871 error_num &&
4872 error_num != HA_ERR_END_OF_FILE &&
4873 share->monitoring_kind[roop_count] &&
4874 need_mons[roop_count]
4875 ) {
4876 error_num = spider_ping_table_mon_from_table(
4877 trx,
4878 trx->thd,
4879 share,
4880 roop_count,
4881 (uint32) share->monitoring_sid[roop_count],
4882 share->table_name,
4883 share->table_name_length,
4884 conn_link_idx[roop_count],
4885 NULL,
4886 0,
4887 share->monitoring_kind[roop_count],
4888 share->monitoring_limit[roop_count],
4889 share->monitoring_flag[roop_count],
4890 TRUE
4891 );
4892 }
4893 result_link_idx = link_ok;
4894 } else {
4895 spider_db_discard_result(this, roop_count, conn);
4896 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
4897 pthread_mutex_unlock(&conn->mta_conn_mutex);
4898 }
4899 }
4900#ifdef HA_CAN_BULK_ACCESS
4901 }
4902#endif
4903#ifndef WITHOUT_SPIDER_BG_SEARCH
4904 }
4905#endif
4906 if (error_num)
4907 break;
4908 }
4909 if (error_num)
4910 {
4911 if (
4912 error_num != HA_ERR_END_OF_FILE &&
4913 check_error_mode(error_num)
4914 )
4915 DBUG_RETURN(error_num);
4916 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
4917 result_list.finish_flg = FALSE;
4918 result_list.record_num = 0;
4919 if (result_list.current)
4920 {
4921 DBUG_PRINT("info",
4922 ("spider result_list.current->finish_flg = FALSE"));
4923 result_list.current->finish_flg = FALSE;
4924 spider_db_free_one_result(&result_list,
4925 (SPIDER_RESULT *) result_list.current);
4926 if (result_list.current == result_list.first)
4927 result_list.current = NULL;
4928 else
4929 result_list.current = result_list.current->prev;
4930 }
4931 } else {
4932#ifdef HA_MRR_USE_DEFAULT_IMPL
4933 if (!range_info)
4934 DBUG_RETURN(0);
4935 if (!(error_num = spider_db_fetch(table->record[0], this, table)))
4936#else
4937 if (!buf || !(error_num = spider_db_fetch(buf, this, table)))
4938#endif
4939 {
4940#ifdef HA_MRR_USE_DEFAULT_IMPL
4941 *range_info = (char *) mrr_cur_range.ptr;
4942#else
4943 *found_range_p = multi_range_curr;
4944#endif
4945 DBUG_RETURN(check_ha_range_eof());
4946 }
4947 if (
4948 error_num != HA_ERR_END_OF_FILE &&
4949 check_error_mode(error_num)
4950 )
4951 DBUG_RETURN(error_num);
4952 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
4953 result_list.finish_flg = FALSE;
4954 result_list.record_num = 0;
4955 if (result_list.current)
4956 {
4957 DBUG_PRINT("info",
4958 ("spider result_list.current->finish_flg = FALSE"));
4959 result_list.current->finish_flg = FALSE;
4960 spider_db_free_one_result(&result_list,
4961 (SPIDER_RESULT *) result_list.current);
4962 if (result_list.current == result_list.first)
4963 result_list.current = NULL;
4964 else
4965 result_list.current = result_list.current->prev;
4966 }
4967 }
4968 set_where_to_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
4969 set_where_to_pos_sql(SPIDER_SQL_TYPE_HANDLER);
4970 }
4971#ifdef HA_MRR_USE_DEFAULT_IMPL
4972 DBUG_PRINT("info",("spider range_res2=%d", range_res));
4973#endif
4974 if (error_num)
4975 DBUG_RETURN(check_error_mode_eof(error_num));
4976 } else {
4977 bool tmp_high_priority = high_priority;
4978 bool have_multi_range;
4979#ifdef HA_MRR_USE_DEFAULT_IMPL
4980 const uchar *first_mrr_start_key;
4981 const uchar *first_mrr_end_key;
4982 uint first_mrr_start_key_length;
4983 uint first_mrr_end_key_length;
4984 have_second_range = FALSE;
4985#endif
4986 if (keyread)
4987 result_list.keyread = TRUE;
4988 else
4989 result_list.keyread = FALSE;
4990 mrr_with_cnt = TRUE;
4991 multi_range_cnt = 0;
4992 multi_range_hit_point = 0;
4993#ifdef HA_MRR_USE_DEFAULT_IMPL
4994 if (multi_range_keys)
4995 {
4996 DBUG_PRINT("info",("spider free multi_range_keys=%p", multi_range_keys));
4997 spider_free(spider_current_trx, multi_range_keys, MYF(0));
4998 }
4999#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
5000 if (!(multi_range_keys = (range_id_t *)
5001 spider_malloc(spider_current_trx, 1, sizeof(range_id_t) *
5002 (multi_range_num < result_list.multi_split_read ?
5003 multi_range_num : result_list.multi_split_read), MYF(MY_WME)))
5004 )
5005#else
5006 if (!(multi_range_keys = (char **)
5007 spider_malloc(spider_current_trx, 1, sizeof(char *) *
5008 (multi_range_num < result_list.multi_split_read ?
5009 multi_range_num : result_list.multi_split_read), MYF(MY_WME)))
5010 )
5011#endif
5012 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
5013 DBUG_PRINT("info",("spider alloc multi_range_keys=%p", multi_range_keys));
5014 if (!mrr_key_buff)
5015 {
5016 if (!(mrr_key_buff = new spider_string[2]))
5017 {
5018 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
5019 }
5020 for (roop_count = 0; roop_count < 2; roop_count++)
5021 mrr_key_buff[roop_count].init_calc_mem(235);
5022 }
5023#else
5024 multi_range_ranges = ranges;
5025#endif
5026 error_num = 0;
5027#ifdef HA_MRR_USE_DEFAULT_IMPL
5028 if ((range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range)))
5029 {
5030 DBUG_PRINT("info",("spider range_res3=%d", range_res));
5031 DBUG_PRINT("info",("spider result_list.finish_flg = TRUE"));
5032 result_list.finish_flg = TRUE;
5033 if (result_list.current)
5034 {
5035 DBUG_PRINT("info",("spider result_list.current->finish_flg = TRUE"));
5036 result_list.current->finish_flg = TRUE;
5037 }
5038 table->status = STATUS_NOT_FOUND;
5039 DBUG_RETURN(HA_ERR_END_OF_FILE);
5040 }
5041 DBUG_PRINT("info",("spider range_res4=%d", range_res));
5042 mrr_key_buff[0].length(0);
5043 first_mrr_start_key = mrr_cur_range.start_key.key;
5044 first_mrr_start_key_length = mrr_cur_range.start_key.length;
5045 if (first_mrr_start_key_length)
5046 {
5047 if (mrr_key_buff[0].reserve(first_mrr_start_key_length))
5048 DBUG_RETURN(HA_ERR_END_OF_FILE);
5049 mrr_key_buff[0].q_append((const char *) first_mrr_start_key,
5050 first_mrr_start_key_length);
5051 mrr_cur_range.start_key.key = (const uchar *) mrr_key_buff[0].ptr();
5052 }
5053 mrr_key_buff[1].length(0);
5054 first_mrr_end_key = mrr_cur_range.end_key.key;
5055 first_mrr_end_key_length = mrr_cur_range.end_key.length;
5056 if (first_mrr_end_key_length)
5057 {
5058 if (mrr_key_buff[1].reserve(first_mrr_end_key_length))
5059 DBUG_RETURN(HA_ERR_END_OF_FILE);
5060 mrr_key_buff[1].q_append((const char *) first_mrr_end_key,
5061 first_mrr_end_key_length);
5062 mrr_cur_range.end_key.key = (const uchar *) mrr_key_buff[1].ptr();
5063 }
5064#else
5065 multi_range_curr = ranges;
5066 multi_range_end = ranges + range_count;
5067#endif
5068 result_list.tmp_table_join = FALSE;
5069 memset(result_list.tmp_table_join_first, 0, share->link_bitmap_size);
5070 do
5071 {
5072#ifdef HA_MRR_USE_DEFAULT_IMPL
5073 if ((range_res = mrr_funcs.next(mrr_iter, &mrr_second_range)))
5074#else
5075 if (multi_range_curr + 1 >= multi_range_end)
5076#endif
5077 {
5078#ifdef HA_MRR_USE_DEFAULT_IMPL
5079 have_second_range = FALSE;
5080#endif
5081 have_multi_range = FALSE;
5082 } else {
5083#ifdef HA_MRR_USE_DEFAULT_IMPL
5084 have_second_range = TRUE;
5085#endif
5086 have_multi_range = TRUE;
5087 }
5088#ifdef HA_MRR_USE_DEFAULT_IMPL
5089 DBUG_PRINT("info",("spider range_res5=%d", range_res));
5090#endif
5091 result_list.tmp_reuse_sql = FALSE;
5092 if (bka_mode &&
5093 have_multi_range &&
5094#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5095 !(sql_kinds & SPIDER_SQL_KIND_HS) &&
5096#endif
5097#ifdef HA_MRR_USE_DEFAULT_IMPL
5098 SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE)
5099#else
5100 SPIDER_TEST(multi_range_curr->range_flag & EQ_RANGE)
5101#endif
5102 ) {
5103 if (
5104 result_list.tmp_table_join &&
5105#ifdef HA_MRR_USE_DEFAULT_IMPL
5106 result_list.tmp_table_join_key_part_map ==
5107 mrr_cur_range.start_key.keypart_map
5108#else
5109 result_list.tmp_table_join_key_part_map ==
5110 multi_range_curr->start_key.keypart_map
5111#endif
5112 ) {
5113 /* reuse tmp_sql */
5114 result_list.tmp_reuse_sql = TRUE;
5115 } else {
5116 /* create tmp_sql */
5117 result_list.tmp_table_join = TRUE;
5118#ifdef HA_MRR_USE_DEFAULT_IMPL
5119 result_list.tmp_table_join_key_part_map =
5120 mrr_cur_range.start_key.keypart_map;
5121#else
5122 result_list.tmp_table_join_key_part_map =
5123 multi_range_curr->start_key.keypart_map;
5124#endif
5125 if ((error_num = reset_sql_sql(
5126 SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL)))
5127 DBUG_RETURN(error_num);
5128 if ((sql_kinds & SPIDER_SQL_KIND_SQL))
5129 {
5130 for (roop_count = 0; roop_count < (int) share->link_count;
5131 roop_count++)
5132 {
5133 result_list.sql_kind_backup[roop_count] = sql_kind[roop_count];
5134 sql_kind[roop_count] = SPIDER_SQL_KIND_SQL;
5135 }
5136 result_list.sql_kinds_backup = sql_kinds;
5137 sql_kinds = SPIDER_SQL_KIND_SQL;
5138 result_list.have_sql_kind_backup = TRUE;
5139 }
5140 }
5141 memset(result_list.tmp_table_join_first, 0xFF,
5142 share->link_bitmap_size);
5143 } else {
5144 result_list.tmp_table_join = FALSE;
5145 if (result_list.have_sql_kind_backup)
5146 {
5147 for (roop_count = 0; roop_count < (int) share->link_count;
5148 roop_count++)
5149 {
5150 sql_kind[roop_count] =
5151 result_list.sql_kind_backup[roop_count];
5152 }
5153 sql_kinds = result_list.sql_kinds_backup;
5154 result_list.have_sql_kind_backup = FALSE;
5155 }
5156 }
5157 result_list.tmp_table_join_break_after_get_next = FALSE;
5158
5159 if (result_list.tmp_table_join)
5160 {
5161 result_list.limit_num =
5162 result_list.internal_limit >= result_list.split_read ?
5163 result_list.split_read : result_list.internal_limit;
5164 if (bka_mode == 2)
5165 {
5166 if (!result_list.tmp_reuse_sql)
5167 {
5168 if ((error_num = append_union_table_and_sql_for_bka(
5169#ifdef HA_MRR_USE_DEFAULT_IMPL
5170 &mrr_cur_range.start_key
5171#else
5172 &multi_range_curr->start_key
5173#endif
5174 ))) {
5175 DBUG_RETURN(error_num);
5176 }
5177 } else {
5178 if ((error_num = reuse_union_table_and_sql_for_bka()))
5179 {
5180 DBUG_RETURN(error_num);
5181 }
5182 }
5183 } else {
5184 if (!result_list.tmp_reuse_sql)
5185 {
5186 if ((error_num = append_tmp_table_and_sql_for_bka(
5187#ifdef HA_MRR_USE_DEFAULT_IMPL
5188 &mrr_cur_range.start_key
5189#else
5190 &multi_range_curr->start_key
5191#endif
5192 ))) {
5193 DBUG_RETURN(error_num);
5194 }
5195 } else {
5196 if ((error_num = reuse_tmp_table_and_sql_for_bka()))
5197 {
5198 DBUG_RETURN(error_num);
5199 }
5200 }
5201 }
5202
5203#ifdef HA_MRR_USE_DEFAULT_IMPL
5204 do
5205#else
5206 for (
5207 ;
5208 multi_range_curr < multi_range_end;
5209 multi_range_curr++
5210 )
5211#endif
5212 {
5213 if (
5214#ifdef HA_MRR_USE_DEFAULT_IMPL
5215 !SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) ||
5216 result_list.tmp_table_join_key_part_map !=
5217 mrr_cur_range.start_key.keypart_map
5218#else
5219 !SPIDER_TEST(multi_range_curr->range_flag & EQ_RANGE) ||
5220 result_list.tmp_table_join_key_part_map !=
5221 multi_range_curr->start_key.keypart_map
5222#endif
5223 ) {
5224 result_list.tmp_table_join_break_after_get_next = TRUE;
5225 break;
5226 }
5227
5228#ifdef HA_MRR_USE_DEFAULT_IMPL
5229#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
5230 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr;
5231#else
5232 multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr;
5233#endif
5234#endif
5235 if (bka_mode == 2)
5236 {
5237 if ((error_num = spider_db_append_select(this)))
5238 DBUG_RETURN(error_num);
5239 if (multi_range_cnt == 0)
5240 {
5241 if ((error_num = append_multi_range_cnt_with_name_sql_part(
5242 SPIDER_SQL_TYPE_SELECT_SQL, multi_range_cnt)))
5243 DBUG_RETURN(error_num);
5244 if ((error_num = append_key_column_values_with_name_sql_part(
5245#ifdef HA_MRR_USE_DEFAULT_IMPL
5246 &mrr_cur_range.start_key,
5247#else
5248 &multi_range_curr->start_key,
5249#endif
5250 SPIDER_SQL_TYPE_SELECT_SQL)))
5251 DBUG_RETURN(error_num);
5252 } else {
5253 if ((error_num = append_multi_range_cnt_sql_part(
5254 SPIDER_SQL_TYPE_SELECT_SQL, multi_range_cnt, TRUE)))
5255 DBUG_RETURN(error_num);
5256 if ((error_num = append_key_column_values_sql_part(
5257#ifdef HA_MRR_USE_DEFAULT_IMPL
5258 &mrr_cur_range.start_key,
5259#else
5260 &multi_range_curr->start_key,
5261#endif
5262 SPIDER_SQL_TYPE_SELECT_SQL)))
5263 DBUG_RETURN(error_num);
5264 }
5265 if ((error_num = append_union_table_connector_sql_part(
5266 SPIDER_SQL_TYPE_SELECT_SQL)))
5267 DBUG_RETURN(error_num);
5268 } else {
5269 if ((error_num = append_multi_range_cnt_sql_part(
5270 SPIDER_SQL_TYPE_TMP_SQL, multi_range_cnt, TRUE)))
5271 DBUG_RETURN(error_num);
5272 if ((error_num = append_key_column_values_sql_part(
5273#ifdef HA_MRR_USE_DEFAULT_IMPL
5274 &mrr_cur_range.start_key,
5275#else
5276 &multi_range_curr->start_key,
5277#endif
5278 SPIDER_SQL_TYPE_TMP_SQL)))
5279 DBUG_RETURN(error_num);
5280 if ((error_num =
5281 append_values_connector_sql_part(SPIDER_SQL_TYPE_TMP_SQL)))
5282 DBUG_RETURN(error_num);
5283 }
5284
5285 multi_range_cnt++;
5286 if (multi_range_cnt >= (uint) result_list.multi_split_read)
5287 break;
5288#ifdef HA_MRR_USE_DEFAULT_IMPL
5289 if (multi_range_cnt == 1)
5290 {
5291 if (have_multi_range)
5292 {
5293 memcpy(&mrr_cur_range, &mrr_second_range,
5294 sizeof(KEY_MULTI_RANGE));
5295 have_second_range = FALSE;
5296 range_res = 0;
5297 } else {
5298 range_res = 1;
5299 }
5300 } else {
5301 range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range);
5302 DBUG_PRINT("info",("spider range_res6=%d", range_res));
5303 }
5304#endif
5305 }
5306#ifdef HA_MRR_USE_DEFAULT_IMPL
5307 while (!range_res);
5308#endif
5309 if (bka_mode == 2)
5310 {
5311 if ((error_num = append_union_table_terminator_sql_part(
5312 SPIDER_SQL_TYPE_SELECT_SQL)))
5313 DBUG_RETURN(error_num);
5314 } else {
5315 if ((error_num =
5316 append_values_terminator_sql_part(SPIDER_SQL_TYPE_TMP_SQL)))
5317 DBUG_RETURN(error_num);
5318 }
5319 result_list.use_union = FALSE;
5320
5321 if ((error_num = append_limit_sql_part(
5322 result_list.internal_offset,
5323 result_list.limit_num,
5324 SPIDER_SQL_TYPE_SELECT_SQL)))
5325 {
5326 DBUG_RETURN(error_num);
5327 }
5328 if (
5329 (error_num = append_select_lock_sql_part(
5330 SPIDER_SQL_TYPE_SELECT_SQL))
5331 ) {
5332 DBUG_RETURN(error_num);
5333 }
5334 } else {
5335 result_list.limit_num = result_list.internal_limit;
5336 result_list.split_read = result_list.internal_limit;
5337 if (
5338 (error_num = init_union_table_name_pos_sql()) ||
5339 (error_num = append_union_all_start_sql_part(
5340 SPIDER_SQL_TYPE_SELECT_SQL))
5341 )
5342 DBUG_RETURN(error_num);
5343
5344#ifdef HA_MRR_USE_DEFAULT_IMPL
5345 do
5346#else
5347 for (
5348 ;
5349 multi_range_curr < multi_range_end;
5350 multi_range_curr++
5351 )
5352#endif
5353 {
5354#ifdef HA_MRR_USE_DEFAULT_IMPL
5355 DBUG_PRINT("info",("spider range_res7=%d", range_res));
5356#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
5357 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr;
5358#else
5359 multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr;
5360#endif
5361#endif
5362 if ((error_num = spider_db_append_select(this)))
5363 DBUG_RETURN(error_num);
5364 if ((error_num = append_multi_range_cnt_sql_part(
5365 SPIDER_SQL_TYPE_SELECT_SQL, multi_range_cnt, TRUE)))
5366 DBUG_RETURN(error_num);
5367 if (
5368 (error_num = spider_db_append_select_columns(this)) ||
5369 (error_num = set_union_table_name_pos_sql())
5370 )
5371 DBUG_RETURN(error_num);
5372 high_priority = FALSE;
5373 if (
5374 share->key_hint &&
5375 (error_num = append_hint_after_table_sql_part(
5376 SPIDER_SQL_TYPE_SELECT_SQL))
5377 )
5378 DBUG_RETURN(error_num);
5379 set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
5380 DBUG_PRINT("info",("spider internal_offset=%lld",
5381 result_list.internal_offset));
5382 DBUG_PRINT("info",("spider limit_num=%lld", result_list.limit_num));
5383 if (
5384#ifdef HA_MRR_USE_DEFAULT_IMPL
5385 (error_num = spider_db_append_key_where(
5386 &mrr_cur_range.start_key,
5387 SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) ?
5388 NULL : &mrr_cur_range.end_key, this))
5389#else
5390 (error_num = spider_db_append_key_where(
5391 &multi_range_curr->start_key,
5392 SPIDER_TEST(multi_range_curr->range_flag & EQ_RANGE) ?
5393 NULL : &multi_range_curr->end_key, this))
5394#endif
5395 )
5396 DBUG_RETURN(error_num);
5397 if (result_list.direct_order_limit)
5398 {
5399 if ((error_num =
5400 append_key_order_for_direct_order_limit_with_alias_sql_part(
5401 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
5402 DBUG_RETURN(error_num);
5403 } else {
5404 if ((error_num = append_key_order_with_alias_sql_part(
5405 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
5406 DBUG_RETURN(error_num);
5407 }
5408 if ((error_num = append_limit_sql_part(
5409 0,
5410 result_list.internal_offset + result_list.limit_num,
5411 SPIDER_SQL_TYPE_SELECT_SQL)))
5412 {
5413 DBUG_RETURN(error_num);
5414 }
5415 if (
5416 (error_num = append_select_lock_sql_part(
5417 SPIDER_SQL_TYPE_SELECT_SQL))
5418 )
5419 DBUG_RETURN(error_num);
5420 if ((error_num = append_union_all_sql_part(
5421 SPIDER_SQL_TYPE_SELECT_SQL)))
5422 DBUG_RETURN(error_num);
5423 multi_range_cnt++;
5424 if (multi_range_cnt >= (uint) result_list.multi_split_read)
5425 break;
5426#ifdef HA_MRR_USE_DEFAULT_IMPL
5427 if (multi_range_cnt == 1)
5428 {
5429 if (have_multi_range)
5430 {
5431 memcpy(&mrr_cur_range, &mrr_second_range,
5432 sizeof(KEY_MULTI_RANGE));
5433 have_second_range = FALSE;
5434 range_res = 0;
5435 } else {
5436 range_res = 1;
5437 }
5438 } else {
5439 range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range);
5440 DBUG_PRINT("info",("spider range_res8=%d", range_res));
5441 }
5442#endif
5443 }
5444#ifdef HA_MRR_USE_DEFAULT_IMPL
5445 while (!range_res);
5446#endif
5447 high_priority = tmp_high_priority;
5448 if ((error_num = append_union_all_end_sql_part(
5449 SPIDER_SQL_TYPE_SELECT_SQL)))
5450 DBUG_RETURN(error_num);
5451 result_list.use_union = TRUE;
5452
5453#ifdef HANDLER_HAS_DIRECT_AGGREGATE
5454 bool direct_aggregate_backup = result_list.direct_aggregate;
5455 result_list.direct_aggregate = FALSE;
5456#endif
5457 if (result_list.direct_order_limit)
5458 {
5459 if ((error_num =
5460 append_key_order_for_direct_order_limit_with_alias_sql_part(
5461 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
5462 DBUG_RETURN(error_num);
5463 } else {
5464 if ((error_num = append_key_order_with_alias_sql_part(
5465 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
5466 DBUG_RETURN(error_num);
5467 }
5468#ifdef HANDLER_HAS_DIRECT_AGGREGATE
5469 result_list.direct_aggregate = direct_aggregate_backup;
5470#endif
5471 if ((error_num = append_limit_sql_part(
5472 result_list.internal_offset,
5473 result_list.limit_num,
5474 SPIDER_SQL_TYPE_SELECT_SQL)))
5475 {
5476 DBUG_RETURN(error_num);
5477 }
5478 }
5479
5480 int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok;
5481 tmp_lock_mode = spider_conn_lock_mode(this);
5482 if (tmp_lock_mode)
5483 {
5484 /* "for update" or "lock in share mode" */
5485 link_ok = spider_conn_link_idx_next(share->link_statuses,
5486 conn_link_idx, -1, share->link_count,
5487 SPIDER_LINK_STATUS_OK);
5488 roop_start = spider_conn_link_idx_next(share->link_statuses,
5489 conn_link_idx, -1, share->link_count,
5490 SPIDER_LINK_STATUS_RECOVERY);
5491 roop_end = share->link_count;
5492 } else {
5493 link_ok = search_link_idx;
5494 roop_start = search_link_idx;
5495 roop_end = search_link_idx + 1;
5496 }
5497
5498 for (roop_count = roop_start; roop_count < roop_end;
5499 roop_count = spider_conn_link_idx_next(share->link_statuses,
5500 conn_link_idx, roop_count, share->link_count,
5501 SPIDER_LINK_STATUS_RECOVERY)
5502 ) {
5503#ifndef WITHOUT_SPIDER_BG_SEARCH
5504 if (result_list.bgs_phase > 0)
5505 {
5506 if ((error_num = spider_check_and_init_casual_read(trx->thd, this,
5507 roop_count)))
5508 DBUG_RETURN(error_num);
5509 if ((error_num = spider_bg_conn_search(this, roop_count, roop_start,
5510 TRUE, FALSE, (roop_count != link_ok))))
5511 {
5512 if (
5513 error_num != HA_ERR_END_OF_FILE &&
5514 share->monitoring_kind[roop_count] &&
5515 need_mons[roop_count]
5516 ) {
5517 error_num = spider_ping_table_mon_from_table(
5518 trx,
5519 trx->thd,
5520 share,
5521 roop_count,
5522 (uint32) share->monitoring_sid[roop_count],
5523 share->table_name,
5524 share->table_name_length,
5525 conn_link_idx[roop_count],
5526 NULL,
5527 0,
5528 share->monitoring_kind[roop_count],
5529 share->monitoring_limit[roop_count],
5530 share->monitoring_flag[roop_count],
5531 TRUE
5532 );
5533 }
5534 break;
5535 }
5536 } else {
5537#endif
5538 ulong sql_type;
5539#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5540 if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL)
5541 {
5542#endif
5543 conn = conns[roop_count];
5544 if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL)
5545 {
5546 sql_type = SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL;
5547 } else {
5548 sql_type = SPIDER_SQL_TYPE_HANDLER;
5549 }
5550#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5551 } else {
5552 if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ)
5553 conn = hs_r_conns[roop_count];
5554 else
5555 conn = hs_w_conns[roop_count];
5556 sql_type = SPIDER_SQL_TYPE_SELECT_HS;
5557 }
5558#endif
5559 spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id];
5560 if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
5561 {
5562 pthread_mutex_lock(&conn->mta_conn_mutex);
5563 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
5564 }
5565 if ((error_num =
5566 dbton_hdl->set_sql_for_exec(sql_type, roop_count)))
5567 {
5568 DBUG_RETURN(error_num);
5569 }
5570 if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
5571 {
5572 pthread_mutex_lock(&conn->mta_conn_mutex);
5573 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
5574 }
5575 sql_type &= ~SPIDER_SQL_TYPE_TMP_SQL;
5576 DBUG_PRINT("info",("spider sql_type=%lu", sql_type));
5577#ifdef HA_CAN_BULK_ACCESS
5578 if (is_bulk_access_clone)
5579 {
5580 connection_ids[roop_count] = conn->connection_id;
5581 spider_trx_add_bulk_access_conn(trx, conn);
5582 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
5583 pthread_mutex_unlock(&conn->mta_conn_mutex);
5584#ifdef HA_MRR_USE_DEFAULT_IMPL
5585 *range_info = multi_range_keys[multi_range_hit_point];
5586#else
5587 *found_range_p = &multi_range_ranges[multi_range_hit_point];
5588#endif
5589 DBUG_RETURN(0);
5590 } else {
5591#endif
5592 conn->need_mon = &need_mons[roop_count];
5593 conn->mta_conn_mutex_lock_already = TRUE;
5594 conn->mta_conn_mutex_unlock_later = TRUE;
5595 if ((error_num = spider_db_set_names(this, conn,
5596 roop_count)))
5597 {
5598 conn->mta_conn_mutex_lock_already = FALSE;
5599 conn->mta_conn_mutex_unlock_later = FALSE;
5600 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
5601 pthread_mutex_unlock(&conn->mta_conn_mutex);
5602 if (
5603 share->monitoring_kind[roop_count] &&
5604 need_mons[roop_count]
5605 ) {
5606 error_num = spider_ping_table_mon_from_table(
5607 trx,
5608 trx->thd,
5609 share,
5610 roop_count,
5611 (uint32) share->monitoring_sid[roop_count],
5612 share->table_name,
5613 share->table_name_length,
5614 conn_link_idx[roop_count],
5615 NULL,
5616 0,
5617 share->monitoring_kind[roop_count],
5618 share->monitoring_limit[roop_count],
5619 share->monitoring_flag[roop_count],
5620 TRUE
5621 );
5622 }
5623 break;
5624 }
5625 if (
5626 result_list.tmp_table_join && bka_mode != 2 &&
5627 spider_bit_is_set(result_list.tmp_table_join_first, roop_count)
5628 ) {
5629 spider_clear_bit(result_list.tmp_table_join_first, roop_count);
5630 spider_set_bit(result_list.tmp_table_created, roop_count);
5631 result_list.tmp_tables_created = TRUE;
5632 spider_conn_set_timeout_from_share(conn, roop_count,
5633 trx->thd, share);
5634 if (dbton_hdl->execute_sql(
5635 SPIDER_SQL_TYPE_TMP_SQL,
5636 conn,
5637 -1,
5638 &need_mons[roop_count])
5639 ) {
5640 conn->mta_conn_mutex_lock_already = FALSE;
5641 conn->mta_conn_mutex_unlock_later = FALSE;
5642 error_num = spider_db_errorno(conn);
5643 if (
5644 share->monitoring_kind[roop_count] &&
5645 need_mons[roop_count]
5646 ) {
5647 error_num = spider_ping_table_mon_from_table(
5648 trx,
5649 trx->thd,
5650 share,
5651 roop_count,
5652 (uint32) share->monitoring_sid[roop_count],
5653 share->table_name,
5654 share->table_name_length,
5655 conn_link_idx[roop_count],
5656 NULL,
5657 0,
5658 share->monitoring_kind[roop_count],
5659 share->monitoring_limit[roop_count],
5660 share->monitoring_flag[roop_count],
5661 TRUE
5662 );
5663 }
5664 break;
5665 }
5666 spider_db_discard_multiple_result(this, roop_count, conn);
5667 }
5668 spider_conn_set_timeout_from_share(conn, roop_count,
5669 trx->thd, share);
5670 if (dbton_hdl->execute_sql(
5671 sql_type,
5672 conn,
5673 result_list.quick_mode,
5674 &need_mons[roop_count])
5675 ) {
5676 conn->mta_conn_mutex_lock_already = FALSE;
5677 conn->mta_conn_mutex_unlock_later = FALSE;
5678 error_num = spider_db_errorno(conn);
5679 if (
5680 share->monitoring_kind[roop_count] &&
5681 need_mons[roop_count]
5682 ) {
5683 error_num = spider_ping_table_mon_from_table(
5684 trx,
5685 trx->thd,
5686 share,
5687 roop_count,
5688 (uint32) share->monitoring_sid[roop_count],
5689 share->table_name,
5690 share->table_name_length,
5691 conn_link_idx[roop_count],
5692 NULL,
5693 0,
5694 share->monitoring_kind[roop_count],
5695 share->monitoring_limit[roop_count],
5696 share->monitoring_flag[roop_count],
5697 TRUE
5698 );
5699 }
5700 break;
5701 }
5702 connection_ids[roop_count] = conn->connection_id;
5703 conn->mta_conn_mutex_lock_already = FALSE;
5704 conn->mta_conn_mutex_unlock_later = FALSE;
5705 if (roop_count == link_ok)
5706 {
5707 if ((error_num = spider_db_store_result(this, roop_count, table)))
5708 {
5709 if (
5710 error_num != HA_ERR_END_OF_FILE &&
5711 share->monitoring_kind[roop_count] &&
5712 need_mons[roop_count]
5713 ) {
5714 error_num = spider_ping_table_mon_from_table(
5715 trx,
5716 trx->thd,
5717 share,
5718 roop_count,
5719 (uint32) share->monitoring_sid[roop_count],
5720 share->table_name,
5721 share->table_name_length,
5722 conn_link_idx[roop_count],
5723 NULL,
5724 0,
5725 share->monitoring_kind[roop_count],
5726 share->monitoring_limit[roop_count],
5727 share->monitoring_flag[roop_count],
5728 TRUE
5729 );
5730 }
5731 break;
5732 }
5733 result_link_idx = link_ok;
5734 } else {
5735 spider_db_discard_result(this, roop_count, conn);
5736 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
5737 pthread_mutex_unlock(&conn->mta_conn_mutex);
5738 }
5739#ifdef HA_CAN_BULK_ACCESS
5740 }
5741#endif
5742#ifndef WITHOUT_SPIDER_BG_SEARCH
5743 }
5744#endif
5745 }
5746 if (error_num)
5747 {
5748 if (
5749 error_num != HA_ERR_END_OF_FILE &&
5750 !check_error_mode(error_num)
5751 )
5752 error_num = HA_ERR_END_OF_FILE;
5753 if (error_num == HA_ERR_END_OF_FILE)
5754 {
5755 if (multi_range_cnt >= (uint) result_list.multi_split_read)
5756 {
5757#ifdef HA_MRR_USE_DEFAULT_IMPL
5758 range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range);
5759 DBUG_PRINT("info",("spider range_res9=%d", range_res));
5760#else
5761 multi_range_curr++;
5762#endif
5763 }
5764 if (
5765#ifdef HA_MRR_USE_DEFAULT_IMPL
5766 range_res
5767#else
5768 multi_range_curr == multi_range_end
5769#endif
5770 ) {
5771 table->status = STATUS_NOT_FOUND;
5772 DBUG_RETURN(error_num);
5773 }
5774
5775 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
5776 result_list.finish_flg = FALSE;
5777 result_list.record_num = 0;
5778 if (result_list.current)
5779 {
5780 DBUG_PRINT("info",
5781 ("spider result_list.current->finish_flg = FALSE"));
5782 result_list.current->finish_flg = FALSE;
5783 spider_db_free_one_result(&result_list,
5784 (SPIDER_RESULT *) result_list.current);
5785 if (result_list.current == result_list.first)
5786 result_list.current = NULL;
5787 else
5788 result_list.current = result_list.current->prev;
5789 }
5790 error_num = 0;
5791 } else
5792 DBUG_RETURN(error_num);
5793 } else {
5794#ifdef HA_MRR_USE_DEFAULT_IMPL
5795 if (!range_info)
5796 DBUG_RETURN(0);
5797 if (!(error_num = spider_db_fetch(table->record[0], this, table)))
5798#else
5799 if (!buf || !(error_num = spider_db_fetch(buf, this, table)))
5800#endif
5801 {
5802#ifdef HA_MRR_USE_DEFAULT_IMPL
5803 *range_info = multi_range_keys[multi_range_hit_point];
5804#else
5805 *found_range_p = &multi_range_ranges[multi_range_hit_point];
5806#endif
5807 DBUG_RETURN(0);
5808 }
5809 if (
5810 error_num != HA_ERR_END_OF_FILE &&
5811 !check_error_mode(error_num)
5812 )
5813 error_num = HA_ERR_END_OF_FILE;
5814 if (error_num == HA_ERR_END_OF_FILE)
5815 {
5816 if (multi_range_cnt >= (uint) result_list.multi_split_read)
5817 {
5818#ifdef HA_MRR_USE_DEFAULT_IMPL
5819 range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range);
5820 DBUG_PRINT("info",("spider range_res10=%d", range_res));
5821#else
5822 multi_range_curr++;
5823#endif
5824 }
5825 if (
5826#ifdef HA_MRR_USE_DEFAULT_IMPL
5827 range_res
5828#else
5829 multi_range_curr == multi_range_end
5830#endif
5831 ) {
5832 table->status = STATUS_NOT_FOUND;
5833 DBUG_RETURN(error_num);
5834 }
5835
5836 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
5837 result_list.finish_flg = FALSE;
5838 result_list.record_num = 0;
5839 if (result_list.current)
5840 {
5841 DBUG_PRINT("info",
5842 ("spider result_list.current->finish_flg = FALSE"));
5843 result_list.current->finish_flg = FALSE;
5844 spider_db_free_one_result(&result_list,
5845 (SPIDER_RESULT *) result_list.current);
5846 if (result_list.current == result_list.first)
5847 result_list.current = NULL;
5848 else
5849 result_list.current = result_list.current->prev;
5850 }
5851 error_num = 0;
5852 } else
5853 DBUG_RETURN(error_num);
5854 }
5855 multi_range_cnt = 0;
5856 if ((error_num = reset_sql_sql(
5857 SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER)))
5858 DBUG_RETURN(error_num);
5859#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5860 if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS)))
5861 DBUG_RETURN(error_num);
5862#endif
5863#ifdef HA_MRR_USE_DEFAULT_IMPL
5864#else
5865 multi_range_ranges = multi_range_curr;
5866#endif
5867 } while (!error_num);
5868 }
5869 DBUG_RETURN(0);
5870}
5871
5872#ifdef HA_MRR_USE_DEFAULT_IMPL
5873int ha_spider::pre_multi_range_read_next(
5874 bool use_parallel
5875) {
5876 DBUG_ENTER("ha_spider::pre_multi_range_read_next");
5877 DBUG_PRINT("info",("spider this=%p", this));
5878 check_pre_call(use_parallel);
5879 if (use_pre_call)
5880 {
5881 store_error_num =
5882 multi_range_read_next_first(NULL);
5883 DBUG_RETURN(store_error_num);
5884 }
5885 DBUG_RETURN(0);
5886}
5887
5888#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
5889int ha_spider::multi_range_read_next(
5890 range_id_t *range_info
5891)
5892#else
5893int ha_spider::multi_range_read_next(
5894 char **range_info
5895)
5896#endif
5897{
5898 int error_num;
5899 DBUG_ENTER("ha_spider::multi_range_read_next");
5900 DBUG_PRINT("info",("spider this=%p", this));
5901 if (use_pre_call)
5902 {
5903 if (store_error_num)
5904 {
5905 if (store_error_num == HA_ERR_END_OF_FILE)
5906 table->status = STATUS_NOT_FOUND;
5907 DBUG_RETURN(store_error_num);
5908 }
5909 if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx)))
5910 DBUG_RETURN(error_num);
5911 use_pre_call = FALSE;
5912 mrr_have_range = TRUE;
5913 DBUG_RETURN(multi_range_read_next_next(range_info));
5914 }
5915 if (!mrr_have_range)
5916 {
5917 error_num = multi_range_read_next_first(range_info);
5918 mrr_have_range = TRUE;
5919 } else
5920 error_num = multi_range_read_next_next(range_info);
5921 DBUG_RETURN(error_num);
5922}
5923#else
5924int ha_spider::pre_read_multi_range_first(
5925 KEY_MULTI_RANGE **found_range_p,
5926 KEY_MULTI_RANGE *ranges,
5927 uint range_count,
5928 bool sorted,
5929 HANDLER_BUFFER *buffer,
5930 bool use_parallel
5931) {
5932 DBUG_ENTER("ha_spider::pre_read_multi_range_first");
5933 DBUG_PRINT("info",("spider this=%p", this));
5934 check_pre_call(use_parallel);
5935 if (use_pre_call)
5936 {
5937 store_error_num =
5938 read_multi_range_first_internal(NULL, found_range_p, ranges,
5939 range_count, sorted, buffer);
5940 DBUG_RETURN(store_error_num);
5941 }
5942 DBUG_RETURN(0);
5943}
5944
5945int ha_spider::read_multi_range_first(
5946 KEY_MULTI_RANGE **found_range_p,
5947 KEY_MULTI_RANGE *ranges,
5948 uint range_count,
5949 bool sorted,
5950 HANDLER_BUFFER *buffer
5951) {
5952 int error_num;
5953 DBUG_ENTER("ha_spider::read_multi_range_first");
5954 DBUG_PRINT("info",("spider this=%p", this));
5955 if (use_pre_call)
5956 {
5957 if (store_error_num)
5958 {
5959 if (store_error_num == HA_ERR_END_OF_FILE)
5960 table->status = STATUS_NOT_FOUND;
5961 DBUG_RETURN(store_error_num);
5962 }
5963 if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx)))
5964 DBUG_RETURN(error_num);
5965 use_pre_call = FALSE;
5966 DBUG_RETURN(read_multi_range_next(found_range_p));
5967 }
5968 DBUG_RETURN(read_multi_range_first_internal(table->record[0], found_range_p,
5969 ranges, range_count, sorted, buffer));
5970}
5971#endif
5972
5973#ifdef HA_MRR_USE_DEFAULT_IMPL
5974#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
5975int ha_spider::multi_range_read_next_next(
5976 range_id_t *range_info
5977)
5978#else
5979int ha_spider::multi_range_read_next_next(
5980 char **range_info
5981)
5982#endif
5983#else
5984int ha_spider::read_multi_range_next(
5985 KEY_MULTI_RANGE **found_range_p
5986)
5987#endif
5988{
5989 int error_num, roop_count;
5990 SPIDER_CONN *conn;
5991#ifdef HA_MRR_USE_DEFAULT_IMPL
5992 int range_res;
5993 backup_error_status();
5994 DBUG_ENTER("ha_spider::multi_range_read_next_next");
5995#else
5996 backup_error_status();
5997 DBUG_ENTER("ha_spider::read_multi_range_next");
5998#endif
5999 DBUG_PRINT("info",("spider this=%p", this));
6000 if (trx->thd->killed)
6001 {
6002 my_error(ER_QUERY_INTERRUPTED, MYF(0));
6003 DBUG_RETURN(ER_QUERY_INTERRUPTED);
6004 }
6005 if (is_clone)
6006 {
6007 DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p",
6008 pt_clone_source_handler));
6009 pt_clone_source_handler->pt_clone_last_searcher = this;
6010 }
6011 if (
6012#ifdef HA_MRR_USE_DEFAULT_IMPL
6013 multi_range_num == 1 ||
6014#endif
6015 result_list.multi_split_read <= 1 ||
6016 (sql_kinds & SPIDER_SQL_KIND_HANDLER)
6017 ) {
6018 if (!(error_num = spider_db_seek_next(table->record[0], this,
6019 search_link_idx, table)))
6020 {
6021#ifdef HA_MRR_USE_DEFAULT_IMPL
6022 *range_info = (char *) mrr_cur_range.ptr;
6023#else
6024 *found_range_p = multi_range_curr;
6025#endif
6026 DBUG_RETURN(0);
6027 }
6028
6029#ifdef HA_MRR_USE_DEFAULT_IMPL
6030 range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range);
6031 DBUG_PRINT("info",("spider range_res1=%d", range_res));
6032#else
6033 multi_range_curr++;
6034#endif
6035 if (
6036 error_num != HA_ERR_END_OF_FILE &&
6037 !check_error_mode(error_num)
6038 )
6039 error_num = HA_ERR_END_OF_FILE;
6040 if (
6041 error_num != HA_ERR_END_OF_FILE ||
6042#ifdef HA_MRR_USE_DEFAULT_IMPL
6043 range_res
6044#else
6045 multi_range_curr == multi_range_end
6046#endif
6047 )
6048 DBUG_RETURN(error_num);
6049 spider_db_free_one_result_for_start_next(this);
6050 spider_first_split_read_param(this);
6051#ifndef WITHOUT_SPIDER_BG_SEARCH
6052 if ((error_num = spider_set_conn_bg_param(this)))
6053 DBUG_RETURN(error_num);
6054#endif
6055 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
6056 result_list.finish_flg = FALSE;
6057 if (result_list.current)
6058 {
6059 DBUG_PRINT("info",("spider result_list.current->finish_flg = FALSE"));
6060 result_list.current->finish_flg = FALSE;
6061 }
6062 result_list.record_num = 0;
6063#ifdef HA_MRR_USE_DEFAULT_IMPL
6064 do
6065#else
6066 for (
6067 ;
6068 multi_range_curr < multi_range_end;
6069 multi_range_curr++
6070 )
6071#endif
6072 {
6073#ifdef HA_MRR_USE_DEFAULT_IMPL
6074 DBUG_PRINT("info",("spider range_res2=%d", range_res));
6075#endif
6076 set_where_to_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
6077 set_where_to_pos_sql(SPIDER_SQL_TYPE_HANDLER);
6078 result_list.limit_num =
6079 result_list.internal_limit - result_list.record_num >=
6080 result_list.split_read ?
6081 result_list.split_read :
6082 result_list.internal_limit - result_list.record_num;
6083 if (
6084#ifdef HA_MRR_USE_DEFAULT_IMPL
6085 (error_num = spider_db_append_key_where(
6086 &mrr_cur_range.start_key,
6087 SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) ?
6088 NULL : &mrr_cur_range.end_key, this))
6089#else
6090 (error_num = spider_db_append_key_where(
6091 &multi_range_curr->start_key,
6092 SPIDER_TEST(multi_range_curr->range_flag & EQ_RANGE) ?
6093 NULL : &multi_range_curr->end_key, this))
6094#endif
6095 )
6096 DBUG_RETURN(error_num);
6097 if (sql_kinds & SPIDER_SQL_KIND_SQL)
6098 {
6099 if (result_list.direct_order_limit)
6100 {
6101 if ((error_num =
6102 append_key_order_for_direct_order_limit_with_alias_sql_part(
6103 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
6104 DBUG_RETURN(error_num);
6105 } else {
6106 if ((error_num = append_key_order_with_alias_sql_part(
6107 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
6108 DBUG_RETURN(error_num);
6109 }
6110 if ((error_num = append_limit_sql_part(
6111 result_list.internal_offset + result_list.record_num,
6112 result_list.limit_num,
6113 SPIDER_SQL_TYPE_SELECT_SQL)))
6114 {
6115 DBUG_RETURN(error_num);
6116 }
6117 if (
6118 (error_num = append_select_lock_sql_part(
6119 SPIDER_SQL_TYPE_SELECT_SQL))
6120 ) {
6121 DBUG_RETURN(error_num);
6122 }
6123 }
6124 if (sql_kinds & SPIDER_SQL_KIND_HANDLER)
6125 {
6126 if ((error_num = append_limit_sql_part(
6127 result_list.internal_offset + result_list.record_num,
6128 result_list.limit_num,
6129 SPIDER_SQL_TYPE_HANDLER)))
6130 {
6131 DBUG_RETURN(error_num);
6132 }
6133 }
6134
6135 int roop_start, roop_end, tmp_lock_mode, link_ok;
6136 tmp_lock_mode = spider_conn_lock_mode(this);
6137 if (tmp_lock_mode)
6138 {
6139 /* "for update" or "lock in share mode" */
6140 link_ok = spider_conn_link_idx_next(share->link_statuses,
6141 conn_link_idx, -1, share->link_count,
6142 SPIDER_LINK_STATUS_OK);
6143 roop_start = spider_conn_link_idx_next(share->link_statuses,
6144 conn_link_idx, -1, share->link_count,
6145 SPIDER_LINK_STATUS_RECOVERY);
6146 roop_end = share->link_count;
6147 } else {
6148 link_ok = search_link_idx;
6149 roop_start = search_link_idx;
6150 roop_end = search_link_idx + 1;
6151 }
6152 for (roop_count = roop_start; roop_count < roop_end;
6153 roop_count = spider_conn_link_idx_next(share->link_statuses,
6154 conn_link_idx, roop_count, share->link_count,
6155 SPIDER_LINK_STATUS_RECOVERY)
6156 ) {
6157#ifndef WITHOUT_SPIDER_BG_SEARCH
6158 if (result_list.bgs_phase > 0)
6159 {
6160 if ((error_num = spider_check_and_init_casual_read(trx->thd, this,
6161 roop_count)))
6162 DBUG_RETURN(error_num);
6163 error_num = spider_bg_conn_search(this, roop_count, roop_start,
6164 TRUE, FALSE, (roop_count != link_ok));
6165 if (
6166 error_num &&
6167 error_num != HA_ERR_END_OF_FILE &&
6168 share->monitoring_kind[roop_count] &&
6169 need_mons[roop_count]
6170 ) {
6171 error_num = spider_ping_table_mon_from_table(
6172 trx,
6173 trx->thd,
6174 share,
6175 roop_count,
6176 (uint32) share->monitoring_sid[roop_count],
6177 share->table_name,
6178 share->table_name_length,
6179 conn_link_idx[roop_count],
6180 NULL,
6181 0,
6182 share->monitoring_kind[roop_count],
6183 share->monitoring_limit[roop_count],
6184 share->monitoring_flag[roop_count],
6185 TRUE
6186 );
6187 }
6188 } else {
6189#endif
6190 ulong sql_type;
6191#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
6192 if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL)
6193 {
6194#endif
6195 conn = conns[roop_count];
6196 if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL)
6197 {
6198 sql_type = SPIDER_SQL_TYPE_SELECT_SQL;
6199 } else {
6200 sql_type = SPIDER_SQL_TYPE_HANDLER;
6201 }
6202#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
6203 } else {
6204 if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ)
6205 conn = hs_r_conns[roop_count];
6206 else
6207 conn = hs_w_conns[roop_count];
6208 sql_type = SPIDER_SQL_TYPE_SELECT_HS;
6209 }
6210#endif
6211 spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id];
6212 if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
6213 {
6214 pthread_mutex_lock(&conn->mta_conn_mutex);
6215 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
6216 }
6217 if ((error_num =
6218 dbton_hdl->set_sql_for_exec(sql_type, roop_count)))
6219 {
6220 DBUG_RETURN(error_num);
6221 }
6222 if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
6223 {
6224 pthread_mutex_lock(&conn->mta_conn_mutex);
6225 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
6226 }
6227 DBUG_PRINT("info",("spider sql_type=%lu", sql_type));
6228#ifdef HA_CAN_BULK_ACCESS
6229 if (is_bulk_access_clone)
6230 {
6231 connection_ids[roop_count] = conn->connection_id;
6232 spider_trx_add_bulk_access_conn(trx, conn);
6233 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
6234 pthread_mutex_unlock(&conn->mta_conn_mutex);
6235#ifdef HA_MRR_USE_DEFAULT_IMPL
6236 *range_info = multi_range_keys[multi_range_hit_point];
6237#else
6238 *found_range_p = &multi_range_ranges[multi_range_hit_point];
6239#endif
6240 DBUG_RETURN(0);
6241 } else {
6242#endif
6243 conn->need_mon = &need_mons[roop_count];
6244 conn->mta_conn_mutex_lock_already = TRUE;
6245 conn->mta_conn_mutex_unlock_later = TRUE;
6246 if ((error_num = spider_db_set_names(this, conn,
6247 roop_count)))
6248 {
6249 conn->mta_conn_mutex_lock_already = FALSE;
6250 conn->mta_conn_mutex_unlock_later = FALSE;
6251 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
6252 pthread_mutex_unlock(&conn->mta_conn_mutex);
6253 if (
6254 share->monitoring_kind[roop_count] &&
6255 need_mons[roop_count]
6256 ) {
6257 error_num = spider_ping_table_mon_from_table(
6258 trx,
6259 trx->thd,
6260 share,
6261 roop_count,
6262 (uint32) share->monitoring_sid[roop_count],
6263 share->table_name,
6264 share->table_name_length,
6265 conn_link_idx[roop_count],
6266 NULL,
6267 0,
6268 share->monitoring_kind[roop_count],
6269 share->monitoring_limit[roop_count],
6270 share->monitoring_flag[roop_count],
6271 TRUE
6272 );
6273 }
6274 }
6275 if (!error_num)
6276 {
6277 spider_conn_set_timeout_from_share(conn, roop_count,
6278 trx->thd, share);
6279 if (dbton_hdl->execute_sql(
6280 sql_type,
6281 conn,
6282 result_list.quick_mode,
6283 &need_mons[roop_count])
6284 ) {
6285 conn->mta_conn_mutex_lock_already = FALSE;
6286 conn->mta_conn_mutex_unlock_later = FALSE;
6287 error_num = spider_db_errorno(conn);
6288 if (
6289 share->monitoring_kind[roop_count] &&
6290 need_mons[roop_count]
6291 ) {
6292 error_num = spider_ping_table_mon_from_table(
6293 trx,
6294 trx->thd,
6295 share,
6296 roop_count,
6297 (uint32) share->monitoring_sid[roop_count],
6298 share->table_name,
6299 share->table_name_length,
6300 conn_link_idx[roop_count],
6301 NULL,
6302 0,
6303 share->monitoring_kind[roop_count],
6304 share->monitoring_limit[roop_count],
6305 share->monitoring_flag[roop_count],
6306 TRUE
6307 );
6308 }
6309 }
6310 }
6311 if (!error_num)
6312 {
6313 connection_ids[roop_count] = conn->connection_id;
6314 conn->mta_conn_mutex_lock_already = FALSE;
6315 conn->mta_conn_mutex_unlock_later = FALSE;
6316 if (roop_count == link_ok)
6317 {
6318 error_num = spider_db_store_result(this, roop_count, table);
6319 if (
6320 error_num &&
6321 error_num != HA_ERR_END_OF_FILE &&
6322 share->monitoring_kind[roop_count] &&
6323 need_mons[roop_count]
6324 ) {
6325 error_num = spider_ping_table_mon_from_table(
6326 trx,
6327 trx->thd,
6328 share,
6329 roop_count,
6330 (uint32) share->monitoring_sid[roop_count],
6331 share->table_name,
6332 share->table_name_length,
6333 conn_link_idx[roop_count],
6334 NULL,
6335 0,
6336 share->monitoring_kind[roop_count],
6337 share->monitoring_limit[roop_count],
6338 share->monitoring_flag[roop_count],
6339 TRUE
6340 );
6341 }
6342 result_link_idx = link_ok;
6343 } else {
6344 spider_db_discard_result(this, roop_count, conn);
6345 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
6346 pthread_mutex_unlock(&conn->mta_conn_mutex);
6347 }
6348 }
6349#ifdef HA_CAN_BULK_ACCESS
6350 }
6351#endif
6352#ifndef WITHOUT_SPIDER_BG_SEARCH
6353 }
6354#endif
6355 if (error_num)
6356 break;
6357 }
6358 if (error_num)
6359 {
6360 if (
6361 error_num != HA_ERR_END_OF_FILE &&
6362 !check_error_mode(error_num)
6363 )
6364 error_num = HA_ERR_END_OF_FILE;
6365 if (error_num == HA_ERR_END_OF_FILE)
6366 {
6367 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
6368 result_list.finish_flg = FALSE;
6369 result_list.record_num = 0;
6370 if (result_list.current)
6371 {
6372 DBUG_PRINT("info",
6373 ("spider result_list.current->finish_flg = FALSE"));
6374 result_list.current->finish_flg = FALSE;
6375 spider_db_free_one_result(&result_list,
6376 (SPIDER_RESULT *) result_list.current);
6377 result_list.current = result_list.current->prev;
6378 }
6379 } else
6380 DBUG_RETURN(error_num);
6381 } else {
6382 if (!(error_num = spider_db_fetch(table->record[0], this, table)))
6383 {
6384#ifdef HA_MRR_USE_DEFAULT_IMPL
6385 *range_info = (char *) mrr_cur_range.ptr;
6386#else
6387 *found_range_p = multi_range_curr;
6388#endif
6389 DBUG_RETURN(check_ha_range_eof());
6390 }
6391 if (
6392 error_num != HA_ERR_END_OF_FILE &&
6393 !check_error_mode(error_num)
6394 )
6395 error_num = HA_ERR_END_OF_FILE;
6396 if (error_num == HA_ERR_END_OF_FILE)
6397 {
6398 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
6399 result_list.finish_flg = FALSE;
6400 result_list.record_num = 0;
6401 if (result_list.current)
6402 {
6403 DBUG_PRINT("info",
6404 ("spider result_list.current->finish_flg = FALSE"));
6405 result_list.current->finish_flg = FALSE;
6406 spider_db_free_one_result(&result_list,
6407 (SPIDER_RESULT *) result_list.current);
6408 result_list.current = result_list.current->prev;
6409 }
6410 } else
6411 DBUG_RETURN(error_num);
6412 }
6413#ifdef HA_MRR_USE_DEFAULT_IMPL
6414 range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range);
6415 DBUG_PRINT("info",("spider range_res3=%d", range_res));
6416#endif
6417 }
6418#ifdef HA_MRR_USE_DEFAULT_IMPL
6419 while (!range_res);
6420#endif
6421 if (error_num)
6422 DBUG_RETURN(check_error_mode_eof(error_num));
6423 } else {
6424 if (!(error_num = spider_db_seek_next(table->record[0], this,
6425 search_link_idx, table)))
6426 {
6427#ifdef HA_MRR_USE_DEFAULT_IMPL
6428 *range_info = multi_range_keys[multi_range_hit_point];
6429#else
6430 *found_range_p = &multi_range_ranges[multi_range_hit_point];
6431#endif
6432 DBUG_RETURN(0);
6433 }
6434
6435#ifdef HA_MRR_USE_DEFAULT_IMPL
6436 const uchar *first_mrr_start_key;
6437 const uchar *first_mrr_end_key;
6438 uint first_mrr_start_key_length;
6439 uint first_mrr_end_key_length;
6440#endif
6441 if (!result_list.tmp_table_join_break_after_get_next)
6442 {
6443#ifdef HA_MRR_USE_DEFAULT_IMPL
6444 range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range);
6445 DBUG_PRINT("info",("spider range_res4=%d", range_res));
6446 if (!range_res)
6447 {
6448 mrr_key_buff[0].length(0);
6449 first_mrr_start_key = mrr_cur_range.start_key.key;
6450 first_mrr_start_key_length = mrr_cur_range.start_key.length;
6451 if (first_mrr_start_key_length)
6452 {
6453 if (mrr_key_buff[0].reserve(first_mrr_start_key_length))
6454 DBUG_RETURN(HA_ERR_END_OF_FILE);
6455 mrr_key_buff[0].q_append((const char *) first_mrr_start_key,
6456 first_mrr_start_key_length);
6457 mrr_cur_range.start_key.key = (const uchar *) mrr_key_buff[0].ptr();
6458 }
6459 mrr_key_buff[1].length(0);
6460 first_mrr_end_key = mrr_cur_range.end_key.key;
6461 first_mrr_end_key_length = mrr_cur_range.end_key.length;
6462 if (first_mrr_end_key_length)
6463 {
6464 if (mrr_key_buff[1].reserve(first_mrr_end_key_length))
6465 DBUG_RETURN(HA_ERR_END_OF_FILE);
6466 mrr_key_buff[1].q_append((const char *) first_mrr_end_key,
6467 first_mrr_end_key_length);
6468 mrr_cur_range.end_key.key = (const uchar *) mrr_key_buff[1].ptr();
6469 }
6470 }
6471#else
6472 if (multi_range_curr < multi_range_end)
6473 multi_range_curr++;
6474#endif
6475 } else {
6476 result_list.tmp_table_join_break_after_get_next = FALSE;
6477#ifdef HA_MRR_USE_DEFAULT_IMPL
6478 range_res = 0;
6479#endif
6480 }
6481
6482 if (
6483 error_num != HA_ERR_END_OF_FILE &&
6484 !check_error_mode(error_num)
6485 )
6486 error_num = HA_ERR_END_OF_FILE;
6487 if (
6488 error_num != HA_ERR_END_OF_FILE ||
6489#ifdef HA_MRR_USE_DEFAULT_IMPL
6490 range_res
6491#else
6492 multi_range_curr == multi_range_end
6493#endif
6494 )
6495 DBUG_RETURN(error_num);
6496 spider_db_free_one_result_for_start_next(this);
6497 spider_first_split_read_param(this);
6498#ifndef WITHOUT_SPIDER_BG_SEARCH
6499 if ((error_num = spider_set_conn_bg_param(this)))
6500 DBUG_RETURN(error_num);
6501#endif
6502 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
6503 result_list.finish_flg = FALSE;
6504 if (result_list.current)
6505 {
6506 DBUG_PRINT("info",("spider result_list.current->finish_flg = FALSE"));
6507 result_list.current->finish_flg = FALSE;
6508 }
6509 result_list.record_num = 0;
6510
6511 if ((error_num = reset_sql_sql(
6512 SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER)))
6513 DBUG_RETURN(error_num);
6514#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
6515 if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS)))
6516 DBUG_RETURN(error_num);
6517#endif
6518#ifdef HA_MRR_USE_DEFAULT_IMPL
6519#else
6520 multi_range_ranges = multi_range_curr;
6521#endif
6522
6523 bool tmp_high_priority = high_priority;
6524 bool have_multi_range;
6525 multi_range_cnt = 0;
6526 error_num = 0;
6527 do
6528 {
6529#ifdef HA_MRR_USE_DEFAULT_IMPL
6530 if (
6531 !have_second_range &&
6532 (range_res = mrr_funcs.next(mrr_iter, &mrr_second_range))
6533 )
6534#else
6535 if (multi_range_curr + 1 >= multi_range_end)
6536#endif
6537 {
6538#ifdef HA_MRR_USE_DEFAULT_IMPL
6539 have_second_range = FALSE;
6540#endif
6541 have_multi_range = FALSE;
6542 } else {
6543#ifdef HA_MRR_USE_DEFAULT_IMPL
6544 have_second_range = TRUE;
6545#endif
6546 have_multi_range = TRUE;
6547 }
6548#ifdef HA_MRR_USE_DEFAULT_IMPL
6549 DBUG_PRINT("info",("spider range_res5=%d", range_res));
6550#endif
6551 result_list.tmp_reuse_sql = FALSE;
6552 if (bka_mode &&
6553 have_multi_range &&
6554#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
6555 !(sql_kinds & SPIDER_SQL_KIND_HS) &&
6556#endif
6557#ifdef HA_MRR_USE_DEFAULT_IMPL
6558 SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE)
6559#else
6560 SPIDER_TEST(multi_range_curr->range_flag & EQ_RANGE)
6561#endif
6562 ) {
6563 if (
6564 result_list.tmp_table_join &&
6565#ifdef HA_MRR_USE_DEFAULT_IMPL
6566 result_list.tmp_table_join_key_part_map ==
6567 mrr_cur_range.start_key.keypart_map
6568#else
6569 result_list.tmp_table_join_key_part_map ==
6570 multi_range_curr->start_key.keypart_map
6571#endif
6572 ) {
6573 /* reuse tmp_sql */
6574 result_list.tmp_reuse_sql = TRUE;
6575 } else {
6576 /* create tmp_sql */
6577 result_list.tmp_table_join = TRUE;
6578#ifdef HA_MRR_USE_DEFAULT_IMPL
6579 result_list.tmp_table_join_key_part_map =
6580 mrr_cur_range.start_key.keypart_map;
6581#else
6582 result_list.tmp_table_join_key_part_map =
6583 multi_range_curr->start_key.keypart_map;
6584#endif
6585 if ((error_num = reset_sql_sql(
6586 SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL)))
6587 DBUG_RETURN(error_num);
6588 if ((sql_kinds & SPIDER_SQL_KIND_SQL))
6589 {
6590 for (roop_count = 0; roop_count < (int) share->link_count;
6591 roop_count++)
6592 {
6593 result_list.sql_kind_backup[roop_count] = sql_kind[roop_count];
6594 sql_kind[roop_count] = SPIDER_SQL_KIND_SQL;
6595 }
6596 result_list.sql_kinds_backup = sql_kinds;
6597 sql_kinds = SPIDER_SQL_KIND_SQL;
6598 result_list.have_sql_kind_backup = TRUE;
6599 }
6600 }
6601 memset(result_list.tmp_table_join_first, 0xFF,
6602 share->link_bitmap_size);
6603 } else {
6604 result_list.tmp_table_join = FALSE;
6605 if (result_list.have_sql_kind_backup)
6606 {
6607 for (roop_count = 0; roop_count < (int) share->link_count;
6608 roop_count++)
6609 {
6610 sql_kind[roop_count] =
6611 result_list.sql_kind_backup[roop_count];
6612 }
6613 sql_kinds = result_list.sql_kinds_backup;
6614 result_list.have_sql_kind_backup = FALSE;
6615 }
6616 }
6617
6618 if (result_list.tmp_table_join)
6619 {
6620 result_list.limit_num =
6621 result_list.internal_limit - result_list.record_num >=
6622 result_list.split_read ?
6623 result_list.split_read :
6624 result_list.internal_limit - result_list.record_num;
6625 if (bka_mode == 2)
6626 {
6627 if (!result_list.tmp_reuse_sql)
6628 {
6629 if ((error_num = append_union_table_and_sql_for_bka(
6630#ifdef HA_MRR_USE_DEFAULT_IMPL
6631 &mrr_cur_range.start_key
6632#else
6633 &multi_range_curr->start_key
6634#endif
6635 ))) {
6636 DBUG_RETURN(error_num);
6637 }
6638 } else {
6639 if ((error_num = reuse_union_table_and_sql_for_bka()))
6640 {
6641 DBUG_RETURN(error_num);
6642 }
6643 }
6644 } else {
6645 if (!result_list.tmp_reuse_sql)
6646 {
6647 if ((error_num = append_tmp_table_and_sql_for_bka(
6648#ifdef HA_MRR_USE_DEFAULT_IMPL
6649 &mrr_cur_range.start_key
6650#else
6651 &multi_range_curr->start_key
6652#endif
6653 ))) {
6654 DBUG_RETURN(error_num);
6655 }
6656 } else {
6657 if ((error_num = reuse_tmp_table_and_sql_for_bka()))
6658 {
6659 DBUG_RETURN(error_num);
6660 }
6661 }
6662 }
6663
6664#ifdef HA_MRR_USE_DEFAULT_IMPL
6665 do
6666#else
6667 for (
6668 ;
6669 multi_range_curr < multi_range_end;
6670 multi_range_curr++
6671 )
6672#endif
6673 {
6674 if (
6675#ifdef HA_MRR_USE_DEFAULT_IMPL
6676 !SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) ||
6677 result_list.tmp_table_join_key_part_map !=
6678 mrr_cur_range.start_key.keypart_map
6679#else
6680 !SPIDER_TEST(multi_range_curr->range_flag & EQ_RANGE) ||
6681 result_list.tmp_table_join_key_part_map !=
6682 multi_range_curr->start_key.keypart_map
6683#endif
6684 ) {
6685 result_list.tmp_table_join_break_after_get_next = TRUE;
6686 break;
6687 }
6688
6689#ifdef HA_MRR_USE_DEFAULT_IMPL
6690#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
6691 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr;
6692#else
6693 multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr;
6694#endif
6695#endif
6696 if (bka_mode == 2)
6697 {
6698 if ((error_num = spider_db_append_select(this)))
6699 DBUG_RETURN(error_num);
6700 if (multi_range_cnt == 0)
6701 {
6702 if ((error_num = append_multi_range_cnt_with_name_sql_part(
6703 SPIDER_SQL_TYPE_SELECT_SQL, multi_range_cnt)))
6704 DBUG_RETURN(error_num);
6705 if ((error_num = append_key_column_values_with_name_sql_part(
6706#ifdef HA_MRR_USE_DEFAULT_IMPL
6707 &mrr_cur_range.start_key,
6708#else
6709 &multi_range_curr->start_key,
6710#endif
6711 SPIDER_SQL_TYPE_SELECT_SQL)))
6712 DBUG_RETURN(error_num);
6713 } else {
6714 if ((error_num = append_multi_range_cnt_sql_part(
6715 SPIDER_SQL_TYPE_SELECT_SQL, multi_range_cnt, TRUE)))
6716 DBUG_RETURN(error_num);
6717 if ((error_num = append_key_column_values_sql_part(
6718#ifdef HA_MRR_USE_DEFAULT_IMPL
6719 &mrr_cur_range.start_key,
6720#else
6721 &multi_range_curr->start_key,
6722#endif
6723 SPIDER_SQL_TYPE_SELECT_SQL)))
6724 DBUG_RETURN(error_num);
6725 }
6726 if ((error_num = append_union_table_connector_sql_part(
6727 SPIDER_SQL_TYPE_SELECT_SQL)))
6728 DBUG_RETURN(error_num);
6729 } else {
6730 if ((error_num = append_multi_range_cnt_sql_part(
6731 SPIDER_SQL_TYPE_TMP_SQL, multi_range_cnt, TRUE)))
6732 DBUG_RETURN(error_num);
6733 if ((error_num = append_key_column_values_sql_part(
6734#ifdef HA_MRR_USE_DEFAULT_IMPL
6735 &mrr_cur_range.start_key,
6736#else
6737 &multi_range_curr->start_key,
6738#endif
6739 SPIDER_SQL_TYPE_TMP_SQL)))
6740 DBUG_RETURN(error_num);
6741
6742 if ((error_num =
6743 append_values_connector_sql_part(SPIDER_SQL_TYPE_TMP_SQL)))
6744 DBUG_RETURN(error_num);
6745 }
6746 multi_range_cnt++;
6747 if (multi_range_cnt >= (uint) result_list.multi_split_read)
6748 break;
6749#ifdef HA_MRR_USE_DEFAULT_IMPL
6750 if (multi_range_cnt == 1)
6751 {
6752 if (have_multi_range)
6753 {
6754 memcpy(&mrr_cur_range, &mrr_second_range,
6755 sizeof(KEY_MULTI_RANGE));
6756 have_second_range = FALSE;
6757 range_res = 0;
6758 } else {
6759 range_res = 1;
6760 }
6761 } else {
6762 range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range);
6763 DBUG_PRINT("info",("spider range_res6=%d", range_res));
6764 }
6765#endif
6766 }
6767#ifdef HA_MRR_USE_DEFAULT_IMPL
6768 while (!range_res);
6769#endif
6770 if (bka_mode == 2)
6771 {
6772 if ((error_num = append_union_table_terminator_sql_part(
6773 SPIDER_SQL_TYPE_SELECT_SQL)))
6774 DBUG_RETURN(error_num);
6775 } else {
6776 if ((error_num =
6777 append_values_terminator_sql_part(SPIDER_SQL_TYPE_TMP_SQL)))
6778 DBUG_RETURN(error_num);
6779 }
6780 result_list.use_union = FALSE;
6781
6782 if ((error_num = append_limit_sql_part(
6783 result_list.internal_offset,
6784 result_list.limit_num,
6785 SPIDER_SQL_TYPE_SELECT_SQL)))
6786 {
6787 DBUG_RETURN(error_num);
6788 }
6789 if (
6790 (error_num = append_select_lock_sql_part(
6791 SPIDER_SQL_TYPE_SELECT_SQL))
6792 ) {
6793 DBUG_RETURN(error_num);
6794 }
6795 } else {
6796 result_list.limit_num =
6797 result_list.internal_limit - result_list.record_num;
6798 if (
6799 (error_num = init_union_table_name_pos_sql()) ||
6800 (error_num =
6801 append_union_all_start_sql_part(SPIDER_SQL_TYPE_SELECT_SQL))
6802 )
6803 DBUG_RETURN(error_num);
6804#ifdef HA_MRR_USE_DEFAULT_IMPL
6805 do
6806#else
6807 for (
6808 ;
6809 multi_range_curr < multi_range_end;
6810 multi_range_curr++
6811 )
6812#endif
6813 {
6814#ifdef HA_MRR_USE_DEFAULT_IMPL
6815#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
6816 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr;
6817#else
6818 multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr;
6819#endif
6820#endif
6821 if ((error_num = spider_db_append_select(this)))
6822 DBUG_RETURN(error_num);
6823 if ((error_num = append_multi_range_cnt_sql_part(
6824 SPIDER_SQL_TYPE_SELECT_SQL, multi_range_cnt, TRUE)))
6825 DBUG_RETURN(error_num);
6826 if (
6827 (error_num = spider_db_append_select_columns(this)) ||
6828 (error_num = set_union_table_name_pos_sql())
6829 )
6830 DBUG_RETURN(error_num);
6831 high_priority = FALSE;
6832 if (
6833 share->key_hint &&
6834 (error_num = append_hint_after_table_sql_part(
6835 SPIDER_SQL_TYPE_SELECT_SQL))
6836 )
6837 DBUG_RETURN(error_num);
6838 set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
6839 if (
6840#ifdef HA_MRR_USE_DEFAULT_IMPL
6841 (error_num = spider_db_append_key_where(
6842 &mrr_cur_range.start_key,
6843 SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) ?
6844 NULL : &mrr_cur_range.end_key, this))
6845#else
6846 (error_num = spider_db_append_key_where(
6847 &multi_range_curr->start_key,
6848 SPIDER_TEST(multi_range_curr->range_flag & EQ_RANGE) ?
6849 NULL : &multi_range_curr->end_key, this))
6850#endif
6851 )
6852 DBUG_RETURN(error_num);
6853 if (result_list.direct_order_limit)
6854 {
6855 if ((error_num =
6856 append_key_order_for_direct_order_limit_with_alias_sql_part(
6857 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
6858 DBUG_RETURN(error_num);
6859 } else {
6860 if ((error_num = append_key_order_with_alias_sql_part(
6861 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
6862 DBUG_RETURN(error_num);
6863 }
6864 if ((error_num = append_limit_sql_part(
6865 0,
6866 result_list.internal_offset + result_list.limit_num,
6867 SPIDER_SQL_TYPE_SELECT_SQL)))
6868 {
6869 DBUG_RETURN(error_num);
6870 }
6871 if ((error_num = append_select_lock_sql_part(
6872 SPIDER_SQL_TYPE_SELECT_SQL)))
6873 DBUG_RETURN(error_num);
6874 if ((error_num =
6875 append_union_all_sql_part(SPIDER_SQL_TYPE_SELECT_SQL)))
6876 DBUG_RETURN(error_num);
6877 multi_range_cnt++;
6878 if (multi_range_cnt >= (uint) result_list.multi_split_read)
6879 break;
6880#ifdef HA_MRR_USE_DEFAULT_IMPL
6881 if (multi_range_cnt == 1)
6882 {
6883 if (have_multi_range)
6884 {
6885 memcpy(&mrr_cur_range, &mrr_second_range,
6886 sizeof(KEY_MULTI_RANGE));
6887 have_second_range = FALSE;
6888 range_res = 0;
6889 } else {
6890 range_res = 1;
6891 }
6892 } else {
6893 range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range);
6894 DBUG_PRINT("info",("spider range_res7=%d", range_res));
6895 }
6896#endif
6897 }
6898#ifdef HA_MRR_USE_DEFAULT_IMPL
6899 while (!range_res);
6900#endif
6901 high_priority = tmp_high_priority;
6902 if ((error_num =
6903 append_union_all_end_sql_part(SPIDER_SQL_TYPE_SELECT_SQL)))
6904 DBUG_RETURN(error_num);
6905 result_list.use_union = TRUE;
6906
6907#ifdef HANDLER_HAS_DIRECT_AGGREGATE
6908 bool direct_aggregate_backup = result_list.direct_aggregate;
6909 result_list.direct_aggregate = FALSE;
6910#endif
6911 if (result_list.direct_order_limit)
6912 {
6913 if ((error_num =
6914 append_key_order_for_direct_order_limit_with_alias_sql_part(
6915 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
6916 DBUG_RETURN(error_num);
6917 } else {
6918 if ((error_num = append_key_order_with_alias_sql_part(
6919 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
6920 DBUG_RETURN(error_num);
6921 }
6922#ifdef HANDLER_HAS_DIRECT_AGGREGATE
6923 result_list.direct_aggregate = direct_aggregate_backup;
6924#endif
6925 if ((error_num = append_limit_sql_part(
6926 result_list.internal_offset,
6927 result_list.limit_num,
6928 SPIDER_SQL_TYPE_SELECT_SQL)))
6929 {
6930 DBUG_RETURN(error_num);
6931 }
6932 }
6933
6934 int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok;
6935 tmp_lock_mode = spider_conn_lock_mode(this);
6936 if (tmp_lock_mode)
6937 {
6938 /* "for update" or "lock in share mode" */
6939 link_ok = spider_conn_link_idx_next(share->link_statuses,
6940 conn_link_idx, -1, share->link_count,
6941 SPIDER_LINK_STATUS_OK);
6942 roop_start = spider_conn_link_idx_next(share->link_statuses,
6943 conn_link_idx, -1, share->link_count,
6944 SPIDER_LINK_STATUS_RECOVERY);
6945 roop_end = share->link_count;
6946 } else {
6947 link_ok = search_link_idx;
6948 roop_start = search_link_idx;
6949 roop_end = search_link_idx + 1;
6950 }
6951 for (roop_count = roop_start; roop_count < roop_end;
6952 roop_count = spider_conn_link_idx_next(share->link_statuses,
6953 conn_link_idx, roop_count, share->link_count,
6954 SPIDER_LINK_STATUS_RECOVERY)
6955 ) {
6956#ifndef WITHOUT_SPIDER_BG_SEARCH
6957 if (result_list.bgs_phase > 0)
6958 {
6959 if ((error_num = spider_check_and_init_casual_read(trx->thd, this,
6960 roop_count)))
6961 DBUG_RETURN(error_num);
6962 if ((error_num = spider_bg_conn_search(this, roop_count, roop_start,
6963 TRUE, FALSE, (roop_count != link_ok))))
6964 {
6965 if (
6966 error_num != HA_ERR_END_OF_FILE &&
6967 share->monitoring_kind[roop_count] &&
6968 need_mons[roop_count]
6969 ) {
6970 error_num = spider_ping_table_mon_from_table(
6971 trx,
6972 trx->thd,
6973 share,
6974 roop_count,
6975 (uint32) share->monitoring_sid[roop_count],
6976 share->table_name,
6977 share->table_name_length,
6978 conn_link_idx[roop_count],
6979 NULL,
6980 0,
6981 share->monitoring_kind[roop_count],
6982 share->monitoring_limit[roop_count],
6983 share->monitoring_flag[roop_count],
6984 TRUE
6985 );
6986 }
6987 break;
6988 }
6989 } else {
6990#endif
6991 ulong sql_type;
6992#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
6993 if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL)
6994 {
6995#endif
6996 conn = conns[roop_count];
6997 if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL)
6998 {
6999 sql_type = SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL;
7000 } else {
7001 sql_type = SPIDER_SQL_TYPE_HANDLER;
7002 }
7003#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
7004 } else {
7005 if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ)
7006 conn = hs_r_conns[roop_count];
7007 else
7008 conn = hs_w_conns[roop_count];
7009 sql_type = SPIDER_SQL_TYPE_SELECT_HS;
7010 }
7011#endif
7012 spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id];
7013 if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
7014 {
7015 pthread_mutex_lock(&conn->mta_conn_mutex);
7016 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
7017 }
7018 if ((error_num =
7019 dbton_hdl->set_sql_for_exec(sql_type, roop_count)))
7020 {
7021 DBUG_RETURN(error_num);
7022 }
7023 if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
7024 {
7025 pthread_mutex_lock(&conn->mta_conn_mutex);
7026 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
7027 }
7028 sql_type &= ~SPIDER_SQL_TYPE_TMP_SQL;
7029 DBUG_PRINT("info",("spider sql_type=%lu", sql_type));
7030#ifdef HA_CAN_BULK_ACCESS
7031 if (is_bulk_access_clone)
7032 {
7033 connection_ids[roop_count] = conn->connection_id;
7034 spider_trx_add_bulk_access_conn(trx, conn);
7035 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
7036 pthread_mutex_unlock(&conn->mta_conn_mutex);
7037#ifdef HA_MRR_USE_DEFAULT_IMPL
7038 *range_info = multi_range_keys[multi_range_hit_point];
7039#else
7040 *found_range_p = &multi_range_ranges[multi_range_hit_point];
7041#endif
7042 DBUG_RETURN(0);
7043 } else {
7044#endif
7045 conn->need_mon = &need_mons[roop_count];
7046 conn->mta_conn_mutex_lock_already = TRUE;
7047 conn->mta_conn_mutex_unlock_later = TRUE;
7048 if ((error_num = spider_db_set_names(this, conn,
7049 roop_count)))
7050 {
7051 conn->mta_conn_mutex_lock_already = FALSE;
7052 conn->mta_conn_mutex_unlock_later = FALSE;
7053 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
7054 pthread_mutex_unlock(&conn->mta_conn_mutex);
7055 if (
7056 share->monitoring_kind[roop_count] &&
7057 need_mons[roop_count]
7058 ) {
7059 error_num = spider_ping_table_mon_from_table(
7060 trx,
7061 trx->thd,
7062 share,
7063 roop_count,
7064 (uint32) share->monitoring_sid[roop_count],
7065 share->table_name,
7066 share->table_name_length,
7067 conn_link_idx[roop_count],
7068 NULL,
7069 0,
7070 share->monitoring_kind[roop_count],
7071 share->monitoring_limit[roop_count],
7072 share->monitoring_flag[roop_count],
7073 TRUE
7074 );
7075 }
7076 break;
7077 }
7078 if (
7079 result_list.tmp_table_join && bka_mode != 2 &&
7080 spider_bit_is_set(result_list.tmp_table_join_first, roop_count)
7081 ) {
7082 spider_clear_bit(result_list.tmp_table_join_first, roop_count);
7083 spider_set_bit(result_list.tmp_table_created, roop_count);
7084 result_list.tmp_tables_created = TRUE;
7085 spider_conn_set_timeout_from_share(conn, roop_count,
7086 trx->thd, share);
7087 if (dbton_hdl->execute_sql(
7088 SPIDER_SQL_TYPE_TMP_SQL,
7089 conn,
7090 -1,
7091 &need_mons[roop_count])
7092 ) {
7093 conn->mta_conn_mutex_lock_already = FALSE;
7094 conn->mta_conn_mutex_unlock_later = FALSE;
7095 error_num = spider_db_errorno(conn);
7096 if (
7097 share->monitoring_kind[roop_count] &&
7098 need_mons[roop_count]
7099 ) {
7100 error_num = spider_ping_table_mon_from_table(
7101 trx,
7102 trx->thd,
7103 share,
7104 roop_count,
7105 (uint32) share->monitoring_sid[roop_count],
7106 share->table_name,
7107 share->table_name_length,
7108 conn_link_idx[roop_count],
7109 NULL,
7110 0,
7111 share->monitoring_kind[roop_count],
7112 share->monitoring_limit[roop_count],
7113 share->monitoring_flag[roop_count],
7114 TRUE
7115 );
7116 }
7117 break;
7118 }
7119 spider_db_discard_multiple_result(this, roop_count, conn);
7120 }
7121 spider_conn_set_timeout_from_share(conn, roop_count,
7122 trx->thd, share);
7123 if (dbton_hdl->execute_sql(
7124 sql_type,
7125 conn,
7126 result_list.quick_mode,
7127 &need_mons[roop_count])
7128 ) {
7129 conn->mta_conn_mutex_lock_already = FALSE;
7130 conn->mta_conn_mutex_unlock_later = FALSE;
7131 error_num = spider_db_errorno(conn);
7132 if (
7133 share->monitoring_kind[roop_count] &&
7134 need_mons[roop_count]
7135 ) {
7136 error_num = spider_ping_table_mon_from_table(
7137 trx,
7138 trx->thd,
7139 share,
7140 roop_count,
7141 (uint32) share->monitoring_sid[roop_count],
7142 share->table_name,
7143 share->table_name_length,
7144 conn_link_idx[roop_count],
7145 NULL,
7146 0,
7147 share->monitoring_kind[roop_count],
7148 share->monitoring_limit[roop_count],
7149 share->monitoring_flag[roop_count],
7150 TRUE
7151 );
7152 }
7153 break;
7154 }
7155 connection_ids[roop_count] = conn->connection_id;
7156 conn->mta_conn_mutex_lock_already = FALSE;
7157 conn->mta_conn_mutex_unlock_later = FALSE;
7158 if (roop_count == link_ok)
7159 {
7160 if ((error_num = spider_db_store_result(this, roop_count, table)))
7161 {
7162 if (
7163 error_num != HA_ERR_END_OF_FILE &&
7164 share->monitoring_kind[roop_count] &&
7165 need_mons[roop_count]
7166 ) {
7167 error_num = spider_ping_table_mon_from_table(
7168 trx,
7169 trx->thd,
7170 share,
7171 roop_count,
7172 (uint32) share->monitoring_sid[roop_count],
7173 share->table_name,
7174 share->table_name_length,
7175 conn_link_idx[roop_count],
7176 NULL,
7177 0,
7178 share->monitoring_kind[roop_count],
7179 share->monitoring_limit[roop_count],
7180 share->monitoring_flag[roop_count],
7181 TRUE
7182 );
7183 }
7184 break;
7185 }
7186 result_link_idx = link_ok;
7187 } else {
7188 spider_db_discard_result(this, roop_count, conn);
7189 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
7190 pthread_mutex_unlock(&conn->mta_conn_mutex);
7191 }
7192#ifdef HA_CAN_BULK_ACCESS
7193 }
7194#endif
7195#ifndef WITHOUT_SPIDER_BG_SEARCH
7196 }
7197#endif
7198 }
7199 if (error_num)
7200 {
7201 if (
7202 error_num != HA_ERR_END_OF_FILE &&
7203 !check_error_mode(error_num)
7204 )
7205 error_num = HA_ERR_END_OF_FILE;
7206 if (error_num == HA_ERR_END_OF_FILE)
7207 {
7208 if (multi_range_cnt >= (uint) result_list.multi_split_read)
7209 {
7210#ifdef HA_MRR_USE_DEFAULT_IMPL
7211 range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range);
7212 DBUG_PRINT("info",("spider range_res8=%d", range_res));
7213#else
7214 multi_range_curr++;
7215#endif
7216 }
7217 if (
7218#ifdef HA_MRR_USE_DEFAULT_IMPL
7219 range_res
7220#else
7221 multi_range_curr == multi_range_end
7222#endif
7223 ) {
7224 table->status = STATUS_NOT_FOUND;
7225 DBUG_RETURN(error_num);
7226 }
7227
7228 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
7229 result_list.finish_flg = FALSE;
7230 result_list.record_num = 0;
7231 if (result_list.current)
7232 {
7233 DBUG_PRINT("info",
7234 ("spider result_list.current->finish_flg = FALSE"));
7235 result_list.current->finish_flg = FALSE;
7236 spider_db_free_one_result(&result_list,
7237 (SPIDER_RESULT *) result_list.current);
7238 if (result_list.current == result_list.first)
7239 result_list.current = NULL;
7240 else
7241 result_list.current = result_list.current->prev;
7242 }
7243 error_num = 0;
7244 } else
7245 DBUG_RETURN(error_num);
7246 } else {
7247 if (!(error_num = spider_db_fetch(table->record[0], this, table)))
7248 {
7249#ifdef HA_MRR_USE_DEFAULT_IMPL
7250 *range_info = multi_range_keys[multi_range_hit_point];
7251#else
7252 *found_range_p = &multi_range_ranges[multi_range_hit_point];
7253#endif
7254 DBUG_RETURN(0);
7255 }
7256 if (
7257 error_num != HA_ERR_END_OF_FILE &&
7258 !check_error_mode(error_num)
7259 )
7260 error_num = HA_ERR_END_OF_FILE;
7261 if (error_num == HA_ERR_END_OF_FILE)
7262 {
7263 if (multi_range_cnt >= (uint) result_list.multi_split_read)
7264 {
7265#ifdef HA_MRR_USE_DEFAULT_IMPL
7266 range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range);
7267 DBUG_PRINT("info",("spider range_res9=%d", range_res));
7268#else
7269 multi_range_curr++;
7270#endif
7271 }
7272 if (
7273#ifdef HA_MRR_USE_DEFAULT_IMPL
7274 range_res
7275#else
7276 multi_range_curr == multi_range_end
7277#endif
7278 ) {
7279 table->status = STATUS_NOT_FOUND;
7280 DBUG_RETURN(error_num);
7281 }
7282
7283 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
7284 result_list.finish_flg = FALSE;
7285 result_list.record_num = 0;
7286 if (result_list.current)
7287 {
7288 DBUG_PRINT("info",
7289 ("spider result_list.current->finish_flg = FALSE"));
7290 result_list.current->finish_flg = FALSE;
7291 spider_db_free_one_result(&result_list,
7292 (SPIDER_RESULT *) result_list.current);
7293 if (result_list.current == result_list.first)
7294 result_list.current = NULL;
7295 else
7296 result_list.current = result_list.current->prev;
7297 }
7298 error_num = 0;
7299 } else
7300 DBUG_RETURN(error_num);
7301 }
7302 multi_range_cnt = 0;
7303 if ((error_num = reset_sql_sql(
7304 SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER)))
7305 DBUG_RETURN(error_num);
7306#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
7307 if (
7308 (error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS))
7309 )
7310 DBUG_RETURN(error_num);
7311#endif
7312#ifdef HA_MRR_USE_DEFAULT_IMPL
7313#else
7314 multi_range_ranges = multi_range_curr;
7315#endif
7316 } while (!error_num);
7317 }
7318 DBUG_RETURN(0);
7319}
7320
7321int ha_spider::rnd_init(
7322 bool scan
7323) {
7324 int error_num;
7325 DBUG_ENTER("ha_spider::rnd_init");
7326 DBUG_PRINT("info",("spider this=%p", this));
7327 DBUG_PRINT("info",("spider scan=%s", scan ? "TRUE" : "FALSE"));
7328 pushed_pos = NULL;
7329/*
7330 if (result_list.lock_type == F_WRLCK)
7331 check_and_start_bulk_update(SPD_BU_START_BY_INDEX_OR_RND_INIT);
7332*/
7333 rnd_scan_and_first = scan;
7334 if (
7335 scan &&
7336 sql_command != SQLCOM_ALTER_TABLE
7337 ) {
7338 spider_set_result_list_param(this);
7339 pk_update = FALSE;
7340 if (
7341 result_list.current &&
7342 !result_list.low_mem_read &&
7343 prev_index_rnd_init == SPD_RND
7344 ) {
7345 result_list.current = result_list.first;
7346 spider_db_set_pos_to_first_row(&result_list);
7347 rnd_scan_and_first = FALSE;
7348 } else {
7349 spider_db_free_one_result_for_start_next(this);
7350 if (
7351 result_list.current &&
7352 result_list.low_mem_read
7353 ) {
7354 int roop_start, roop_end, roop_count, tmp_lock_mode;
7355 tmp_lock_mode = spider_conn_lock_mode(this);
7356 if (tmp_lock_mode)
7357 {
7358 /* "for update" or "lock in share mode" */
7359 roop_start = spider_conn_link_idx_next(share->link_statuses,
7360 conn_link_idx, -1, share->link_count,
7361 SPIDER_LINK_STATUS_RECOVERY);
7362 roop_end = share->link_count;
7363 } else {
7364 roop_start = search_link_idx;
7365 roop_end = search_link_idx + 1;
7366 }
7367 for (roop_count = roop_start; roop_count < roop_end;
7368 roop_count = spider_conn_link_idx_next(share->link_statuses,
7369 conn_link_idx, roop_count, share->link_count,
7370 SPIDER_LINK_STATUS_RECOVERY)
7371 ) {
7372#ifndef WITHOUT_SPIDER_BG_SEARCH
7373 if (conns[roop_count] && result_list.bgs_working)
7374 spider_bg_conn_break(conns[roop_count], this);
7375#endif
7376 if (quick_targets[roop_count])
7377 {
7378 DBUG_ASSERT(quick_targets[roop_count] ==
7379 conns[roop_count]->quick_target);
7380 DBUG_PRINT("info", ("spider conn[%p]->quick_target=NULL",
7381 conns[roop_count]));
7382 conns[roop_count]->quick_target = NULL;
7383 quick_targets[roop_count] = NULL;
7384 }
7385 }
7386 result_list.record_num = 0;
7387 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
7388 result_list.finish_flg = FALSE;
7389 result_list.quick_phase = 0;
7390#ifndef WITHOUT_SPIDER_BG_SEARCH
7391 result_list.bgs_phase = 0;
7392#endif
7393 }
7394
7395 mrr_with_cnt = FALSE;
7396 use_spatial_index = FALSE;
7397
7398 if (
7399 update_request &&
7400 share->have_recovery_link &&
7401 result_list.lock_type == F_WRLCK &&
7402 (pk_update = spider_check_pk_update(table))
7403 ) {
7404 bitmap_set_all(table->read_set);
7405 if (is_clone)
7406 memset(searched_bitmap, 0xFF, no_bytes_in_map(table->read_set));
7407 }
7408
7409 set_select_column_mode();
7410 result_list.keyread = FALSE;
7411
7412 init_rnd_handler = FALSE;
7413 if ((error_num = reset_sql_sql(
7414 SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER)))
7415 DBUG_RETURN(error_num);
7416#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
7417 if (
7418 (error_num = reset_hs_sql(SPIDER_SQL_TYPE_SELECT_HS)) ||
7419 (error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS))
7420 )
7421 DBUG_RETURN(error_num);
7422#endif
7423 result_list.check_direct_order_limit = FALSE;
7424 }
7425 }
7426 prev_index_rnd_init = SPD_RND;
7427 DBUG_RETURN(0);
7428}
7429
7430#ifdef HA_CAN_BULK_ACCESS
7431int ha_spider::pre_rnd_init(
7432 bool scan
7433) {
7434 DBUG_ENTER("ha_spider::pre_rnd_init");
7435 DBUG_PRINT("info",("spider this=%p", this));
7436 DBUG_RETURN(bulk_access_link_current->spider->ha_rnd_init(scan));
7437}
7438#endif
7439
7440int ha_spider::rnd_end()
7441{
7442/*
7443 int error_num;
7444 backup_error_status();
7445*/
7446 DBUG_ENTER("ha_spider::rnd_end");
7447 DBUG_PRINT("info",("spider this=%p", this));
7448/*
7449#ifdef INFO_KIND_FORCE_LIMIT_BEGIN
7450 info_limit = 9223372036854775807LL;
7451#endif
7452 if (
7453 (error_num = check_and_end_bulk_update(
7454 SPD_BU_START_BY_INDEX_OR_RND_INIT)) ||
7455 (error_num = spider_trx_check_link_idx_failed(this))
7456 )
7457 DBUG_RETURN(check_error_mode(error_num));
7458*/
7459 DBUG_RETURN(0);
7460}
7461
7462#ifdef HA_CAN_BULK_ACCESS
7463int ha_spider::pre_rnd_end()
7464{
7465 DBUG_ENTER("ha_spider::pre_rnd_end");
7466 DBUG_PRINT("info",("spider this=%p", this));
7467 DBUG_RETURN(bulk_access_link_current->spider->ha_rnd_end());
7468}
7469#endif
7470
7471int ha_spider::rnd_next_internal(
7472 uchar *buf
7473) {
7474 int error_num;
7475 ha_spider *direct_limit_offset_spider =
7476 (ha_spider *) partition_handler_share->creator;
7477 backup_error_status();
7478 DBUG_ENTER("ha_spider::rnd_next_internal");
7479 DBUG_PRINT("info",("spider this=%p", this));
7480 if (trx->thd->killed)
7481 {
7482 my_error(ER_QUERY_INTERRUPTED, MYF(0));
7483 DBUG_RETURN(ER_QUERY_INTERRUPTED);
7484 }
7485 /* do not copy table data at alter table */
7486 if (sql_command == SQLCOM_ALTER_TABLE)
7487 DBUG_RETURN(HA_ERR_END_OF_FILE);
7488#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
7489 do_direct_update = FALSE;
7490#endif
7491
7492 if (rnd_scan_and_first)
7493 {
7494#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
7495 if (sql_kinds & SPIDER_SQL_KIND_HS)
7496 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
7497#endif
7498#ifndef WITHOUT_SPIDER_BG_SEARCH
7499 if ((error_num = spider_set_conn_bg_param(this)))
7500 DBUG_RETURN(error_num);
7501#endif
7502 if ((error_num = rnd_handler_init()))
7503 DBUG_RETURN(check_error_mode_eof(error_num));
7504 check_direct_order_limit();
7505#ifdef WITH_PARTITION_STORAGE_ENGINE
7506 check_select_column(TRUE);
7507#endif
7508
7509 if (this->result_list.direct_limit_offset)
7510 {
7511 if (direct_limit_offset_spider->direct_select_limit == 0)
7512 { // mean has got all result
7513 DBUG_RETURN(check_error_mode_eof(HA_ERR_END_OF_FILE));
7514 }
7515 if (
7516 partition_handler_share->handlers &&
7517 direct_limit_offset_spider->direct_current_offset > 0
7518 ) {
7519 longlong table_count = this->records();
7520 DBUG_PRINT("info",("spider table_count=%lld", table_count));
7521 if (table_count <= direct_limit_offset_spider->direct_current_offset)
7522 {
7523 // skip this spider(partition)
7524 direct_limit_offset_spider->direct_current_offset -= table_count;
7525 DBUG_PRINT("info",("spider direct_current_offset=%lld",
7526 direct_limit_offset_spider->direct_current_offset));
7527 DBUG_RETURN(check_error_mode_eof(HA_ERR_END_OF_FILE));
7528 }
7529 }
7530
7531 // make the offset/limit statement
7532 DBUG_PRINT("info",("spider direct_current_offset=%lld",
7533 direct_limit_offset_spider->direct_current_offset));
7534 result_list.internal_offset = direct_limit_offset_spider->direct_current_offset;
7535 DBUG_PRINT("info",("spider direct_select_limit=%lld",
7536 direct_limit_offset_spider->direct_select_limit));
7537 result_list.internal_limit = direct_limit_offset_spider->direct_select_limit;
7538 result_list.split_read = direct_limit_offset_spider->direct_select_limit;
7539
7540 // start with this spider(partition)
7541 direct_limit_offset_spider->direct_current_offset = 0;
7542 }
7543
7544 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
7545 result_list.finish_flg = FALSE;
7546 result_list.record_num = 0;
7547 if (
7548 (error_num = spider_db_append_select(this)) ||
7549 (error_num = spider_db_append_select_columns(this))
7550 )
7551 DBUG_RETURN(error_num);
7552 set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
7553
7554 /* append condition pushdown */
7555 if (spider_db_append_condition(this, NULL, 0, FALSE))
7556 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
7557
7558 set_order_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
7559 if (result_list.direct_order_limit)
7560 {
7561 if ((error_num =
7562 append_key_order_for_direct_order_limit_with_alias_sql_part(
7563 NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
7564 DBUG_RETURN(error_num);
7565 }
7566#ifdef HANDLER_HAS_DIRECT_AGGREGATE
7567 else if (result_list.direct_aggregate)
7568 {
7569 if ((error_num =
7570 append_group_by_sql_part(NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
7571 DBUG_RETURN(error_num);
7572 }
7573#endif
7574 result_list.desc_flg = FALSE;
7575 result_list.sorted = FALSE;
7576 result_list.key_info = NULL;
7577 result_list.limit_num =
7578 result_list.internal_limit >= result_list.split_read ?
7579 result_list.split_read : result_list.internal_limit;
7580 if (sql_kinds & SPIDER_SQL_KIND_SQL)
7581 {
7582 if ((error_num = append_limit_sql_part(
7583 result_list.internal_offset,
7584 result_list.limit_num,
7585 SPIDER_SQL_TYPE_SELECT_SQL)))
7586 {
7587 DBUG_RETURN(error_num);
7588 }
7589 if (
7590 (error_num = append_select_lock_sql_part(
7591 SPIDER_SQL_TYPE_SELECT_SQL))
7592 ) {
7593 DBUG_RETURN(error_num);
7594 }
7595 }
7596 if (sql_kinds & SPIDER_SQL_KIND_HANDLER)
7597 {
7598 if ((error_num = append_limit_sql_part(
7599 result_list.internal_offset,
7600 result_list.limit_num,
7601 SPIDER_SQL_TYPE_HANDLER)))
7602 {
7603 DBUG_RETURN(error_num);
7604 }
7605 }
7606
7607 int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok;
7608 tmp_lock_mode = spider_conn_lock_mode(this);
7609 if (tmp_lock_mode)
7610 {
7611 /* "for update" or "lock in share mode" */
7612 link_ok = spider_conn_link_idx_next(share->link_statuses,
7613 conn_link_idx, -1, share->link_count,
7614 SPIDER_LINK_STATUS_OK);
7615 roop_start = spider_conn_link_idx_next(share->link_statuses,
7616 conn_link_idx, -1, share->link_count,
7617 SPIDER_LINK_STATUS_RECOVERY);
7618 roop_end = share->link_count;
7619 } else {
7620 link_ok = search_link_idx;
7621 roop_start = search_link_idx;
7622 roop_end = search_link_idx + 1;
7623 }
7624 for (roop_count = roop_start; roop_count < roop_end;
7625 roop_count = spider_conn_link_idx_next(share->link_statuses,
7626 conn_link_idx, roop_count, share->link_count,
7627 SPIDER_LINK_STATUS_RECOVERY)
7628 ) {
7629#ifndef WITHOUT_SPIDER_BG_SEARCH
7630 if (result_list.bgs_phase > 0)
7631 {
7632 if ((error_num = spider_check_and_init_casual_read(trx->thd, this,
7633 roop_count)))
7634 DBUG_RETURN(error_num);
7635 if ((error_num = spider_bg_conn_search(this, roop_count, roop_start,
7636 TRUE, FALSE, (roop_count != link_ok))))
7637 {
7638 if (
7639 error_num != HA_ERR_END_OF_FILE &&
7640 share->monitoring_kind[roop_count] &&
7641 need_mons[roop_count]
7642 ) {
7643 error_num = spider_ping_table_mon_from_table(
7644 trx,
7645 trx->thd,
7646 share,
7647 roop_count,
7648 (uint32) share->monitoring_sid[roop_count],
7649 share->table_name,
7650 share->table_name_length,
7651 conn_link_idx[roop_count],
7652 NULL,
7653 0,
7654 share->monitoring_kind[roop_count],
7655 share->monitoring_limit[roop_count],
7656 share->monitoring_flag[roop_count],
7657 TRUE
7658 );
7659 }
7660 DBUG_RETURN(check_error_mode_eof(error_num));
7661 }
7662 } else {
7663#endif
7664 SPIDER_CONN *conn = conns[roop_count];
7665 ulong sql_type;
7666 if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL)
7667 {
7668 sql_type = SPIDER_SQL_TYPE_SELECT_SQL;
7669 } else {
7670 sql_type = SPIDER_SQL_TYPE_HANDLER;
7671 }
7672 spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id];
7673 if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
7674 {
7675 pthread_mutex_lock(&conn->mta_conn_mutex);
7676 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
7677 }
7678 if ((error_num =
7679 dbton_hdl->set_sql_for_exec(sql_type, roop_count)))
7680 {
7681 DBUG_RETURN(error_num);
7682 }
7683 if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type))
7684 {
7685 pthread_mutex_lock(&conn->mta_conn_mutex);
7686 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
7687 }
7688 DBUG_PRINT("info",("spider sql_type=%lu", sql_type));
7689 conn->need_mon = &need_mons[roop_count];
7690 conn->mta_conn_mutex_lock_already = TRUE;
7691 conn->mta_conn_mutex_unlock_later = TRUE;
7692 if ((error_num = spider_db_set_names(this, conn,
7693 roop_count)))
7694 {
7695 conn->mta_conn_mutex_lock_already = FALSE;
7696 conn->mta_conn_mutex_unlock_later = FALSE;
7697 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
7698 pthread_mutex_unlock(&conn->mta_conn_mutex);
7699 if (
7700 share->monitoring_kind[roop_count] &&
7701 need_mons[roop_count]
7702 ) {
7703 error_num = spider_ping_table_mon_from_table(
7704 trx,
7705 trx->thd,
7706 share,
7707 roop_count,
7708 (uint32) share->monitoring_sid[roop_count],
7709 share->table_name,
7710 share->table_name_length,
7711 conn_link_idx[roop_count],
7712 NULL,
7713 0,
7714 share->monitoring_kind[roop_count],
7715 share->monitoring_limit[roop_count],
7716 share->monitoring_flag[roop_count],
7717 TRUE
7718 );
7719 }
7720 DBUG_RETURN(check_error_mode_eof(error_num));
7721 }
7722 spider_conn_set_timeout_from_share(conn, roop_count,
7723 trx->thd, share);
7724 if (dbton_hdl->execute_sql(
7725 sql_type,
7726 conn,
7727 result_list.quick_mode,
7728 &need_mons[roop_count])
7729 ) {
7730 conn->mta_conn_mutex_lock_already = FALSE;
7731 conn->mta_conn_mutex_unlock_later = FALSE;
7732 error_num = spider_db_errorno(conn);
7733 if (
7734 share->monitoring_kind[roop_count] &&
7735 need_mons[roop_count]
7736 ) {
7737 error_num = spider_ping_table_mon_from_table(
7738 trx,
7739 trx->thd,
7740 share,
7741 roop_count,
7742 (uint32) share->monitoring_sid[roop_count],
7743 share->table_name,
7744 share->table_name_length,
7745 conn_link_idx[roop_count],
7746 NULL,
7747 0,
7748 share->monitoring_kind[roop_count],
7749 share->monitoring_limit[roop_count],
7750 share->monitoring_flag[roop_count],
7751 TRUE
7752 );
7753 }
7754 DBUG_RETURN(check_error_mode_eof(error_num));
7755 }
7756 connection_ids[roop_count] = conn->connection_id;
7757 conn->mta_conn_mutex_lock_already = FALSE;
7758 conn->mta_conn_mutex_unlock_later = FALSE;
7759 if (roop_count == link_ok)
7760 {
7761 if ((error_num = spider_db_store_result(this, roop_count, table)))
7762 {
7763 if (
7764 error_num != HA_ERR_END_OF_FILE &&
7765 share->monitoring_kind[roop_count] &&
7766 need_mons[roop_count]
7767 ) {
7768 error_num = spider_ping_table_mon_from_table(
7769 trx,
7770 trx->thd,
7771 share,
7772 roop_count,
7773 (uint32) share->monitoring_sid[roop_count],
7774 share->table_name,
7775 share->table_name_length,
7776 conn_link_idx[roop_count],
7777 NULL,
7778 0,
7779 share->monitoring_kind[roop_count],
7780 share->monitoring_limit[roop_count],
7781 share->monitoring_flag[roop_count],
7782 TRUE
7783 );
7784 }
7785 DBUG_RETURN(check_error_mode_eof(error_num));
7786 }
7787 result_link_idx = link_ok;
7788 } else {
7789 spider_db_discard_result(this, roop_count, conn);
7790 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
7791 pthread_mutex_unlock(&conn->mta_conn_mutex);
7792 }
7793#ifndef WITHOUT_SPIDER_BG_SEARCH
7794 }
7795#endif
7796 }
7797 rnd_scan_and_first = FALSE;
7798
7799 if (this->result_list.direct_limit_offset)
7800 {
7801 if (buf && (error_num = spider_db_seek_next(buf, this, search_link_idx,
7802 table)))
7803 DBUG_RETURN(check_error_mode_eof(error_num));
7804 DBUG_RETURN(0);
7805 }
7806 }
7807
7808 if (
7809 result_list.direct_limit_offset &&
7810 direct_limit_offset_spider->direct_select_offset > 0
7811 ) {
7812 // limit-- for each got row
7813 direct_limit_offset_spider->direct_select_offset--;
7814 DBUG_RETURN(0);
7815 }
7816
7817 if (buf && (error_num = spider_db_seek_next(buf, this, search_link_idx,
7818 table)))
7819 DBUG_RETURN(check_error_mode_eof(error_num));
7820 DBUG_RETURN(0);
7821}
7822
7823int ha_spider::pre_rnd_next(
7824 bool use_parallel
7825) {
7826 DBUG_ENTER("ha_spider::pre_rnd_next");
7827 DBUG_PRINT("info",("spider this=%p", this));
7828 check_pre_call(use_parallel);
7829 if (use_pre_call)
7830 {
7831 store_error_num =
7832 rnd_next_internal(NULL);
7833 DBUG_RETURN(store_error_num);
7834 }
7835 DBUG_RETURN(0);
7836}
7837
7838int ha_spider::rnd_next(
7839 uchar *buf
7840) {
7841 int error_num;
7842 DBUG_ENTER("ha_spider::rnd_next");
7843 DBUG_PRINT("info",("spider this=%p", this));
7844 if (use_pre_call)
7845 {
7846 if (store_error_num)
7847 {
7848 if (store_error_num == HA_ERR_END_OF_FILE)
7849 table->status = STATUS_NOT_FOUND;
7850 DBUG_RETURN(store_error_num);
7851 }
7852 if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx)))
7853 DBUG_RETURN(error_num);
7854 use_pre_call = FALSE;
7855 }
7856 DBUG_RETURN(rnd_next_internal(buf));
7857}
7858
7859void ha_spider::position(
7860 const uchar *record
7861) {
7862 DBUG_ENTER("ha_spider::position");
7863 DBUG_PRINT("info",("spider this=%p", this));
7864 if (pushed_pos)
7865 {
7866 DBUG_PRINT("info",("spider pushed_pos=%p", pushed_pos));
7867 memcpy(ref, pushed_pos, ref_length);
7868 DBUG_VOID_RETURN;
7869 }
7870 if (pt_clone_last_searcher)
7871 {
7872 /* sercher is cloned handler */
7873 DBUG_PRINT("info",("spider cloned handler access"));
7874 pt_clone_last_searcher->position(record);
7875 memcpy(ref, pt_clone_last_searcher->ref, ref_length);
7876 } else {
7877 if (is_clone)
7878 {
7879 DBUG_PRINT("info",("spider set pt_clone_last_searcher (NULL) to %p",
7880 pt_clone_source_handler));
7881 pt_clone_source_handler->pt_clone_last_searcher = NULL;
7882 }
7883 memset(ref, '0', sizeof(SPIDER_POSITION));
7884 DBUG_PRINT("info",("spider self position"));
7885 DBUG_PRINT("info",
7886 ("spider current_row_num=%lld", result_list.current_row_num));
7887 if (!position_bitmap_init)
7888 {
7889 if (select_column_mode)
7890 {
7891 spider_db_handler *dbton_hdl =
7892 dbton_handler[result_list.current->dbton_id];
7893 dbton_hdl->copy_minimum_select_bitmap(position_bitmap);
7894 }
7895 position_bitmap_init = TRUE;
7896 }
7897 spider_db_create_position(this, (SPIDER_POSITION *) ref);
7898 }
7899 DBUG_VOID_RETURN;
7900}
7901
7902int ha_spider::rnd_pos(
7903 uchar *buf,
7904 uchar *pos
7905) {
7906 DBUG_ENTER("ha_spider::rnd_pos");
7907 DBUG_PRINT("info",("spider this=%p", this));
7908#ifndef DBUG_OFF
7909 for (uint roop_count = 0; roop_count < ((table->s->fields + 7) / 8);
7910 roop_count++)
7911 {
7912 DBUG_PRINT("info",("spider roop_count=%d", roop_count));
7913 DBUG_PRINT("info",("spider read_set=%d",
7914 ((uchar *) table->read_set->bitmap)[roop_count]));
7915 }
7916#endif
7917 if (trx->thd->killed)
7918 {
7919 my_error(ER_QUERY_INTERRUPTED, MYF(0));
7920 DBUG_RETURN(ER_QUERY_INTERRUPTED);
7921 }
7922 DBUG_PRINT("info",("spider pos=%p", pos));
7923 DBUG_PRINT("info",("spider buf=%p", buf));
7924 pushed_pos_buf = *((SPIDER_POSITION *) pos);
7925 pushed_pos = &pushed_pos_buf;
7926 DBUG_RETURN(spider_db_seek_tmp(buf, &pushed_pos_buf, this, table));
7927}
7928
7929int ha_spider::cmp_ref(
7930 const uchar *ref1,
7931 const uchar *ref2
7932) {
7933 int ret = 0;
7934 DBUG_ENTER("ha_spider::cmp_ref");
7935 DBUG_PRINT("info",("spider this=%p", this));
7936 DBUG_PRINT("info",("spider ref1=%p", ref1));
7937 DBUG_PRINT("info",("spider ref2=%p", ref2));
7938 result_list.in_cmp_ref = TRUE;
7939 if (table_share->primary_key < MAX_KEY)
7940 {
7941 uchar table_key[MAX_KEY_LENGTH];
7942 KEY *key_info = &table->key_info[table_share->primary_key];
7943 DBUG_PRINT("info",("spider cmp by primary key"));
7944 rnd_pos(table->record[0], (uchar *) ref2);
7945 key_copy(
7946 table_key,
7947 table->record[0],
7948 key_info,
7949 key_info->key_length);
7950 rnd_pos(table->record[0], (uchar *) ref1);
7951 ret = key_cmp(key_info->key_part, table_key, key_info->key_length);
7952 } else {
7953 Field **field;
7954 my_ptrdiff_t ptr_diff = PTR_BYTE_DIFF(table->record[1], table->record[0]);
7955 DBUG_PRINT("info",("spider cmp by all rows"));
7956 rnd_pos(table->record[1], (uchar *) ref2);
7957 rnd_pos(table->record[0], (uchar *) ref1);
7958 for (
7959 field = table->field;
7960 *field;
7961 field++
7962 ) {
7963 if ((ret = (*field)->cmp_binary_offset((uint) ptr_diff)))
7964 {
7965 DBUG_PRINT("info",("spider different at %s",
7966 (*field)->field_name.str));
7967 break;
7968 }
7969 }
7970 }
7971 result_list.in_cmp_ref = FALSE;
7972 DBUG_PRINT("info",("spider ret=%d", ret));
7973 DBUG_RETURN(ret);
7974}
7975
7976float spider_ft_find_relevance(
7977 FT_INFO *handler,
7978 uchar *record,
7979 uint length
7980) {
7981 DBUG_ENTER("spider_ft_find_relevance");
7982 st_spider_ft_info *info = (st_spider_ft_info*) handler;
7983 DBUG_PRINT("info",("spider info=%p", info));
7984 DBUG_PRINT("info",("spider score=%f", info->score));
7985 DBUG_RETURN(info->score);
7986}
7987
7988float spider_ft_get_relevance(
7989 FT_INFO *handler
7990) {
7991 DBUG_ENTER("spider_ft_get_relevance");
7992 st_spider_ft_info *info = (st_spider_ft_info*) handler;
7993 DBUG_PRINT("info",("spider info=%p", info));
7994 DBUG_PRINT("info",("spider score=%f", info->score));
7995 DBUG_RETURN(info->score);
7996}
7997
7998void spider_ft_close_search(
7999 FT_INFO *handler
8000) {
8001 DBUG_ENTER("spider_ft_close_search");
8002 DBUG_VOID_RETURN;
8003}
8004
8005_ft_vft spider_ft_vft = {
8006 NULL, // spider_ft_read_next
8007 spider_ft_find_relevance,
8008 spider_ft_close_search,
8009 spider_ft_get_relevance,
8010 NULL // spider_ft_reinit_search
8011};
8012
8013int ha_spider::ft_init()
8014{
8015 int roop_count, error_num;
8016 DBUG_ENTER("ha_spider::ft_init");
8017 DBUG_PRINT("info",("spider this=%p", this));
8018 if (store_error_num)
8019 DBUG_RETURN(store_error_num);
8020 if (active_index == MAX_KEY && inited == NONE)
8021 {
8022 st_spider_ft_info *ft_info = ft_first;
8023 ft_init_without_index_init = TRUE;
8024 ft_init_idx = MAX_KEY;
8025 while (TRUE)
8026 {
8027 if (ft_info->used_in_where)
8028 {
8029 ft_init_idx = ft_info->inx;
8030 if ((error_num = index_init(ft_init_idx, FALSE)))
8031 DBUG_RETURN(error_num);
8032 active_index = MAX_KEY;
8033 break;
8034 }
8035 if (ft_info == ft_current)
8036 break;
8037 ft_info = ft_info->next;
8038 }
8039 if (ft_init_idx == MAX_KEY)
8040 {
8041 if ((error_num = rnd_init(TRUE)))
8042 DBUG_RETURN(error_num);
8043 }
8044 } else {
8045 ft_init_idx = active_index;
8046 ft_init_without_index_init = FALSE;
8047 }
8048
8049 ft_init_and_first = TRUE;
8050
8051 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
8052 sql_kind[roop_count] = SPIDER_SQL_KIND_SQL;
8053 sql_kinds = SPIDER_SQL_KIND_SQL;
8054 DBUG_RETURN(0);
8055}
8056
8057void ha_spider::ft_end()
8058{
8059 DBUG_ENTER("ha_spider::ft_end");
8060 DBUG_PRINT("info",("spider this=%p", this));
8061 if (ft_init_without_index_init)
8062 {
8063 if (ft_init_idx == MAX_KEY)
8064 store_error_num = rnd_end();
8065 else
8066 store_error_num = index_end();
8067 }
8068 ft_init_without_index_init = FALSE;
8069 handler::ft_end();
8070 DBUG_VOID_RETURN;
8071}
8072
8073FT_INFO *ha_spider::ft_init_ext(
8074 uint flags,
8075 uint inx,
8076 String *key
8077) {
8078 st_spider_ft_info *tmp_ft_info;
8079 backup_error_status();
8080 DBUG_ENTER("ha_spider::ft_init_ext");
8081 DBUG_PRINT("info",("spider this=%p", this));
8082 DBUG_PRINT("info",("spider flags=%u", flags));
8083 DBUG_PRINT("info",("spider inx=%u", inx));
8084 DBUG_PRINT("info",("spider key=%s", key->c_ptr_safe()));
8085 if (inx == NO_SUCH_KEY)
8086 {
8087 my_error(ER_FT_MATCHING_KEY_NOT_FOUND, MYF(0));
8088 DBUG_RETURN(NULL);
8089 }
8090
8091 tmp_ft_info = ft_current;
8092 if (ft_current)
8093 ft_current = ft_current->next;
8094 else {
8095 ft_current = ft_first;
8096 set_ft_discard_bitmap();
8097 }
8098
8099 if (!ft_current)
8100 {
8101 if (!(ft_current = (st_spider_ft_info *)
8102 spider_malloc(spider_current_trx, 2, sizeof(st_spider_ft_info),
8103 MYF(MY_WME | MY_ZEROFILL))))
8104 {
8105 my_error(HA_ERR_OUT_OF_MEM, MYF(0));
8106 DBUG_RETURN(NULL);
8107 }
8108 if (tmp_ft_info)
8109 tmp_ft_info->next = ft_current;
8110 else
8111 ft_first = ft_current;
8112 }
8113
8114 ft_current->please = &spider_ft_vft;
8115 ft_current->file = this;
8116 ft_current->used_in_where = (flags & FT_SORTED);
8117 ft_current->target = ft_count;
8118 ft_current->flags = flags;
8119 ft_current->inx = inx;
8120 ft_current->key = key;
8121
8122 ft_count++;
8123 DBUG_RETURN((FT_INFO *) ft_current);
8124}
8125
8126int ha_spider::ft_read_internal(
8127 uchar *buf
8128) {
8129 int error_num;
8130 backup_error_status();
8131 DBUG_ENTER("ha_spider::ft_read_internal");
8132 DBUG_PRINT("info",("spider this=%p", this));
8133 if (trx->thd->killed)
8134 {
8135 my_error(ER_QUERY_INTERRUPTED, MYF(0));
8136 DBUG_RETURN(ER_QUERY_INTERRUPTED);
8137 }
8138 if (ft_init_and_first)
8139 {
8140 ft_init_and_first = FALSE;
8141 spider_db_free_one_result_for_start_next(this);
8142 check_direct_order_limit();
8143#ifndef WITHOUT_SPIDER_BG_SEARCH
8144 if ((error_num = spider_set_conn_bg_param(this)))
8145 DBUG_RETURN(error_num);
8146#endif
8147#ifdef WITH_PARTITION_STORAGE_ENGINE
8148 check_select_column(FALSE);
8149#endif
8150 DBUG_PRINT("info",("spider result_list.finish_flg = FALSE"));
8151 result_list.finish_flg = FALSE;
8152 result_list.record_num = 0;
8153 if (keyread)
8154 result_list.keyread = TRUE;
8155 else
8156 result_list.keyread = FALSE;
8157 if (
8158 (error_num = spider_db_append_select(this)) ||
8159 (error_num = spider_db_append_select_columns(this))
8160 )
8161 DBUG_RETURN(error_num);
8162 uint tmp_active_index = active_index;
8163 active_index = ft_init_idx;
8164 if (
8165 ft_init_idx < MAX_KEY &&
8166 share->key_hint &&
8167 (error_num =
8168 append_hint_after_table_sql_part(SPIDER_SQL_TYPE_SELECT_SQL))
8169 ) {
8170 active_index = tmp_active_index;
8171 DBUG_RETURN(error_num);
8172 }
8173 active_index = tmp_active_index;
8174 set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
8175 result_list.desc_flg = FALSE;
8176 result_list.sorted = TRUE;
8177 if (ft_init_idx == MAX_KEY)
8178 result_list.key_info = NULL;
8179 else
8180 result_list.key_info = &table->key_info[ft_init_idx];
8181 result_list.key_order = 0;
8182 result_list.limit_num =
8183 result_list.internal_limit >= result_list.split_read ?
8184 result_list.split_read : result_list.internal_limit;
8185 if ((error_num = spider_db_append_match_where(this)))
8186 DBUG_RETURN(error_num);
8187 if (result_list.direct_order_limit)
8188 {
8189 if ((error_num =
8190 append_key_order_for_direct_order_limit_with_alias_sql_part(NULL, 0,
8191 SPIDER_SQL_TYPE_SELECT_SQL)))
8192 DBUG_RETURN(error_num);
8193 }
8194#ifdef HANDLER_HAS_DIRECT_AGGREGATE
8195 else if (result_list.direct_aggregate)
8196 {
8197 if ((error_num =
8198 append_group_by_sql_part(NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)))
8199 DBUG_RETURN(error_num);
8200 }
8201#endif
8202 if (sql_kinds & SPIDER_SQL_KIND_SQL)
8203 {
8204 if ((error_num = append_limit_sql_part(
8205 result_list.internal_offset,
8206 result_list.limit_num,
8207 SPIDER_SQL_TYPE_SELECT_SQL)))
8208 {
8209 DBUG_RETURN(error_num);
8210 }
8211 if (
8212 (error_num = append_select_lock_sql_part(
8213 SPIDER_SQL_TYPE_SELECT_SQL))
8214 ) {
8215 DBUG_RETURN(error_num);
8216 }
8217 }
8218 if (sql_kinds & SPIDER_SQL_KIND_HANDLER)
8219 {
8220 if ((error_num = append_limit_sql_part(
8221 result_list.internal_offset,
8222 result_list.limit_num,
8223 SPIDER_SQL_TYPE_HANDLER)))
8224 {
8225 DBUG_RETURN(error_num);
8226 }
8227 }
8228
8229 int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok;
8230 tmp_lock_mode = spider_conn_lock_mode(this);
8231 if (tmp_lock_mode)
8232 {
8233 /* "for update" or "lock in share mode" */
8234 link_ok = spider_conn_link_idx_next(share->link_statuses,
8235 conn_link_idx, -1, share->link_count,
8236 SPIDER_LINK_STATUS_OK);
8237 roop_start = spider_conn_link_idx_next(share->link_statuses,
8238 conn_link_idx, -1, share->link_count,
8239 SPIDER_LINK_STATUS_RECOVERY);
8240 roop_end = share->link_count;
8241 } else {
8242 link_ok = search_link_idx;
8243 roop_start = search_link_idx;
8244 roop_end = search_link_idx + 1;
8245 }
8246 for (roop_count = roop_start; roop_count < roop_end;
8247 roop_count = spider_conn_link_idx_next(share->link_statuses,
8248 conn_link_idx, roop_count, share->link_count,
8249 SPIDER_LINK_STATUS_RECOVERY)
8250 ) {
8251#ifndef WITHOUT_SPIDER_BG_SEARCH
8252 if (result_list.bgs_phase > 0)
8253 {
8254 if ((error_num = spider_check_and_init_casual_read(trx->thd, this,
8255 roop_count)))
8256 DBUG_RETURN(error_num);
8257 if ((error_num = spider_bg_conn_search(this, roop_count, roop_start,
8258 TRUE, FALSE, (roop_count != link_ok))))
8259 {
8260 if (
8261 error_num != HA_ERR_END_OF_FILE &&
8262 share->monitoring_kind[roop_count] &&
8263 need_mons[roop_count]
8264 ) {
8265 error_num = spider_ping_table_mon_from_table(
8266 trx,
8267 trx->thd,
8268 share,
8269 roop_count,
8270 (uint32) share->monitoring_sid[roop_count],
8271 share->table_name,
8272 share->table_name_length,
8273 conn_link_idx[roop_count],
8274 NULL,
8275 0,
8276 share->monitoring_kind[roop_count],
8277 share->monitoring_limit[roop_count],
8278 share->monitoring_flag[roop_count],
8279 TRUE
8280 );
8281 }
8282 DBUG_RETURN(check_error_mode_eof(error_num));
8283 }
8284 } else {
8285#endif
8286 uint dbton_id = share->use_sql_dbton_ids[roop_count];
8287 spider_db_handler *dbton_hdl = dbton_handler[dbton_id];
8288 SPIDER_CONN *conn = conns[roop_count];
8289 if (dbton_hdl->need_lock_before_set_sql_for_exec(
8290 SPIDER_SQL_TYPE_SELECT_SQL))
8291 {
8292 pthread_mutex_lock(&conn->mta_conn_mutex);
8293 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
8294 }
8295 if ((error_num = dbton_hdl->set_sql_for_exec(
8296 SPIDER_SQL_TYPE_SELECT_SQL, roop_count)))
8297 {
8298 DBUG_RETURN(error_num);
8299 }
8300 if (!dbton_hdl->need_lock_before_set_sql_for_exec(
8301 SPIDER_SQL_TYPE_SELECT_SQL))
8302 {
8303 pthread_mutex_lock(&conn->mta_conn_mutex);
8304 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
8305 }
8306 conn->need_mon = &need_mons[roop_count];
8307 conn->mta_conn_mutex_lock_already = TRUE;
8308 conn->mta_conn_mutex_unlock_later = TRUE;
8309 if ((error_num = spider_db_set_names(this, conn, roop_count)))
8310 {
8311 conn->mta_conn_mutex_lock_already = FALSE;
8312 conn->mta_conn_mutex_unlock_later = FALSE;
8313 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
8314 pthread_mutex_unlock(&conn->mta_conn_mutex);
8315 if (
8316 share->monitoring_kind[roop_count] &&
8317 need_mons[roop_count]
8318 ) {
8319 error_num = spider_ping_table_mon_from_table(
8320 trx,
8321 trx->thd,
8322 share,
8323 roop_count,
8324 (uint32) share->monitoring_sid[roop_count],
8325 share->table_name,
8326 share->table_name_length,
8327 conn_link_idx[roop_count],
8328 NULL,
8329 0,
8330 share->monitoring_kind[roop_count],
8331 share->monitoring_limit[roop_count],
8332 share->monitoring_flag[roop_count],
8333 TRUE
8334 );
8335 }
8336 DBUG_RETURN(check_error_mode_eof(error_num));
8337 }
8338 spider_conn_set_timeout_from_share(conn, roop_count, trx->thd, share);
8339 if (dbton_hdl->execute_sql(
8340 SPIDER_SQL_TYPE_SELECT_SQL,
8341 conn,
8342 result_list.quick_mode,
8343 &need_mons[roop_count])
8344 ) {
8345 conn->mta_conn_mutex_lock_already = FALSE;
8346 conn->mta_conn_mutex_unlock_later = FALSE;
8347 error_num = spider_db_errorno(conn);
8348 if (
8349 share->monitoring_kind[roop_count] &&
8350 need_mons[roop_count]
8351 ) {
8352 error_num = spider_ping_table_mon_from_table(
8353 trx,
8354 trx->thd,
8355 share,
8356 roop_count,
8357 (uint32) share->monitoring_sid[roop_count],
8358 share->table_name,
8359 share->table_name_length,
8360 conn_link_idx[roop_count],
8361 NULL,
8362 0,
8363 share->monitoring_kind[roop_count],
8364 share->monitoring_limit[roop_count],
8365 share->monitoring_flag[roop_count],
8366 TRUE
8367 );
8368 }
8369 DBUG_RETURN(check_error_mode_eof(error_num));
8370 }
8371 connection_ids[roop_count] = conn->connection_id;
8372 conn->mta_conn_mutex_lock_already = FALSE;
8373 conn->mta_conn_mutex_unlock_later = FALSE;
8374 if (roop_count == link_ok)
8375 {
8376 if ((error_num = spider_db_store_result(this, roop_count, table)))
8377 {
8378 if (
8379 error_num != HA_ERR_END_OF_FILE &&
8380 share->monitoring_kind[roop_count] &&
8381 need_mons[roop_count]
8382 ) {
8383 error_num = spider_ping_table_mon_from_table(
8384 trx,
8385 trx->thd,
8386 share,
8387 roop_count,
8388 (uint32) share->monitoring_sid[roop_count],
8389 share->table_name,
8390 share->table_name_length,
8391 conn_link_idx[roop_count],
8392 NULL,
8393 0,
8394 share->monitoring_kind[roop_count],
8395 share->monitoring_limit[roop_count],
8396 share->monitoring_flag[roop_count],
8397 TRUE
8398 );
8399 }
8400 DBUG_RETURN(check_error_mode_eof(error_num));
8401 }
8402 result_link_idx = link_ok;
8403 } else {
8404 spider_db_discard_result(this, roop_count, conn);
8405 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
8406 pthread_mutex_unlock(&conn->mta_conn_mutex);
8407 }
8408#ifndef WITHOUT_SPIDER_BG_SEARCH
8409 }
8410#endif
8411 }
8412 }
8413
8414 if (is_clone)
8415 {
8416 DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p",
8417 pt_clone_source_handler));
8418 pt_clone_source_handler->pt_clone_last_searcher = this;
8419 }
8420 if (buf && (error_num = spider_db_seek_next(buf, this, search_link_idx,
8421 table)))
8422 DBUG_RETURN(check_error_mode_eof(error_num));
8423 DBUG_RETURN(0);
8424}
8425
8426int ha_spider::pre_ft_read(
8427 bool use_parallel
8428) {
8429 DBUG_ENTER("ha_spider::pre_ft_read");
8430 DBUG_PRINT("info",("spider this=%p", this));
8431 check_pre_call(use_parallel);
8432 if (use_pre_call)
8433 {
8434 store_error_num =
8435 ft_read_internal(NULL);
8436 DBUG_RETURN(store_error_num);
8437 }
8438 DBUG_RETURN(0);
8439}
8440
8441int ha_spider::ft_read(
8442 uchar *buf
8443) {
8444 int error_num;
8445 DBUG_ENTER("ha_spider::ft_read");
8446 DBUG_PRINT("info",("spider this=%p", this));
8447 if (use_pre_call)
8448 {
8449 if (store_error_num)
8450 {
8451 if (store_error_num == HA_ERR_END_OF_FILE)
8452 table->status = STATUS_NOT_FOUND;
8453 DBUG_RETURN(store_error_num);
8454 }
8455 if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx)))
8456 DBUG_RETURN(error_num);
8457 use_pre_call = FALSE;
8458 }
8459 DBUG_RETURN(ft_read_internal(buf));
8460}
8461
8462int ha_spider::info(
8463 uint flag
8464) {
8465 int error_num;
8466 THD *thd = ha_thd();
8467 double sts_interval = spider_param_sts_interval(thd, share->sts_interval);
8468 int sts_mode = spider_param_sts_mode(thd, share->sts_mode);
8469#ifdef WITH_PARTITION_STORAGE_ENGINE
8470 int sts_sync = spider_param_sts_sync(thd, share->sts_sync);
8471#endif
8472#ifndef WITHOUT_SPIDER_BG_SEARCH
8473 int sts_bg_mode = spider_param_sts_bg_mode(thd, share->sts_bg_mode);
8474#endif
8475 SPIDER_INIT_ERROR_TABLE *spider_init_error_table = NULL;
8476 set_error_mode();
8477 backup_error_status();
8478 DBUG_ENTER("ha_spider::info");
8479 DBUG_PRINT("info",("spider this=%p", this));
8480 DBUG_PRINT("info",("spider flag=%x", flag));
8481#ifdef HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT
8482 auto_inc_temporary = FALSE;
8483#endif
8484 sql_command = thd_sql_command(thd);
8485/*
8486 if (
8487 sql_command == SQLCOM_DROP_TABLE ||
8488 sql_command == SQLCOM_ALTER_TABLE ||
8489 sql_command == SQLCOM_SHOW_CREATE
8490 ) {
8491*/
8492 if (flag & HA_STATUS_AUTO)
8493 {
8494 if (share->lgtm_tblhnd_share->auto_increment_value)
8495 stats.auto_increment_value =
8496 share->lgtm_tblhnd_share->auto_increment_value;
8497 else {
8498 stats.auto_increment_value = 1;
8499#ifdef HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT
8500 auto_inc_temporary = TRUE;
8501#endif
8502 }
8503 }
8504 if (
8505 sql_command == SQLCOM_DROP_TABLE ||
8506 sql_command == SQLCOM_ALTER_TABLE
8507 )
8508 DBUG_RETURN(0);
8509/*
8510 }
8511*/
8512
8513 if (flag &
8514 (HA_STATUS_TIME | HA_STATUS_CONST | HA_STATUS_VARIABLE | HA_STATUS_AUTO))
8515 {
8516 time_t tmp_time = (time_t) time((time_t*) 0);
8517 DBUG_PRINT("info",
8518 ("spider difftime=%f", difftime(tmp_time, share->sts_get_time)));
8519 DBUG_PRINT("info",
8520 ("spider sts_interval=%f", sts_interval));
8521 int tmp_auto_increment_mode = 0;
8522 if (flag & HA_STATUS_AUTO)
8523 {
8524 tmp_auto_increment_mode = spider_param_auto_increment_mode(thd,
8525 share->auto_increment_mode);
8526#ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC
8527 info_auto_called = TRUE;
8528#endif
8529 }
8530 if (!share->sts_init)
8531 {
8532 pthread_mutex_lock(&share->sts_mutex);
8533 if (share->sts_init)
8534 pthread_mutex_unlock(&share->sts_mutex);
8535 else {
8536 if ((spider_init_error_table =
8537 spider_get_init_error_table(trx, share, FALSE)))
8538 {
8539 DBUG_PRINT("info",("spider diff=%f",
8540 difftime(tmp_time, spider_init_error_table->init_error_time)));
8541 if (difftime(tmp_time,
8542 spider_init_error_table->init_error_time) <
8543 spider_param_table_init_error_interval())
8544 {
8545 pthread_mutex_unlock(&share->sts_mutex);
8546 if (sql_command == SQLCOM_SHOW_CREATE)
8547 {
8548 if (thd->is_error())
8549 {
8550 DBUG_PRINT("info", ("spider clear_error"));
8551 thd->clear_error();
8552 }
8553 DBUG_RETURN(0);
8554 }
8555 if (spider_init_error_table->init_error_with_message)
8556 my_message(spider_init_error_table->init_error,
8557 spider_init_error_table->init_error_msg, MYF(0));
8558 DBUG_RETURN(check_error_mode(spider_init_error_table->init_error));
8559 }
8560 }
8561 pthread_mutex_unlock(&share->sts_mutex);
8562 sts_interval = 0;
8563#ifdef WITH_PARTITION_STORAGE_ENGINE
8564 if (tmp_auto_increment_mode == 1)
8565 sts_sync = 0;
8566#endif
8567 }
8568 }
8569 if (flag & HA_STATUS_AUTO)
8570 {
8571 if (
8572#ifdef WITH_PARTITION_STORAGE_ENGINE
8573 share->partition_share &&
8574#endif
8575 tmp_auto_increment_mode == 1 &&
8576 !share->lgtm_tblhnd_share->auto_increment_init
8577 ) {
8578 sts_interval = 0;
8579#ifdef WITH_PARTITION_STORAGE_ENGINE
8580 sts_sync = 0;
8581#endif
8582 }
8583 }
8584 if (difftime(tmp_time, share->sts_get_time) >= sts_interval)
8585 {
8586 if (
8587 sts_interval == 0 ||
8588 !pthread_mutex_trylock(&share->sts_mutex)
8589 ) {
8590#ifndef WITHOUT_SPIDER_BG_SEARCH
8591 if (sts_interval == 0 || sts_bg_mode == 0)
8592 {
8593#endif
8594 if (sts_interval == 0)
8595 pthread_mutex_lock(&share->sts_mutex);
8596 if (difftime(tmp_time, share->sts_get_time) >= sts_interval)
8597 {
8598 if ((error_num = spider_check_trx_and_get_conn(ha_thd(), this,
8599 FALSE)))
8600 {
8601 pthread_mutex_unlock(&share->sts_mutex);
8602 if (!share->sts_init)
8603 {
8604 if (
8605 spider_init_error_table ||
8606 (spider_init_error_table =
8607 spider_get_init_error_table(trx, share, TRUE))
8608 ) {
8609 spider_init_error_table->init_error = error_num;
8610 if ((spider_init_error_table->init_error_with_message =
8611 thd->is_error()))
8612 strmov(spider_init_error_table->init_error_msg,
8613 spider_stmt_da_message(thd));
8614 spider_init_error_table->init_error_time =
8615 (time_t) time((time_t*) 0);
8616 }
8617 share->init_error = TRUE;
8618 share->init = TRUE;
8619 }
8620 if (sql_command == SQLCOM_SHOW_CREATE)
8621 {
8622 if (thd->is_error())
8623 {
8624 DBUG_PRINT("info", ("spider clear_error"));
8625 thd->clear_error();
8626 }
8627 DBUG_RETURN(0);
8628 }
8629 DBUG_RETURN(check_error_mode(error_num));
8630 }
8631 if ((error_num = spider_get_sts(share, search_link_idx, tmp_time,
8632 this, sts_interval, sts_mode,
8633#ifdef WITH_PARTITION_STORAGE_ENGINE
8634 sts_sync,
8635#endif
8636 share->sts_init ? 2 : 1,
8637 flag | (share->sts_init ? 0 : HA_STATUS_AUTO)))
8638 ) {
8639 pthread_mutex_unlock(&share->sts_mutex);
8640 if (
8641 share->monitoring_kind[search_link_idx] &&
8642 need_mons[search_link_idx]
8643 ) {
8644 error_num = spider_ping_table_mon_from_table(
8645 trx,
8646 trx->thd,
8647 share,
8648 search_link_idx,
8649 (uint32) share->monitoring_sid[search_link_idx],
8650 share->table_name,
8651 share->table_name_length,
8652 conn_link_idx[search_link_idx],
8653 NULL,
8654 0,
8655 share->monitoring_kind[search_link_idx],
8656 share->monitoring_limit[search_link_idx],
8657 share->monitoring_flag[search_link_idx],
8658 TRUE
8659 );
8660 }
8661 if (!share->sts_init)
8662 {
8663 if (
8664 spider_init_error_table ||
8665 (spider_init_error_table =
8666 spider_get_init_error_table(trx, share, TRUE))
8667 ) {
8668 spider_init_error_table->init_error = error_num;
8669/*
8670 if (!thd->is_error())
8671 my_error(error_num, MYF(0), "");
8672*/
8673 if ((spider_init_error_table->init_error_with_message =
8674 thd->is_error()))
8675 strmov(spider_init_error_table->init_error_msg,
8676 spider_stmt_da_message(thd));
8677 spider_init_error_table->init_error_time =
8678 (time_t) time((time_t*) 0);
8679 }
8680 share->init_error = TRUE;
8681 share->init = TRUE;
8682 }
8683 if (sql_command == SQLCOM_SHOW_CREATE)
8684 {
8685 if (thd->is_error())
8686 {
8687 DBUG_PRINT("info", ("spider clear_error"));
8688 thd->clear_error();
8689 }
8690 DBUG_RETURN(0);
8691 }
8692 DBUG_RETURN(check_error_mode(error_num));
8693 }
8694 }
8695#ifndef WITHOUT_SPIDER_BG_SEARCH
8696 } else if (sts_bg_mode == 1) {
8697 /* background */
8698 if (!share->bg_sts_init || share->bg_sts_thd_wait)
8699 {
8700 share->bg_sts_thd_wait = FALSE;
8701 share->bg_sts_try_time = tmp_time;
8702 share->bg_sts_interval = sts_interval;
8703 share->bg_sts_mode = sts_mode;
8704#ifdef WITH_PARTITION_STORAGE_ENGINE
8705 share->bg_sts_sync = sts_sync;
8706#endif
8707 if (!share->bg_sts_init)
8708 {
8709 if ((error_num = spider_create_sts_thread(share)))
8710 {
8711 pthread_mutex_unlock(&share->sts_mutex);
8712 if (sql_command == SQLCOM_SHOW_CREATE)
8713 {
8714 if (thd->is_error())
8715 {
8716 DBUG_PRINT("info", ("spider clear_error"));
8717 thd->clear_error();
8718 }
8719 DBUG_RETURN(0);
8720 }
8721 DBUG_RETURN(error_num);
8722 }
8723 } else
8724 pthread_cond_signal(&share->bg_sts_cond);
8725 }
8726 } else {
8727 share->bg_sts_try_time = tmp_time;
8728 share->bg_sts_interval = sts_interval;
8729 share->bg_sts_mode = sts_mode;
8730#ifdef WITH_PARTITION_STORAGE_ENGINE
8731 share->bg_sts_sync = sts_sync;
8732#endif
8733 spider_table_add_share_to_sts_thread(share);
8734 }
8735#endif
8736 pthread_mutex_unlock(&share->sts_mutex);
8737 }
8738 }
8739 if (flag & HA_STATUS_CONST)
8740 {
8741 if ((error_num = check_crd()))
8742 {
8743 if (sql_command == SQLCOM_SHOW_CREATE)
8744 {
8745 if (thd->is_error())
8746 {
8747 DBUG_PRINT("info", ("spider clear_error"));
8748 thd->clear_error();
8749 }
8750 DBUG_RETURN(0);
8751 }
8752 DBUG_RETURN(error_num);
8753 }
8754 spider_db_set_cardinarity(this, table);
8755 }
8756
8757 if (flag & HA_STATUS_TIME)
8758 stats.update_time = (ulong) share->update_time;
8759 if (flag & (HA_STATUS_CONST | HA_STATUS_VARIABLE))
8760 {
8761 stats.max_data_file_length = share->max_data_file_length;
8762 stats.create_time = (ulong) share->create_time;
8763 stats.block_size = spider_param_block_size(thd);
8764 }
8765 if (flag & HA_STATUS_VARIABLE)
8766 {
8767 stats.data_file_length = share->data_file_length;
8768 stats.index_file_length = share->index_file_length;
8769 stats.records = share->records;
8770 stats.mean_rec_length = share->mean_rec_length;
8771 stats.check_time = (ulong) share->check_time;
8772 if (stats.records <= 1 /* && (flag & HA_STATUS_NO_LOCK) */ )
8773 stats.records = 2;
8774 }
8775 if (flag & HA_STATUS_AUTO)
8776 {
8777#ifdef HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT
8778 auto_inc_temporary = FALSE;
8779#endif
8780#ifdef WITH_PARTITION_STORAGE_ENGINE
8781 if (share->partition_share && table->next_number_field)
8782 {
8783 ulonglong first_value, nb_reserved_values;
8784 if (
8785 tmp_auto_increment_mode == 0 &&
8786 !(
8787 table->next_number_field->val_int() != 0 ||
8788 (table->auto_increment_field_not_null &&
8789 thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO)
8790 )
8791 ) {
8792 get_auto_increment(0, 0, 0, &first_value, &nb_reserved_values);
8793 share->lgtm_tblhnd_share->auto_increment_value = first_value;
8794 share->lgtm_tblhnd_share->auto_increment_lclval = first_value;
8795 share->lgtm_tblhnd_share->auto_increment_init = TRUE;
8796 DBUG_PRINT("info",("spider init auto_increment_lclval=%llu",
8797 share->lgtm_tblhnd_share->auto_increment_lclval));
8798 DBUG_PRINT("info",("spider auto_increment_value=%llu",
8799 share->lgtm_tblhnd_share->auto_increment_value));
8800 stats.auto_increment_value = first_value;
8801 } else if (tmp_auto_increment_mode == 1 &&
8802 !share->lgtm_tblhnd_share->auto_increment_init)
8803 {
8804 DBUG_PRINT("info",("spider auto_increment_value=%llu",
8805 share->lgtm_tblhnd_share->auto_increment_value));
8806 share->lgtm_tblhnd_share->auto_increment_lclval =
8807 share->lgtm_tblhnd_share->auto_increment_value;
8808 share->lgtm_tblhnd_share->auto_increment_init = TRUE;
8809 stats.auto_increment_value =
8810 share->lgtm_tblhnd_share->auto_increment_value;
8811 } else {
8812 DBUG_PRINT("info",("spider auto_increment_value=%llu",
8813 share->lgtm_tblhnd_share->auto_increment_value));
8814 stats.auto_increment_value =
8815 share->lgtm_tblhnd_share->auto_increment_value;
8816 }
8817 } else {
8818#endif
8819 stats.auto_increment_value =
8820 share->lgtm_tblhnd_share->auto_increment_value;
8821#ifdef WITH_PARTITION_STORAGE_ENGINE
8822 }
8823#endif
8824 }
8825 }
8826 if (flag & HA_STATUS_ERRKEY)
8827 errkey = dup_key_idx;
8828 DBUG_RETURN(0);
8829}
8830
8831ha_rows ha_spider::records_in_range(
8832 uint inx,
8833 key_range *start_key,
8834 key_range *end_key
8835) {
8836 int error_num;
8837 THD *thd = ha_thd();
8838 double crd_interval = spider_param_crd_interval(thd, share->crd_interval);
8839 int crd_mode = spider_param_crd_mode(thd, share->crd_mode);
8840 int crd_type = spider_param_crd_type(thd, share->crd_type);
8841#ifdef WITH_PARTITION_STORAGE_ENGINE
8842 int crd_sync = spider_param_crd_sync(thd, share->crd_sync);
8843#endif
8844#ifndef WITHOUT_SPIDER_BG_SEARCH
8845 int crd_bg_mode = spider_param_crd_bg_mode(thd, share->crd_bg_mode);
8846#endif
8847 SPIDER_INIT_ERROR_TABLE *spider_init_error_table = NULL;
8848 uint dbton_id;
8849 spider_db_handler *dbton_hdl;
8850 DBUG_ENTER("ha_spider::records_in_range");
8851 DBUG_PRINT("info",("spider this=%p", this));
8852 DBUG_PRINT("info",("spider inx=%u", inx));
8853 time_t tmp_time = (time_t) time((time_t*) 0);
8854 if (!share->crd_init)
8855 {
8856 pthread_mutex_lock(&share->crd_mutex);
8857 if (share->crd_init)
8858 pthread_mutex_unlock(&share->crd_mutex);
8859 else {
8860 if ((spider_init_error_table =
8861 spider_get_init_error_table(trx, share, FALSE)))
8862 {
8863 DBUG_PRINT("info",("spider diff=%f",
8864 difftime(tmp_time, spider_init_error_table->init_error_time)));
8865 if (difftime(tmp_time,
8866 spider_init_error_table->init_error_time) <
8867 spider_param_table_init_error_interval())
8868 {
8869 pthread_mutex_unlock(&share->crd_mutex);
8870 if (spider_init_error_table->init_error_with_message)
8871 my_message(spider_init_error_table->init_error,
8872 spider_init_error_table->init_error_msg, MYF(0));
8873 if (check_error_mode(spider_init_error_table->init_error))
8874 my_errno = spider_init_error_table->init_error;
8875 DBUG_RETURN(HA_POS_ERROR);
8876 }
8877 }
8878 pthread_mutex_unlock(&share->crd_mutex);
8879 if (crd_mode == 3)
8880 crd_mode = 1;
8881 crd_interval = 0;
8882 }
8883 }
8884 dbton_id = share->sql_dbton_ids[search_link_idx];
8885 dbton_hdl = dbton_handler[dbton_id];
8886 crd_mode = dbton_hdl->crd_mode_exchange(crd_mode);
8887 if (crd_mode == 1 || crd_mode == 2)
8888 {
8889 DBUG_PRINT("info", ("spider static_key_cardinality[%u]=%lld", inx,
8890 share->static_key_cardinality[inx]));
8891 DBUG_PRINT("info",
8892 ("spider difftime=%f", difftime(tmp_time, share->crd_get_time)));
8893 DBUG_PRINT("info",
8894 ("spider crd_interval=%f", crd_interval));
8895 if (
8896 share->static_key_cardinality[inx] == -1 &&
8897 difftime(tmp_time, share->crd_get_time) >= crd_interval
8898 ) {
8899 if (
8900 crd_interval == 0 ||
8901 !pthread_mutex_trylock(&share->crd_mutex)
8902 ) {
8903#ifndef WITHOUT_SPIDER_BG_SEARCH
8904 if (crd_interval == 0 || crd_bg_mode == 0)
8905 {
8906#endif
8907 if (crd_interval == 0)
8908 pthread_mutex_lock(&share->crd_mutex);
8909 if (difftime(tmp_time, share->crd_get_time) >= crd_interval)
8910 {
8911 if ((error_num = spider_get_crd(share, search_link_idx, tmp_time,
8912 this, table, crd_interval, crd_mode,
8913#ifdef WITH_PARTITION_STORAGE_ENGINE
8914 crd_sync,
8915#endif
8916 share->crd_init ? 2 : 1)))
8917 {
8918 pthread_mutex_unlock(&share->crd_mutex);
8919 if (
8920 share->monitoring_kind[search_link_idx] &&
8921 need_mons[search_link_idx]
8922 ) {
8923 error_num = spider_ping_table_mon_from_table(
8924 trx,
8925 trx->thd,
8926 share,
8927 search_link_idx,
8928 (uint32) share->monitoring_sid[search_link_idx],
8929 share->table_name,
8930 share->table_name_length,
8931 conn_link_idx[search_link_idx],
8932 NULL,
8933 0,
8934 share->monitoring_kind[search_link_idx],
8935 share->monitoring_limit[search_link_idx],
8936 share->monitoring_flag[search_link_idx],
8937 TRUE
8938 );
8939 }
8940 if (!share->crd_init)
8941 {
8942 if (
8943 spider_init_error_table ||
8944 (spider_init_error_table =
8945 spider_get_init_error_table(trx, share, TRUE))
8946 ) {
8947 spider_init_error_table->init_error = error_num;
8948/*
8949 if (!thd->is_error())
8950 my_error(error_num, MYF(0), "");
8951*/
8952 if ((spider_init_error_table->init_error_with_message =
8953 thd->is_error()))
8954 strmov(spider_init_error_table->init_error_msg,
8955 spider_stmt_da_message(thd));
8956 spider_init_error_table->init_error_time =
8957 (time_t) time((time_t*) 0);
8958 }
8959 share->init_error = TRUE;
8960 share->init = TRUE;
8961 }
8962 if (check_error_mode(error_num))
8963 my_errno = error_num;
8964 DBUG_RETURN(HA_POS_ERROR);
8965 }
8966 }
8967#ifndef WITHOUT_SPIDER_BG_SEARCH
8968 } else if (crd_bg_mode == 1) {
8969 /* background */
8970 if (!share->bg_crd_init || share->bg_crd_thd_wait)
8971 {
8972 share->bg_crd_thd_wait = FALSE;
8973 share->bg_crd_try_time = tmp_time;
8974 share->bg_crd_interval = crd_interval;
8975 share->bg_crd_mode = crd_mode;
8976#ifdef WITH_PARTITION_STORAGE_ENGINE
8977 share->bg_crd_sync = crd_sync;
8978#endif
8979 if (!share->bg_crd_init)
8980 {
8981 if ((error_num = spider_create_crd_thread(share)))
8982 {
8983 pthread_mutex_unlock(&share->crd_mutex);
8984 my_errno = error_num;
8985 DBUG_RETURN(HA_POS_ERROR);
8986 }
8987 } else
8988 pthread_cond_signal(&share->bg_crd_cond);
8989 }
8990 } else {
8991 share->bg_crd_try_time = tmp_time;
8992 share->bg_crd_interval = crd_interval;
8993 share->bg_crd_mode = crd_mode;
8994#ifdef WITH_PARTITION_STORAGE_ENGINE
8995 share->bg_crd_sync = crd_sync;
8996#endif
8997 spider_table_add_share_to_crd_thread(share);
8998 }
8999#endif
9000 pthread_mutex_unlock(&share->crd_mutex);
9001 }
9002 }
9003
9004 KEY *key_info = &table->key_info[inx];
9005 key_part_map full_key_part_map =
9006 make_prev_keypart_map(spider_user_defined_key_parts(key_info));
9007 key_part_map start_key_part_map;
9008 key_part_map end_key_part_map;
9009 key_part_map tgt_key_part_map;
9010 KEY_PART_INFO *key_part;
9011 Field *field = NULL;
9012 double rows = (double) share->records;
9013 double weight, rate;
9014 DBUG_PRINT("info",("spider rows1=%f", rows));
9015 if (start_key)
9016 start_key_part_map = start_key->keypart_map & full_key_part_map;
9017 else
9018 start_key_part_map = 0;
9019 if (end_key)
9020 end_key_part_map = end_key->keypart_map & full_key_part_map;
9021 else
9022 end_key_part_map = 0;
9023
9024 if (!start_key_part_map && !end_key_part_map)
9025 {
9026 DBUG_RETURN(HA_POS_ERROR);
9027 }
9028 else if (start_key_part_map >= end_key_part_map)
9029 {
9030 tgt_key_part_map = start_key_part_map;
9031 } else {
9032 tgt_key_part_map = end_key_part_map;
9033 }
9034
9035 if (crd_type == 0)
9036 weight = spider_param_crd_weight(thd, share->crd_weight);
9037 else
9038 weight = 1;
9039
9040 if (share->static_key_cardinality[inx] == -1)
9041 {
9042 for (
9043 key_part = key_info->key_part;
9044 tgt_key_part_map > 1;
9045 tgt_key_part_map >>= 1,
9046 key_part++
9047 ) {
9048 field = key_part->field;
9049 DBUG_PRINT("info",
9050 ("spider field_index=%u",
9051 field->field_index));
9052 DBUG_PRINT("info",
9053 ("spider cardinality=%lld", share->cardinality[field->field_index]));
9054 if (share->cardinality[field->field_index] == -1)
9055 {
9056 DBUG_PRINT("info",
9057 ("spider uninitialized column cardinality"));
9058 DBUG_RETURN(HA_POS_ERROR);
9059 }
9060 if ((rate =
9061 ((double) share->cardinality[field->field_index]) / weight) >= 1
9062 ) {
9063 if ((rows = rows / rate) < 2)
9064 {
9065 DBUG_PRINT("info",("spider rows2=%f then ret 2", rows));
9066 DBUG_RETURN((ha_rows) 2);
9067 }
9068 }
9069 if (crd_type == 1)
9070 weight += spider_param_crd_weight(thd, share->crd_weight);
9071 else if (crd_type == 2)
9072 weight *= spider_param_crd_weight(thd, share->crd_weight);
9073 }
9074 field = key_part->field;
9075 DBUG_PRINT("info",
9076 ("spider field_index=%u",
9077 field->field_index));
9078 DBUG_PRINT("info",
9079 ("spider cardinality=%lld", share->cardinality[field->field_index]));
9080 if (share->cardinality[field->field_index] == -1)
9081 {
9082 DBUG_PRINT("info",
9083 ("spider uninitialized column cardinality"));
9084 DBUG_RETURN(HA_POS_ERROR);
9085 }
9086 }
9087 if (
9088 start_key_part_map >= end_key_part_map &&
9089 start_key->flag == HA_READ_KEY_EXACT
9090 ) {
9091 if (share->static_key_cardinality[inx] == -1)
9092 {
9093 if ((rate =
9094 ((double) share->cardinality[field->field_index]) / weight) >= 1)
9095 rows = rows / rate;
9096 } else {
9097 rate = ((double) share->static_key_cardinality[inx]);
9098 rows = rows / rate;
9099 }
9100 } else if (start_key_part_map == end_key_part_map)
9101 {
9102 if (share->static_key_cardinality[inx] == -1)
9103 {
9104 if ((rate =
9105 ((double) share->cardinality[field->field_index]) / weight / 4) >= 1)
9106 rows = rows / rate;
9107 } else {
9108 if ((rate =
9109 ((double) share->static_key_cardinality[inx]) / 4) >= 1)
9110 rows = rows / rate;
9111 }
9112 } else {
9113 if (share->static_key_cardinality[inx] == -1)
9114 {
9115 if ((rate =
9116 ((double) share->cardinality[field->field_index]) / weight / 16) >= 1)
9117 rows = rows / rate;
9118 } else {
9119 if ((rate =
9120 ((double) share->static_key_cardinality[inx]) / 16) >= 1)
9121 rows = rows / rate;
9122 }
9123 }
9124 if (rows < 2)
9125 {
9126 DBUG_PRINT("info",("spider rows3=%f then ret 2", rows));
9127 DBUG_RETURN((ha_rows) 2);
9128 }
9129 DBUG_PRINT("info",("spider rows4=%f", rows));
9130 DBUG_RETURN((ha_rows) rows);
9131 } else if (crd_mode == 3)
9132 {
9133 result_list.key_info = &table->key_info[inx];
9134 DBUG_RETURN(spider_db_explain_select(start_key, end_key, this,
9135 search_link_idx));
9136 }
9137 DBUG_RETURN((ha_rows) spider_param_crd_weight(thd, share->crd_weight));
9138}
9139
9140int ha_spider::check_crd()
9141{
9142 int error_num;
9143 THD *thd = ha_thd();
9144 double crd_interval = spider_param_crd_interval(thd, share->crd_interval);
9145 int crd_mode = spider_param_crd_mode(thd, share->crd_mode);
9146#ifdef WITH_PARTITION_STORAGE_ENGINE
9147 int crd_sync = spider_param_crd_sync(thd, share->crd_sync);
9148#endif
9149#ifndef WITHOUT_SPIDER_BG_SEARCH
9150 int crd_bg_mode = spider_param_crd_bg_mode(thd, share->crd_bg_mode);
9151#endif
9152 SPIDER_INIT_ERROR_TABLE *spider_init_error_table = NULL;
9153 uint dbton_id;
9154 spider_db_handler *dbton_hdl;
9155 DBUG_ENTER("ha_spider::check_crd");
9156 DBUG_PRINT("info",("spider this=%p", this));
9157 time_t tmp_time = (time_t) time((time_t*) 0);
9158 if (!share->crd_init)
9159 {
9160 pthread_mutex_lock(&share->crd_mutex);
9161 if (share->crd_init)
9162 pthread_mutex_unlock(&share->crd_mutex);
9163 else {
9164 if ((spider_init_error_table =
9165 spider_get_init_error_table(trx, share, FALSE)))
9166 {
9167 DBUG_PRINT("info",("spider diff=%f",
9168 difftime(tmp_time, spider_init_error_table->init_error_time)));
9169 if (difftime(tmp_time,
9170 spider_init_error_table->init_error_time) <
9171 spider_param_table_init_error_interval())
9172 {
9173 pthread_mutex_unlock(&share->crd_mutex);
9174 if (spider_init_error_table->init_error_with_message)
9175 my_message(spider_init_error_table->init_error,
9176 spider_init_error_table->init_error_msg, MYF(0));
9177 DBUG_RETURN(check_error_mode(spider_init_error_table->init_error));
9178 }
9179 }
9180 pthread_mutex_unlock(&share->crd_mutex);
9181 crd_interval = 0;
9182 }
9183 }
9184 if (crd_mode == 3)
9185 crd_mode = 1;
9186 if ((error_num = spider_check_trx_and_get_conn(ha_thd(), this, FALSE)))
9187 {
9188 DBUG_RETURN(check_error_mode(error_num));
9189 }
9190 dbton_id = share->sql_dbton_ids[search_link_idx];
9191 dbton_hdl = dbton_handler[dbton_id];
9192 crd_mode = dbton_hdl->crd_mode_exchange(crd_mode);
9193 DBUG_PRINT("info",
9194 ("spider difftime=%f", difftime(tmp_time, share->crd_get_time)));
9195 DBUG_PRINT("info",
9196 ("spider crd_interval=%f", crd_interval));
9197 if (difftime(tmp_time, share->crd_get_time) >= crd_interval)
9198 {
9199 if (
9200 crd_interval == 0 ||
9201 !pthread_mutex_trylock(&share->crd_mutex)
9202 ) {
9203#ifndef WITHOUT_SPIDER_BG_SEARCH
9204 if (crd_interval == 0 || crd_bg_mode == 0)
9205 {
9206#endif
9207 if (crd_interval == 0)
9208 pthread_mutex_lock(&share->crd_mutex);
9209 if (difftime(tmp_time, share->crd_get_time) >= crd_interval)
9210 {
9211 if ((error_num = spider_get_crd(share, search_link_idx, tmp_time,
9212 this, table, crd_interval, crd_mode,
9213#ifdef WITH_PARTITION_STORAGE_ENGINE
9214 crd_sync,
9215#endif
9216 share->crd_init ? 2 : 1)))
9217 {
9218 pthread_mutex_unlock(&share->crd_mutex);
9219 if (
9220 share->monitoring_kind[search_link_idx] &&
9221 need_mons[search_link_idx]
9222 ) {
9223 error_num = spider_ping_table_mon_from_table(
9224 trx,
9225 trx->thd,
9226 share,
9227 search_link_idx,
9228 (uint32) share->monitoring_sid[search_link_idx],
9229 share->table_name,
9230 share->table_name_length,
9231 conn_link_idx[search_link_idx],
9232 NULL,
9233 0,
9234 share->monitoring_kind[search_link_idx],
9235 share->monitoring_limit[search_link_idx],
9236 share->monitoring_flag[search_link_idx],
9237 TRUE
9238 );
9239 }
9240 if (!share->crd_init)
9241 {
9242 if (
9243 spider_init_error_table ||
9244 (spider_init_error_table =
9245 spider_get_init_error_table(trx, share, TRUE))
9246 ) {
9247 spider_init_error_table->init_error = error_num;
9248 if ((spider_init_error_table->init_error_with_message =
9249 thd->is_error()))
9250 strmov(spider_init_error_table->init_error_msg,
9251 spider_stmt_da_message(thd));
9252 spider_init_error_table->init_error_time =
9253 (time_t) time((time_t*) 0);
9254 }
9255 share->init_error = TRUE;
9256 share->init = TRUE;
9257 }
9258 DBUG_RETURN(check_error_mode(error_num));
9259 }
9260 }
9261#ifndef WITHOUT_SPIDER_BG_SEARCH
9262 } else if (crd_bg_mode == 1) {
9263 /* background */
9264 if (!share->bg_crd_init || share->bg_crd_thd_wait)
9265 {
9266 share->bg_crd_thd_wait = FALSE;
9267 share->bg_crd_try_time = tmp_time;
9268 share->bg_crd_interval = crd_interval;
9269 share->bg_crd_mode = crd_mode;
9270#ifdef WITH_PARTITION_STORAGE_ENGINE
9271 share->bg_crd_sync = crd_sync;
9272#endif
9273 if (!share->bg_crd_init)
9274 {
9275 if ((error_num = spider_create_crd_thread(share)))
9276 {
9277 pthread_mutex_unlock(&share->crd_mutex);
9278 DBUG_RETURN(error_num);
9279 }
9280 } else
9281 pthread_cond_signal(&share->bg_crd_cond);
9282 }
9283 } else {
9284 share->bg_crd_try_time = tmp_time;
9285 share->bg_crd_interval = crd_interval;
9286 share->bg_crd_mode = crd_mode;
9287#ifdef WITH_PARTITION_STORAGE_ENGINE
9288 share->bg_crd_sync = crd_sync;
9289#endif
9290 spider_table_add_share_to_crd_thread(share);
9291 }
9292#endif
9293 pthread_mutex_unlock(&share->crd_mutex);
9294 }
9295 }
9296 DBUG_RETURN(0);
9297}
9298
9299int ha_spider::pre_records()
9300{
9301 int error_num;
9302 backup_error_status();
9303 DBUG_ENTER("ha_spider::pre_records");
9304 DBUG_PRINT("info",("spider this=%p", this));
9305 if (sql_command == SQLCOM_ALTER_TABLE)
9306 {
9307 DBUG_RETURN(0);
9308 }
9309 if (!(share->additional_table_flags & HA_HAS_RECORDS))
9310 {
9311 DBUG_RETURN(0);
9312 }
9313 THD *thd = trx->thd;
9314 if (
9315 spider_param_sync_autocommit(thd) &&
9316 (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
9317 ) {
9318 result_list.casual_read[search_link_idx] =
9319 spider_param_casual_read(thd, share->casual_read);
9320 }
9321 if ((error_num = spider_db_show_records(this, search_link_idx, TRUE)))
9322 {
9323 DBUG_RETURN(check_error_mode(error_num));
9324 }
9325 use_pre_records = TRUE;
9326 DBUG_RETURN(0);
9327}
9328
9329ha_rows ha_spider::records()
9330{
9331 int error_num;
9332 backup_error_status();
9333 DBUG_ENTER("ha_spider::records");
9334 DBUG_PRINT("info",("spider this=%p", this));
9335 if (sql_command == SQLCOM_ALTER_TABLE)
9336 {
9337 use_pre_records = FALSE;
9338 DBUG_RETURN(0);
9339 }
9340 if (!(share->additional_table_flags & HA_HAS_RECORDS) && !this->result_list.direct_limit_offset)
9341 {
9342 DBUG_RETURN(handler::records());
9343 }
9344 if (!use_pre_records && !this->result_list.direct_limit_offset)
9345 {
9346 THD *thd = trx->thd;
9347 if (
9348 spider_param_sync_autocommit(thd) &&
9349 (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
9350 ) {
9351 result_list.casual_read[search_link_idx] =
9352 spider_param_casual_read(thd, share->casual_read);
9353 }
9354 }
9355 if ((error_num = spider_db_show_records(this, search_link_idx, FALSE)))
9356 {
9357 use_pre_records = FALSE;
9358 check_error_mode(error_num);
9359 DBUG_RETURN(HA_POS_ERROR);
9360 }
9361 use_pre_records = FALSE;
9362 share->records = table_rows;
9363 DBUG_RETURN(table_rows);
9364}
9365
9366const char *ha_spider::table_type() const
9367{
9368 DBUG_ENTER("ha_spider::table_type");
9369 DBUG_PRINT("info",("spider this=%p", this));
9370 DBUG_RETURN("SPIDER");
9371}
9372
9373ulonglong ha_spider::table_flags() const
9374{
9375 DBUG_ENTER("ha_spider::table_flags");
9376 DBUG_PRINT("info",("spider this=%p", this));
9377 ulonglong flags =
9378 HA_REC_NOT_IN_SEQ |
9379 HA_CAN_GEOMETRY |
9380 HA_NULL_IN_KEY |
9381 HA_CAN_INDEX_BLOBS |
9382 HA_AUTO_PART_KEY |
9383 HA_CAN_RTREEKEYS |
9384 HA_PRIMARY_KEY_REQUIRED_FOR_DELETE |
9385 /* HA_NO_PREFIX_CHAR_KEYS | */
9386 HA_CAN_FULLTEXT |
9387 HA_CAN_SQL_HANDLER |
9388 HA_FILE_BASED |
9389 HA_CAN_INSERT_DELAYED |
9390 HA_CAN_BIT_FIELD |
9391 HA_NO_COPY_ON_ALTER |
9392 HA_BINLOG_ROW_CAPABLE |
9393 HA_BINLOG_STMT_CAPABLE |
9394 HA_PARTIAL_COLUMN_READ |
9395#ifdef HA_CMP_REF_IS_EXPENSIVE
9396 HA_CMP_REF_IS_EXPENSIVE |
9397#endif
9398#ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON
9399 HA_CAN_TABLE_CONDITION_PUSHDOWN |
9400#endif
9401#ifdef HA_CAN_BULK_ACCESS
9402#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
9403 (support_bulk_access_hs() ? HA_CAN_BULK_ACCESS : 0) |
9404#endif
9405#endif
9406 SPIDER_CAN_BG_SEARCH |
9407 SPIDER_CAN_BG_INSERT |
9408 SPIDER_CAN_BG_UPDATE |
9409#ifdef HA_CAN_DIRECT_UPDATE_AND_DELETE
9410 HA_CAN_DIRECT_UPDATE_AND_DELETE |
9411#endif
9412#ifdef HA_CAN_FORCE_BULK_UPDATE
9413 (share && share->force_bulk_update ? HA_CAN_FORCE_BULK_UPDATE : 0) |
9414#endif
9415#ifdef HA_CAN_FORCE_BULK_DELETE
9416 (share && share->force_bulk_delete ? HA_CAN_FORCE_BULK_DELETE : 0) |
9417#endif
9418 (share ? share->additional_table_flags : 0)
9419 ;
9420 DBUG_RETURN(flags);
9421}
9422
9423const char *ha_spider::index_type(
9424 uint key_number
9425) {
9426 KEY *key_info = &table->s->key_info[key_number];
9427 DBUG_ENTER("ha_spider::index_type");
9428 DBUG_PRINT("info",("spider this=%p", this));
9429 DBUG_PRINT("info",("spider flags=%ld", key_info->flags));
9430 DBUG_PRINT("info",("spider algorithm=%d", key_info->algorithm));
9431 DBUG_RETURN(
9432 (key_info->flags & HA_FULLTEXT) ? "FULLTEXT" :
9433 (key_info->flags & HA_SPATIAL) ? "SPATIAL" :
9434 (key_info->algorithm == HA_KEY_ALG_HASH) ? "HASH" :
9435 (key_info->algorithm == HA_KEY_ALG_RTREE) ? "RTREE" :
9436 "BTREE"
9437 );
9438}
9439
9440ulong ha_spider::index_flags(
9441 uint idx,
9442 uint part,
9443 bool all_parts
9444) const {
9445 DBUG_ENTER("ha_spider::index_flags");
9446 DBUG_PRINT("info",("spider this=%p", this));
9447 DBUG_RETURN(
9448 (table_share->key_info[idx].algorithm == HA_KEY_ALG_FULLTEXT) ?
9449 0 :
9450 (table_share->key_info[idx].algorithm == HA_KEY_ALG_HASH) ?
9451 HA_ONLY_WHOLE_INDEX | HA_KEY_SCAN_NOT_ROR :
9452 HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_READ_RANGE |
9453 HA_KEYREAD_ONLY
9454 );
9455}
9456
9457uint ha_spider::max_supported_record_length() const
9458{
9459 DBUG_ENTER("ha_spider::max_supported_record_length");
9460 DBUG_PRINT("info",("spider this=%p", this));
9461 DBUG_RETURN(HA_MAX_REC_LENGTH);
9462}
9463
9464uint ha_spider::max_supported_keys() const
9465{
9466 DBUG_ENTER("ha_spider::max_supported_keys");
9467 DBUG_PRINT("info",("spider this=%p", this));
9468 DBUG_RETURN(MAX_KEY);
9469}
9470
9471uint ha_spider::max_supported_key_parts() const
9472{
9473 DBUG_ENTER("ha_spider::max_supported_key_parts");
9474 DBUG_PRINT("info",("spider this=%p", this));
9475 DBUG_RETURN(MAX_REF_PARTS);
9476}
9477
9478uint ha_spider::max_supported_key_length() const
9479{
9480 DBUG_ENTER("ha_spider::max_supported_key_length");
9481 DBUG_PRINT("info",("spider this=%p", this));
9482 DBUG_RETURN(SPIDER_MAX_KEY_LENGTH);
9483}
9484
9485uint ha_spider::max_supported_key_part_length() const
9486{
9487 DBUG_ENTER("ha_spider::max_supported_key_part_length");
9488 DBUG_PRINT("info",("spider this=%p", this));
9489 DBUG_RETURN(SPIDER_MAX_KEY_LENGTH);
9490}
9491
9492uint8 ha_spider::table_cache_type()
9493{
9494 DBUG_ENTER("ha_spider::table_cache_type");
9495 DBUG_PRINT("info",("spider this=%p", this));
9496 DBUG_RETURN(HA_CACHE_TBL_NOCACHE);
9497}
9498
9499#ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC
9500bool ha_spider::need_info_for_auto_inc()
9501{
9502 THD *thd = ha_thd();
9503 DBUG_ENTER("ha_spider::need_info_for_auto_inc");
9504 DBUG_PRINT("info",("spider this=%p", this));
9505 DBUG_PRINT("info",("spider return=%s", (
9506 !share->lgtm_tblhnd_share->auto_increment_init ||
9507 (
9508 !spider_param_auto_increment_mode(thd, share->auto_increment_mode) &&
9509 !info_auto_called
9510 )
9511 ) ? "TRUE" : "FALSE"));
9512 DBUG_RETURN((
9513 !share->lgtm_tblhnd_share->auto_increment_init ||
9514 (
9515 !spider_param_auto_increment_mode(thd, share->auto_increment_mode) &&
9516 !info_auto_called
9517 )
9518 ));
9519}
9520#endif
9521
9522#ifdef HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT
9523bool ha_spider::can_use_for_auto_inc_init()
9524{
9525 DBUG_ENTER("ha_spider::can_use_for_auto_inc_init");
9526 DBUG_PRINT("info",("spider this=%p", this));
9527 DBUG_PRINT("info",("spider return=%s", (
9528 !auto_inc_temporary
9529 ) ? "TRUE" : "FALSE"));
9530 DBUG_RETURN((
9531 !auto_inc_temporary
9532 ));
9533}
9534#endif
9535
9536int ha_spider::update_auto_increment()
9537{
9538 int error_num;
9539 THD *thd = ha_thd();
9540 int auto_increment_mode = spider_param_auto_increment_mode(thd,
9541 share->auto_increment_mode);
9542 bool lock_here = FALSE;
9543 backup_error_status();
9544 DBUG_ENTER("ha_spider::update_auto_increment");
9545 DBUG_PRINT("info",("spider this=%p", this));
9546 force_auto_increment = TRUE;
9547/*
9548 if (
9549 next_insert_id >= auto_inc_interval_for_cur_row.maximum() &&
9550 trx->thd->auto_inc_intervals_forced.get_current()
9551 ) {
9552 force_auto_increment = TRUE;
9553 DBUG_PRINT("info",("spider force_auto_increment=TRUE"));
9554 } else {
9555 force_auto_increment = FALSE;
9556 DBUG_PRINT("info",("spider force_auto_increment=FALSE"));
9557 }
9558*/
9559 DBUG_PRINT("info",("spider auto_increment_mode=%d",
9560 auto_increment_mode));
9561 DBUG_PRINT("info",("spider next_number_field=%lld",
9562 table->next_number_field->val_int()));
9563 if (
9564 auto_increment_mode == 1 &&
9565 !(
9566 table->next_number_field->val_int() != 0 ||
9567 (table->auto_increment_field_not_null &&
9568 thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO)
9569 )
9570 ) {
9571 lock_here = TRUE;
9572 pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
9573 next_insert_id = share->lgtm_tblhnd_share->auto_increment_value;
9574 DBUG_PRINT("info",("spider auto_increment_value=%llu",
9575 share->lgtm_tblhnd_share->auto_increment_value));
9576 }
9577 if ((error_num = handler::update_auto_increment()))
9578 {
9579 if (lock_here)
9580 pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
9581 DBUG_RETURN(check_error_mode(error_num));
9582 }
9583 if (lock_here)
9584 {
9585 if (insert_id_for_cur_row)
9586 {
9587 share->lgtm_tblhnd_share->auto_increment_lclval =
9588 insert_id_for_cur_row + 1;
9589 share->lgtm_tblhnd_share->auto_increment_value = next_insert_id;
9590 DBUG_PRINT("info",("spider after auto_increment_lclval=%llu",
9591 share->lgtm_tblhnd_share->auto_increment_lclval));
9592 DBUG_PRINT("info",("spider auto_increment_value=%llu",
9593 share->lgtm_tblhnd_share->auto_increment_value));
9594 }
9595 pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
9596 }
9597 if (!store_last_insert_id)
9598 {
9599 store_last_insert_id = table->next_number_field->val_int();
9600 }
9601 DBUG_RETURN(0);
9602}
9603
9604void ha_spider::get_auto_increment(
9605 ulonglong offset,
9606 ulonglong increment,
9607 ulonglong nb_desired_values,
9608 ulonglong *first_value,
9609 ulonglong *nb_reserved_values
9610) {
9611 THD *thd = ha_thd();
9612 int auto_increment_mode = spider_param_auto_increment_mode(thd,
9613 share->auto_increment_mode);
9614 DBUG_ENTER("ha_spider::get_auto_increment");
9615 DBUG_PRINT("info",("spider this=%p", this));
9616 *nb_reserved_values = ULONGLONG_MAX;
9617 if (auto_increment_mode == 0)
9618 {
9619 /* strict mode */
9620 int error_num;
9621 extra(HA_EXTRA_KEYREAD);
9622 if (index_init(table_share->next_number_index, TRUE))
9623 goto error_index_init;
9624 result_list.internal_limit = 1;
9625 if (table_share->next_number_keypart)
9626 {
9627 uchar key[MAX_KEY_LENGTH];
9628 key_copy(key, table->record[0],
9629 &table->key_info[table_share->next_number_index],
9630 table_share->next_number_key_offset);
9631 error_num = index_read_last_map(table->record[1], key,
9632 make_prev_keypart_map(table_share->next_number_keypart));
9633 } else
9634 error_num = index_last(table->record[1]);
9635
9636 if (error_num)
9637 *first_value = 1;
9638 else
9639 *first_value = ((ulonglong) table->next_number_field->
9640 val_int_offset(table_share->rec_buff_length) + 1);
9641 index_end();
9642 extra(HA_EXTRA_NO_KEYREAD);
9643 DBUG_VOID_RETURN;
9644
9645error_index_init:
9646 extra(HA_EXTRA_NO_KEYREAD);
9647 *first_value = ~(ulonglong)0;
9648 DBUG_VOID_RETURN;
9649 } else {
9650 if (auto_increment_mode != 1)
9651 pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
9652 DBUG_PRINT("info",("spider before auto_increment_lclval=%llu",
9653 share->lgtm_tblhnd_share->auto_increment_lclval));
9654 *first_value = share->lgtm_tblhnd_share->auto_increment_lclval;
9655 share->lgtm_tblhnd_share->auto_increment_lclval +=
9656 nb_desired_values * increment;
9657 DBUG_PRINT("info",("spider after auto_increment_lclval=%llu",
9658 share->lgtm_tblhnd_share->auto_increment_lclval));
9659 if (auto_increment_mode != 1)
9660 pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
9661 }
9662 DBUG_VOID_RETURN;
9663}
9664
9665int ha_spider::reset_auto_increment(
9666 ulonglong value
9667) {
9668 DBUG_ENTER("ha_spider::reset_auto_increment");
9669 DBUG_PRINT("info",("spider this=%p", this));
9670 if (table->next_number_field)
9671 {
9672 pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
9673 share->lgtm_tblhnd_share->auto_increment_lclval = value;
9674 share->lgtm_tblhnd_share->auto_increment_init = TRUE;
9675 DBUG_PRINT("info",("spider init auto_increment_lclval=%llu",
9676 share->lgtm_tblhnd_share->auto_increment_lclval));
9677 pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
9678 }
9679 DBUG_RETURN(0);
9680}
9681
9682void ha_spider::release_auto_increment()
9683{
9684 DBUG_ENTER("ha_spider::release_auto_increment");
9685 DBUG_PRINT("info",("spider this=%p", this));
9686 DBUG_VOID_RETURN;
9687}
9688
9689#ifdef SPIDER_HANDLER_START_BULK_INSERT_HAS_FLAGS
9690void ha_spider::start_bulk_insert(
9691 ha_rows rows,
9692 uint flags
9693)
9694#else
9695void ha_spider::start_bulk_insert(
9696 ha_rows rows
9697)
9698#endif
9699{
9700 DBUG_ENTER("ha_spider::start_bulk_insert");
9701 DBUG_PRINT("info",("spider this=%p", this));
9702 bulk_insert = TRUE;
9703 bulk_size = -1;
9704 store_last_insert_id = 0;
9705 DBUG_VOID_RETURN;
9706}
9707
9708int ha_spider::end_bulk_insert()
9709{
9710 int error_num;
9711 backup_error_status();
9712 DBUG_ENTER("ha_spider::end_bulk_insert");
9713 DBUG_PRINT("info",("spider this=%p", this));
9714 bulk_insert = FALSE;
9715 if (bulk_size == -1)
9716 DBUG_RETURN(0);
9717 if ((error_num = spider_db_bulk_insert(this, table, TRUE)))
9718 DBUG_RETURN(check_error_mode(error_num));
9719 DBUG_RETURN(0);
9720}
9721
9722int ha_spider::write_row(
9723 uchar *buf
9724) {
9725 int error_num;
9726 THD *thd = ha_thd();
9727 int auto_increment_mode = spider_param_auto_increment_mode(thd,
9728 share->auto_increment_mode);
9729 bool auto_increment_flag =
9730 table->next_number_field && buf == table->record[0];
9731 backup_error_status();
9732 DBUG_ENTER("ha_spider::write_row");
9733 DBUG_PRINT("info",("spider this=%p", this));
9734 if (spider_param_read_only_mode(thd, share->read_only_mode))
9735 {
9736 my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0),
9737 table_share->db.str, table_share->table_name.str);
9738 DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM);
9739 }
9740#ifdef HA_CAN_BULK_ACCESS
9741 if (
9742 bulk_access_executing &&
9743 (
9744 (
9745 !is_bulk_access_clone &&
9746 bulk_access_link_exec_tgt->called
9747 ) ||
9748 bulk_access_pre_called
9749 )
9750 ) {
9751 ulonglong option_backup = 0;
9752 if (is_bulk_access_clone)
9753 {
9754 bulk_access_pre_called = FALSE;
9755 DBUG_RETURN(spider_db_bulk_bulk_insert(this));
9756 }
9757#if MYSQL_VERSION_ID < 50500
9758 option_backup = thd->options;
9759 thd->options &= ~OPTION_BIN_LOG;
9760#else
9761 option_backup = thd->variables.option_bits;
9762 thd->variables.option_bits &= ~OPTION_BIN_LOG;
9763#endif
9764 error_num = bulk_access_link_exec_tgt->spider->ha_write_row(buf);
9765#if MYSQL_VERSION_ID < 50500
9766 thd->options = option_backup;
9767#else
9768 thd->variables.option_bits = option_backup;
9769#endif
9770 DBUG_RETURN(error_num);
9771 }
9772#endif
9773#ifndef SPIDER_WITHOUT_HA_STATISTIC_INCREMENT
9774 ha_statistic_increment(&SSV::ha_write_count);
9775#endif
9776#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
9777#else
9778 if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
9779 table->timestamp_field->set_time();
9780#endif
9781 if (!bulk_insert)
9782 store_last_insert_id = 0;
9783 if (auto_increment_flag)
9784 {
9785 if (auto_increment_mode == 3)
9786 {
9787 if (!table->auto_increment_field_not_null)
9788 {
9789#ifndef DBUG_OFF
9790 my_bitmap_map *tmp_map =
9791 dbug_tmp_use_all_columns(table, table->write_set);
9792#endif
9793 table->next_number_field->store((longlong) 0, TRUE);
9794#ifndef DBUG_OFF
9795 dbug_tmp_restore_column_map(table->write_set, tmp_map);
9796#endif
9797 force_auto_increment = FALSE;
9798 table->file->insert_id_for_cur_row = 0;
9799 }
9800 } else if (auto_increment_mode == 2)
9801 {
9802#ifndef DBUG_OFF
9803 my_bitmap_map *tmp_map =
9804 dbug_tmp_use_all_columns(table, table->write_set);
9805#endif
9806 table->next_number_field->store((longlong) 0, TRUE);
9807 table->auto_increment_field_not_null = FALSE;
9808#ifndef DBUG_OFF
9809 dbug_tmp_restore_column_map(table->write_set, tmp_map);
9810#endif
9811 force_auto_increment = FALSE;
9812 table->file->insert_id_for_cur_row = 0;
9813 } else {
9814 if (!share->lgtm_tblhnd_share->auto_increment_init)
9815 {
9816 pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
9817 if (!share->lgtm_tblhnd_share->auto_increment_init)
9818 {
9819 info(HA_STATUS_AUTO);
9820 share->lgtm_tblhnd_share->auto_increment_lclval =
9821 stats.auto_increment_value;
9822 share->lgtm_tblhnd_share->auto_increment_init = TRUE;
9823 DBUG_PRINT("info",("spider init auto_increment_lclval=%llu",
9824 share->lgtm_tblhnd_share->auto_increment_lclval));
9825 }
9826 pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
9827 }
9828 if ((error_num = update_auto_increment()))
9829 DBUG_RETURN(error_num);
9830 }
9831 }
9832 if (!bulk_insert || bulk_size < 0)
9833 {
9834 direct_dup_insert =
9835 spider_param_direct_dup_insert(trx->thd, share->direct_dup_insert);
9836 DBUG_PRINT("info",("spider direct_dup_insert=%d", direct_dup_insert));
9837 if ((error_num = spider_db_bulk_insert_init(this, table)))
9838 DBUG_RETURN(check_error_mode(error_num));
9839 if (bulk_insert)
9840 bulk_size =
9841#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
9842 (insert_with_update && !result_list.insert_dup_update_pushdown) ||
9843#else
9844 insert_with_update ||
9845#endif
9846 (!direct_dup_insert && ignore_dup_key) ?
9847 0 : spider_param_bulk_size(trx->thd, share->bulk_size);
9848 else
9849 bulk_size = 0;
9850 }
9851 if ((error_num = spider_db_bulk_insert(this, table, FALSE)))
9852 DBUG_RETURN(check_error_mode(error_num));
9853
9854#ifdef HA_CAN_BULK_ACCESS
9855 /* bulk access disabled case (like using partitioning) */
9856 if (bulk_access_executing && is_bulk_access_clone)
9857 {
9858 bulk_req_exec();
9859 DBUG_RETURN(spider_db_bulk_bulk_insert(this));
9860 }
9861#endif
9862 DBUG_RETURN(0);
9863}
9864
9865#ifdef HA_CAN_BULK_ACCESS
9866int ha_spider::pre_write_row(
9867 uchar *buf
9868) {
9869 int error_num;
9870 ulonglong option_backup = 0;
9871 THD *thd = trx->thd;
9872 DBUG_ENTER("ha_spider::pre_write_row");
9873 DBUG_PRINT("info",("spider this=%p", this));
9874#if MYSQL_VERSION_ID < 50500
9875 option_backup = thd->options;
9876 thd->options &= ~OPTION_BIN_LOG;
9877#else
9878 option_backup = thd->variables.option_bits;
9879 thd->variables.option_bits &= ~OPTION_BIN_LOG;
9880#endif
9881 error_num = bulk_access_link_current->spider->ha_write_row(buf);
9882 bulk_access_link_current->spider->bulk_access_pre_called = TRUE;
9883 bulk_access_link_current->called = TRUE;
9884#if MYSQL_VERSION_ID < 50500
9885 thd->options = option_backup;
9886#else
9887 thd->variables.option_bits = option_backup;
9888#endif
9889 DBUG_RETURN(error_num);
9890}
9891#endif
9892
9893#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
9894void ha_spider::direct_update_init(
9895 THD *thd,
9896 bool hs_request
9897) {
9898#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
9899 uint roop_count;
9900#endif
9901 DBUG_ENTER("ha_spider::direct_update_init");
9902 DBUG_PRINT("info",("spider this=%p", this));
9903 do_direct_update = TRUE;
9904#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
9905 if (hs_request)
9906 {
9907 maybe_do_hs_direct_update = TRUE;
9908 memset(do_hs_direct_update, 0, share->link_bitmap_size);
9909 for (roop_count = 0; roop_count < share->link_count; roop_count++)
9910 {
9911 if (spider_param_use_hs_write(thd, share->use_hs_writes[roop_count]))
9912 {
9913 DBUG_PRINT("info",("spider do_hs_direct_update[%d]=TRUE",
9914 roop_count));
9915 spider_set_bit(do_hs_direct_update, roop_count);
9916 } else {
9917 maybe_do_hs_direct_update = FALSE;
9918 }
9919 }
9920 } else {
9921 maybe_do_hs_direct_update = FALSE;
9922 }
9923#endif
9924 DBUG_VOID_RETURN;
9925}
9926#endif
9927
9928bool ha_spider::start_bulk_update(
9929) {
9930 DBUG_ENTER("ha_spider::start_bulk_update");
9931 DBUG_PRINT("info",("spider this=%p", this));
9932 DBUG_RETURN(check_and_start_bulk_update(SPD_BU_START_BY_BULK_INIT));
9933}
9934
9935int ha_spider::exec_bulk_update(
9936 ha_rows *dup_key_found
9937) {
9938 int error_num;
9939 backup_error_status();
9940 DBUG_ENTER("ha_spider::exec_bulk_update");
9941 DBUG_PRINT("info",("spider this=%p", this));
9942 *dup_key_found = 0;
9943 if ((error_num = spider_db_bulk_update_end(this, dup_key_found)))
9944 DBUG_RETURN(check_error_mode(error_num));
9945 DBUG_RETURN(0);
9946}
9947
9948int ha_spider::end_bulk_update(
9949) {
9950 int error_num;
9951 backup_error_status();
9952 DBUG_ENTER("ha_spider::end_bulk_update");
9953 DBUG_PRINT("info",("spider this=%p", this));
9954 if ((error_num = check_and_end_bulk_update(SPD_BU_START_BY_BULK_INIT)))
9955 {
9956 if (check_error_mode(error_num))
9957 DBUG_RETURN(error_num);
9958 }
9959 DBUG_RETURN(0);
9960}
9961
9962int ha_spider::bulk_update_row(
9963 const uchar *old_data,
9964 const uchar *new_data,
9965 ha_rows *dup_key_found
9966) {
9967 DBUG_ENTER("ha_spider::bulk_update_row");
9968 DBUG_PRINT("info",("spider this=%p", this));
9969 *dup_key_found = 0;
9970 DBUG_RETURN(update_row(old_data, new_data));
9971}
9972
9973int ha_spider::update_row(
9974 const uchar *old_data,
9975 const uchar *new_data
9976) {
9977 int error_num;
9978 THD *thd = ha_thd();
9979 backup_error_status();
9980 DBUG_ENTER("ha_spider::update_row");
9981 DBUG_PRINT("info",("spider this=%p", this));
9982 if (spider_param_read_only_mode(thd, share->read_only_mode))
9983 {
9984 my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0),
9985 table_share->db.str, table_share->table_name.str);
9986 DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM);
9987 }
9988#ifdef HA_CAN_BULK_ACCESS
9989 if (
9990 bulk_access_executing && !is_bulk_access_clone &&
9991 bulk_access_link_exec_tgt->called
9992 ) {
9993 ulonglong option_backup = 0;
9994#if MYSQL_VERSION_ID < 50500
9995 option_backup = thd->options;
9996 thd->options &= ~OPTION_BIN_LOG;
9997#else
9998 option_backup = thd->variables.option_bits;
9999 thd->variables.option_bits &= ~OPTION_BIN_LOG;
10000#endif
10001 error_num = bulk_access_link_exec_tgt->spider->ha_update_row(
10002 old_data, new_data);
10003#if MYSQL_VERSION_ID < 50500
10004 thd->options = option_backup;
10005#else
10006 thd->variables.option_bits = option_backup;
10007#endif
10008 DBUG_RETURN(error_num);
10009 }
10010#endif
10011#ifndef SPIDER_WITHOUT_HA_STATISTIC_INCREMENT
10012 ha_statistic_increment(&SSV::ha_update_count);
10013#endif
10014#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
10015 do_direct_update = FALSE;
10016#endif
10017#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
10018#else
10019 if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
10020 table->timestamp_field->set_time();
10021#endif
10022 if ((error_num = spider_db_update(this, table, old_data)))
10023 DBUG_RETURN(check_error_mode(error_num));
10024 if (table->found_next_number_field &&
10025 new_data == table->record[0] &&
10026 !table->s->next_number_keypart
10027 ) {
10028 pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
10029 if (!share->lgtm_tblhnd_share->auto_increment_init)
10030 {
10031 info(HA_STATUS_AUTO);
10032 share->lgtm_tblhnd_share->auto_increment_lclval =
10033 stats.auto_increment_value;
10034 share->lgtm_tblhnd_share->auto_increment_init = TRUE;
10035 DBUG_PRINT("info",("spider init auto_increment_lclval=%llu",
10036 share->lgtm_tblhnd_share->auto_increment_lclval));
10037 }
10038 ulonglong tmp_auto_increment;
10039 if (((Field_num *) table->found_next_number_field)->unsigned_flag)
10040 {
10041 tmp_auto_increment =
10042 (ulonglong) table->found_next_number_field->val_int();
10043 } else {
10044 longlong tmp_auto_increment2 =
10045 table->found_next_number_field->val_int();
10046 if (tmp_auto_increment2 > 0)
10047 tmp_auto_increment = tmp_auto_increment2;
10048 else
10049 tmp_auto_increment = 0;
10050 }
10051 if (tmp_auto_increment >= share->lgtm_tblhnd_share->auto_increment_lclval)
10052 {
10053 share->lgtm_tblhnd_share->auto_increment_lclval = tmp_auto_increment + 1;
10054 share->lgtm_tblhnd_share->auto_increment_value = tmp_auto_increment + 1;
10055 DBUG_PRINT("info",("spider after auto_increment_lclval=%llu",
10056 share->lgtm_tblhnd_share->auto_increment_lclval));
10057 DBUG_PRINT("info",("spider auto_increment_value=%llu",
10058 share->lgtm_tblhnd_share->auto_increment_value));
10059 }
10060 pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
10061 }
10062 DBUG_RETURN(0);
10063}
10064
10065#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
10066#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS
10067int ha_spider::direct_update_rows_init(
10068 uint mode,
10069 KEY_MULTI_RANGE *ranges,
10070 uint range_count,
10071 bool sorted,
10072 const uchar *new_data
10073) {
10074#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
10075 int error_num;
10076#endif
10077 st_select_lex *select_lex;
10078 longlong select_limit;
10079 longlong offset_limit;
10080 THD *thd = trx->thd;
10081 DBUG_ENTER("ha_spider::direct_update_rows_init");
10082 DBUG_PRINT("info",("spider this=%p", this));
10083#ifdef HA_CAN_BULK_ACCESS
10084 if (
10085 bulk_access_executing &&
10086 (
10087 (
10088 !is_bulk_access_clone &&
10089 bulk_access_link_exec_tgt->called
10090 ) ||
10091 bulk_access_pre_called
10092 )
10093 ) {
10094 if (is_bulk_access_clone)
10095 {
10096 DBUG_PRINT("info",("spider return pre_direct_init_result %d",
10097 pre_direct_init_result));
10098 DBUG_RETURN(pre_direct_init_result);
10099 }
10100 DBUG_RETURN(bulk_access_link_exec_tgt->spider->direct_update_rows_init(
10101 mode, ranges, range_count, sorted, new_data));
10102 }
10103#endif
10104 direct_update_init(
10105 thd,
10106#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
10107 sql_command == SQLCOM_HS_UPDATE
10108#else
10109 FALSE
10110#endif
10111 );
10112 if (!condition)
10113 cond_check = FALSE;
10114 spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit);
10115 if (
10116 !range_count &&
10117 direct_update_fields
10118 ) {
10119 if (
10120#if MYSQL_VERSION_ID < 50500
10121 !thd->variables.engine_condition_pushdown ||
10122#else
10123#ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON
10124#else
10125 !(thd->variables.optimizer_switch &
10126 OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) ||
10127#endif
10128#endif
10129 !select_lex ||
10130 select_lex->table_list.elements != 1 ||
10131 check_update_columns_sql_part() ||
10132 spider_db_append_condition(this, NULL, 0, TRUE)
10133 ) {
10134 DBUG_PRINT("info",("spider FALSE by condition"));
10135 do_direct_update = FALSE;
10136 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
10137 }
10138 if (select_lex->order_list.elements)
10139 {
10140 ORDER *order;
10141 for (order = (ORDER *) select_lex->order_list.first; order;
10142 order = order->next)
10143 {
10144 if (check_item_type_sql((*order->item)))
10145 {
10146 DBUG_PRINT("info",("spider FALSE by order"));
10147 do_direct_update = FALSE;
10148 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
10149 }
10150 }
10151 result_list.direct_order_limit = TRUE;
10152 }
10153 trx->direct_update_count++;
10154 DBUG_PRINT("info",("spider OK"));
10155 DBUG_RETURN(0);
10156 }
10157
10158 DBUG_PRINT("info",("spider offset_limit=%lld", offset_limit));
10159 DBUG_PRINT("info",("spider mode=%u", mode));
10160 DBUG_PRINT("info",("spider sql_command=%u", sql_command));
10161#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
10162 DBUG_PRINT("info",("spider maybe_do_hs_direct_update=%s",
10163 maybe_do_hs_direct_update ? "TRUE" : "FALSE"));
10164 DBUG_PRINT("info",("spider hs_pushed_ret_fields_num=%zu",
10165 hs_pushed_ret_fields_num));
10166#endif
10167 DBUG_PRINT("info",("spider do_direct_update=%s",
10168 do_direct_update ? "TRUE" : "FALSE"));
10169 if (
10170 (
10171 !offset_limit
10172#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
10173 || (mode == 2 && maybe_do_hs_direct_update)
10174#endif
10175 ) &&
10176#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
10177 sql_command == SQLCOM_HS_UPDATE &&
10178 hs_pushed_ret_fields_num < MAX_FIELDS &&
10179#endif
10180 do_direct_update
10181 ) {
10182#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
10183 DBUG_PRINT("info",("spider pk_update=%s", pk_update ? "TRUE" : "FALSE"));
10184 DBUG_PRINT("info",("spider start_key=%p", &ranges->start_key));
10185 if (pk_update && spider_check_hs_pk_update(this, &ranges->start_key))
10186 {
10187 DBUG_PRINT("info",("spider FALSE by pk_update"));
10188 do_direct_update = FALSE;
10189 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
10190 }
10191 if ((error_num = spider_check_trx_and_get_conn(thd, this, TRUE)))
10192 {
10193 DBUG_RETURN(error_num);
10194 }
10195#endif
10196 trx->direct_update_count++;
10197 DBUG_PRINT("info",("spider OK"));
10198 DBUG_RETURN(0);
10199 }
10200 DBUG_PRINT("info",("spider FALSE by default"));
10201 do_direct_update = FALSE;
10202 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
10203}
10204#else
10205int ha_spider::direct_update_rows_init()
10206{
10207 st_select_lex *select_lex;
10208 longlong select_limit;
10209 longlong offset_limit;
10210 THD *thd = trx->thd;
10211 DBUG_ENTER("ha_spider::direct_update_rows_init");
10212 DBUG_PRINT("info",("spider this=%p", this));
10213#ifdef HA_CAN_BULK_ACCESS
10214 if (
10215 bulk_access_executing &&
10216 (
10217 (
10218 !is_bulk_access_clone &&
10219 bulk_access_link_exec_tgt->called
10220 ) ||
10221 bulk_access_pre_called
10222 )
10223 ) {
10224 if (is_bulk_access_clone)
10225 {
10226 DBUG_PRINT("info",("spider return pre_direct_init_result %d",
10227 pre_direct_init_result));
10228 DBUG_RETURN(pre_direct_init_result);
10229 }
10230 DBUG_RETURN(bulk_access_link_exec_tgt->spider->direct_update_rows_init());
10231 }
10232#endif
10233 direct_update_init(
10234 thd,
10235 FALSE
10236 );
10237 if (!condition)
10238 cond_check = FALSE;
10239 spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit);
10240 if (direct_update_fields)
10241 {
10242 if (
10243#if MYSQL_VERSION_ID < 50500
10244 !thd->variables.engine_condition_pushdown ||
10245#else
10246#ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON
10247#else
10248 !(thd->variables.optimizer_switch &
10249 OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) ||
10250#endif
10251#endif
10252 !select_lex ||
10253 select_lex->table_list.elements != 1 ||
10254 check_update_columns_sql_part() ||
10255 spider_db_append_condition(this, NULL, 0, TRUE)
10256 ) {
10257 DBUG_PRINT("info",("spider FALSE by condition"));
10258 do_direct_update = FALSE;
10259 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
10260 }
10261 if (select_lex->order_list.elements)
10262 {
10263 ORDER *order;
10264 for (order = (ORDER *) select_lex->order_list.first; order;
10265 order = order->next)
10266 {
10267 if (check_item_type_sql((*order->item)))
10268 {
10269 DBUG_PRINT("info",("spider FALSE by order"));
10270 do_direct_update = FALSE;
10271 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
10272 }
10273 }
10274 result_list.direct_order_limit = TRUE;
10275 }
10276 trx->direct_update_count++;
10277 DBUG_PRINT("info",("spider OK"));
10278 DBUG_RETURN(0);
10279 }
10280
10281 DBUG_PRINT("info",("spider offset_limit=%lld", offset_limit));
10282 DBUG_PRINT("info",("spider sql_command=%u", sql_command));
10283 DBUG_PRINT("info",("spider do_direct_update=%s",
10284 do_direct_update ? "TRUE" : "FALSE"));
10285 if (
10286 !offset_limit &&
10287 do_direct_update
10288 ) {
10289 trx->direct_update_count++;
10290 DBUG_PRINT("info",("spider OK"));
10291 DBUG_RETURN(0);
10292 }
10293 DBUG_PRINT("info",("spider FALSE by default"));
10294 do_direct_update = FALSE;
10295 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
10296}
10297#endif
10298
10299#ifdef HA_CAN_BULK_ACCESS
10300#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS
10301int ha_spider::pre_direct_update_rows_init(
10302 uint mode,
10303 KEY_MULTI_RANGE *ranges,
10304 uint range_count,
10305 bool sorted,
10306 const uchar *new_data
10307) {
10308 int error_num;
10309 DBUG_ENTER("ha_spider::pre_direct_update_rows_init");
10310 DBUG_PRINT("info",("spider this=%p", this));
10311 if (bulk_access_started)
10312 {
10313 error_num = bulk_access_link_current->spider->
10314 pre_direct_update_rows_init(
10315 mode, ranges, range_count, sorted, new_data);
10316 bulk_access_link_current->spider->bulk_access_pre_called = TRUE;
10317 bulk_access_link_current->called = TRUE;
10318 DBUG_RETURN(error_num);
10319 }
10320 pre_direct_init_result = direct_update_rows_init(
10321 mode, ranges, range_count, sorted, new_data);
10322 DBUG_RETURN(pre_direct_init_result);
10323}
10324#else
10325int ha_spider::pre_direct_update_rows_init()
10326{
10327 int error_num;
10328 DBUG_ENTER("ha_spider::pre_direct_update_rows_init");
10329 DBUG_PRINT("info",("spider this=%p", this));
10330 if (bulk_access_started)
10331 {
10332 error_num = bulk_access_link_current->spider->
10333 pre_direct_update_rows_init();
10334 bulk_access_link_current->spider->bulk_access_pre_called = TRUE;
10335 bulk_access_link_current->called = TRUE;
10336 DBUG_RETURN(error_num);
10337 }
10338 pre_direct_init_result = direct_update_rows_init();
10339 DBUG_RETURN(pre_direct_init_result);
10340}
10341#endif
10342#endif
10343
10344#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS
10345int ha_spider::direct_update_rows(
10346 KEY_MULTI_RANGE *ranges,
10347 uint range_count,
10348 bool sorted,
10349 uchar *new_data,
10350 ha_rows *update_rows
10351) {
10352 int error_num;
10353 THD *thd = ha_thd();
10354 backup_error_status();
10355 DBUG_ENTER("ha_spider::direct_update_rows");
10356 DBUG_PRINT("info",("spider this=%p", this));
10357 if (spider_param_read_only_mode(thd, share->read_only_mode))
10358 {
10359 my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0),
10360 table_share->db.str, table_share->table_name.str);
10361 DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM);
10362 }
10363#ifdef HA_CAN_BULK_ACCESS
10364 if (
10365 bulk_access_executing &&
10366 (
10367 (
10368 !is_bulk_access_clone &&
10369 bulk_access_link_exec_tgt->called
10370 ) ||
10371 bulk_access_pre_called
10372 )
10373 ) {
10374 if (is_bulk_access_clone)
10375 {
10376 bulk_access_pre_called = FALSE;
10377 DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows));
10378 }
10379 DBUG_RETURN(bulk_access_link_exec_tgt->spider->ha_direct_update_rows(
10380 ranges, range_count, sorted, new_data, update_rows));
10381 }
10382#endif
10383 if (
10384 (active_index != MAX_KEY && (error_num = index_handler_init())) ||
10385 (active_index == MAX_KEY && (error_num = rnd_handler_init())) ||
10386 (error_num = spider_db_direct_update(this, table, ranges, range_count,
10387 update_rows))
10388 )
10389 DBUG_RETURN(check_error_mode(error_num));
10390
10391#ifdef HA_CAN_BULK_ACCESS
10392 if (bulk_access_executing && is_bulk_access_clone)
10393 {
10394 bulk_req_exec();
10395 DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows));
10396 }
10397#endif
10398 DBUG_RETURN(0);
10399}
10400#else
10401int ha_spider::direct_update_rows(
10402 ha_rows *update_rows
10403) {
10404 int error_num;
10405 THD *thd = ha_thd();
10406 backup_error_status();
10407 DBUG_ENTER("ha_spider::direct_update_rows");
10408 DBUG_PRINT("info",("spider this=%p", this));
10409 if (spider_param_read_only_mode(thd, share->read_only_mode))
10410 {
10411 my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0),
10412 table_share->db.str, table_share->table_name.str);
10413 DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM);
10414 }
10415#ifdef HA_CAN_BULK_ACCESS
10416 if (
10417 bulk_access_executing &&
10418 (
10419 (
10420 !is_bulk_access_clone &&
10421 bulk_access_link_exec_tgt->called
10422 ) ||
10423 bulk_access_pre_called
10424 )
10425 ) {
10426 if (is_bulk_access_clone)
10427 {
10428 bulk_access_pre_called = FALSE;
10429 DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows));
10430 }
10431 DBUG_RETURN(bulk_access_link_exec_tgt->spider->ha_direct_update_rows(
10432 update_rows));
10433 }
10434#endif
10435 if (
10436 (active_index != MAX_KEY && (error_num = index_handler_init())) ||
10437 (active_index == MAX_KEY && (error_num = rnd_handler_init())) ||
10438 (error_num = spider_db_direct_update(this, table, update_rows))
10439 )
10440 DBUG_RETURN(check_error_mode(error_num));
10441
10442#ifdef HA_CAN_BULK_ACCESS
10443 if (bulk_access_executing && is_bulk_access_clone)
10444 {
10445 bulk_req_exec();
10446 DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows));
10447 }
10448#endif
10449 DBUG_RETURN(0);
10450}
10451#endif
10452
10453#ifdef HA_CAN_BULK_ACCESS
10454#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS
10455int ha_spider::pre_direct_update_rows(
10456 KEY_MULTI_RANGE *ranges,
10457 uint range_count,
10458 bool sorted,
10459 uchar *new_data,
10460 ha_rows *update_rows
10461) {
10462 DBUG_ENTER("ha_spider::pre_direct_update_rows");
10463 DBUG_PRINT("info",("spider this=%p", this));
10464 DBUG_RETURN(bulk_access_link_current->spider->ha_direct_update_rows(ranges,
10465 range_count, sorted, new_data, update_rows));
10466}
10467#else
10468int ha_spider::pre_direct_update_rows()
10469{
10470 uint update_rows;
10471 DBUG_ENTER("ha_spider::pre_direct_update_rows");
10472 DBUG_PRINT("info",("spider this=%p", this));
10473 DBUG_RETURN(bulk_access_link_current->spider->ha_direct_update_rows(
10474 &update_rows));
10475}
10476#endif
10477#endif
10478#endif
10479
10480bool ha_spider::start_bulk_delete(
10481) {
10482 DBUG_ENTER("ha_spider::start_bulk_delete");
10483 DBUG_PRINT("info",("spider this=%p", this));
10484 DBUG_RETURN(check_and_start_bulk_update(SPD_BU_START_BY_BULK_INIT));
10485}
10486
10487int ha_spider::end_bulk_delete(
10488) {
10489 int error_num;
10490 backup_error_status();
10491 DBUG_ENTER("ha_spider::end_bulk_delete");
10492 DBUG_PRINT("info",("spider this=%p", this));
10493 if ((error_num = check_and_end_bulk_update(SPD_BU_START_BY_BULK_INIT)))
10494 DBUG_RETURN(check_error_mode(error_num));
10495 DBUG_RETURN(0);
10496}
10497
10498int ha_spider::delete_row(
10499 const uchar *buf
10500) {
10501 THD *thd = ha_thd();
10502 int error_num;
10503 backup_error_status();
10504 DBUG_ENTER("ha_spider::delete_row");
10505 DBUG_PRINT("info",("spider this=%p", this));
10506 if (spider_param_read_only_mode(thd, share->read_only_mode))
10507 {
10508 my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0),
10509 table_share->db.str, table_share->table_name.str);
10510 DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM);
10511 }
10512#ifdef HA_CAN_BULK_ACCESS
10513 if (
10514 bulk_access_executing && !is_bulk_access_clone &&
10515 bulk_access_link_exec_tgt->called
10516 ) {
10517 ulonglong option_backup = 0;
10518#if MYSQL_VERSION_ID < 50500
10519 option_backup = thd->options;
10520 thd->options &= ~OPTION_BIN_LOG;
10521#else
10522 option_backup = thd->variables.option_bits;
10523 thd->variables.option_bits &= ~OPTION_BIN_LOG;
10524#endif
10525 error_num = bulk_access_link_exec_tgt->spider->ha_delete_row(buf);
10526#if MYSQL_VERSION_ID < 50500
10527 thd->options = option_backup;
10528#else
10529 thd->variables.option_bits = option_backup;
10530#endif
10531 DBUG_RETURN(error_num);
10532 }
10533#endif
10534#ifndef SPIDER_WITHOUT_HA_STATISTIC_INCREMENT
10535 ha_statistic_increment(&SSV::ha_delete_count);
10536#endif
10537#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
10538 do_direct_update = FALSE;
10539#endif
10540 if ((error_num = spider_db_delete(this, table, buf)))
10541 DBUG_RETURN(check_error_mode(error_num));
10542 DBUG_RETURN(0);
10543}
10544
10545#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
10546#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS
10547int ha_spider::direct_delete_rows_init(
10548 uint mode,
10549 KEY_MULTI_RANGE *ranges,
10550 uint range_count,
10551 bool sorted
10552) {
10553#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
10554 int error_num;
10555#endif
10556 st_select_lex *select_lex;
10557 longlong select_limit;
10558 longlong offset_limit;
10559 THD *thd = trx->thd;
10560 DBUG_ENTER("ha_spider::direct_delete_rows_init");
10561 DBUG_PRINT("info",("spider this=%p", this));
10562#ifdef HA_CAN_BULK_ACCESS
10563 if (
10564 bulk_access_executing &&
10565 (
10566 (
10567 !is_bulk_access_clone &&
10568 bulk_access_link_exec_tgt->called
10569 ) ||
10570 bulk_access_pre_called
10571 )
10572 ) {
10573 if (is_bulk_access_clone)
10574 {
10575 DBUG_RETURN(pre_direct_init_result);
10576 }
10577 DBUG_RETURN(bulk_access_link_exec_tgt->spider->direct_delete_rows_init(
10578 mode, ranges, range_count, sorted));
10579 }
10580#endif
10581 direct_update_init(
10582 thd,
10583#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
10584 sql_command == SQLCOM_HS_DELETE
10585#else
10586 FALSE
10587#endif
10588 );
10589 if (!condition)
10590 cond_check = FALSE;
10591 spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit);
10592 if (!range_count)
10593 {
10594 if (
10595#if MYSQL_VERSION_ID < 50500
10596 !thd->variables.engine_condition_pushdown ||
10597#else
10598#ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON
10599#else
10600 !(thd->variables.optimizer_switch &
10601 OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) ||
10602#endif
10603#endif
10604 !select_lex ||
10605 select_lex->table_list.elements != 1 ||
10606 spider_db_append_condition(this, NULL, 0, TRUE)
10607 ) {
10608 DBUG_PRINT("info",("spider FALSE by condition"));
10609 do_direct_update = FALSE;
10610 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
10611 }
10612 if (select_lex->order_list.elements)
10613 {
10614 ORDER *order;
10615 for (order = (ORDER *) select_lex->order_list.first; order;
10616 order = order->next)
10617 {
10618 if (check_item_type_sql((*order->item)))
10619 {
10620 DBUG_PRINT("info",("spider FALSE by order"));
10621 do_direct_update = FALSE;
10622 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
10623 }
10624 }
10625 result_list.direct_order_limit = TRUE;
10626 }
10627 trx->direct_delete_count++;
10628 DBUG_PRINT("info",("spider OK"));
10629 DBUG_RETURN(0);
10630 }
10631
10632 if (
10633 (
10634 !offset_limit
10635#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
10636 || (mode == 2 && maybe_do_hs_direct_update)
10637#endif
10638 ) &&
10639#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
10640 sql_command == SQLCOM_HS_DELETE &&
10641#endif
10642 do_direct_update
10643 ) {
10644#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
10645 if ((error_num = spider_check_trx_and_get_conn(thd, this, TRUE)))
10646 {
10647 DBUG_RETURN(error_num);
10648 }
10649#endif
10650 trx->direct_delete_count++;
10651 DBUG_PRINT("info",("spider OK"));
10652 DBUG_RETURN(0);
10653 }
10654 DBUG_PRINT("info",("spider FALSE by default"));
10655 do_direct_update = FALSE;
10656 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
10657}
10658#else
10659int ha_spider::direct_delete_rows_init()
10660{
10661 st_select_lex *select_lex;
10662 longlong select_limit;
10663 longlong offset_limit;
10664 THD *thd = trx->thd;
10665 DBUG_ENTER("ha_spider::direct_delete_rows_init");
10666 DBUG_PRINT("info",("spider this=%p", this));
10667#ifdef HA_CAN_BULK_ACCESS
10668 if (
10669 bulk_access_executing &&
10670 (
10671 (
10672 !is_bulk_access_clone &&
10673 bulk_access_link_exec_tgt->called
10674 ) ||
10675 bulk_access_pre_called
10676 )
10677 ) {
10678 if (is_bulk_access_clone)
10679 {
10680 DBUG_RETURN(pre_direct_init_result);
10681 }
10682 DBUG_RETURN(bulk_access_link_exec_tgt->spider->direct_delete_rows_init());
10683 }
10684#endif
10685 direct_update_init(
10686 thd,
10687 FALSE
10688 );
10689 if (!condition)
10690 cond_check = FALSE;
10691 spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit);
10692 if (
10693#if MYSQL_VERSION_ID < 50500
10694 !thd->variables.engine_condition_pushdown ||
10695#else
10696#ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON
10697#else
10698 !(thd->variables.optimizer_switch &
10699 OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) ||
10700#endif
10701#endif
10702 !select_lex ||
10703 select_lex->table_list.elements != 1 ||
10704 spider_db_append_condition(this, NULL, 0, TRUE)
10705 ) {
10706 DBUG_PRINT("info",("spider FALSE by condition"));
10707 do_direct_update = FALSE;
10708 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
10709 }
10710 if (select_lex->order_list.elements)
10711 {
10712 ORDER *order;
10713 for (order = (ORDER *) select_lex->order_list.first; order;
10714 order = order->next)
10715 {
10716 if (check_item_type_sql((*order->item)))
10717 {
10718 DBUG_PRINT("info",("spider FALSE by order"));
10719 do_direct_update = FALSE;
10720 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
10721 }
10722 }
10723 result_list.direct_order_limit = TRUE;
10724 }
10725 trx->direct_delete_count++;
10726 DBUG_PRINT("info",("spider OK"));
10727 DBUG_RETURN(0);
10728}
10729#endif
10730
10731#ifdef HA_CAN_BULK_ACCESS
10732#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS
10733int ha_spider::pre_direct_delete_rows_init(
10734 uint mode,
10735 KEY_MULTI_RANGE *ranges,
10736 uint range_count,
10737 bool sorted
10738) {
10739 int error_num;
10740 DBUG_ENTER("ha_spider::pre_direct_delete_rows_init");
10741 DBUG_PRINT("info",("spider this=%p", this));
10742 if (bulk_access_started)
10743 {
10744 error_num = bulk_access_link_current->spider->
10745 pre_direct_delete_rows_init(
10746 mode, ranges, range_count, sorted);
10747 bulk_access_link_current->spider->bulk_access_pre_called = TRUE;
10748 bulk_access_link_current->called = TRUE;
10749 DBUG_RETURN(error_num);
10750 }
10751 pre_direct_init_result = direct_delete_rows_init(
10752 mode, ranges, range_count, sorted);
10753 DBUG_RETURN(pre_direct_init_result);
10754}
10755#else
10756int ha_spider::pre_direct_delete_rows_init()
10757{
10758 int error_num;
10759 DBUG_ENTER("ha_spider::pre_direct_delete_rows_init");
10760 DBUG_PRINT("info",("spider this=%p", this));
10761 if (bulk_access_started)
10762 {
10763 error_num = bulk_access_link_current->spider->
10764 pre_direct_delete_rows_init();
10765 bulk_access_link_current->spider->bulk_access_pre_called = TRUE;
10766 bulk_access_link_current->called = TRUE;
10767 DBUG_RETURN(error_num);
10768 }
10769 pre_direct_init_result = direct_delete_rows_init();
10770 DBUG_RETURN(pre_direct_init_result);
10771}
10772#endif
10773#endif
10774
10775#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS
10776int ha_spider::direct_delete_rows(
10777 KEY_MULTI_RANGE *ranges,
10778 uint range_count,
10779 bool sorted,
10780 ha_rows *delete_rows
10781) {
10782 int error_num;
10783 THD *thd = ha_thd();
10784 backup_error_status();
10785 DBUG_ENTER("ha_spider::direct_delete_rows");
10786 DBUG_PRINT("info",("spider this=%p", this));
10787 if (spider_param_read_only_mode(thd, share->read_only_mode))
10788 {
10789 my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0),
10790 table_share->db.str, table_share->table_name.str);
10791 DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM);
10792 }
10793#ifdef HA_CAN_BULK_ACCESS
10794 if (
10795 bulk_access_executing &&
10796 (
10797 (
10798 !is_bulk_access_clone &&
10799 bulk_access_link_exec_tgt->called
10800 ) ||
10801 bulk_access_pre_called
10802 )
10803 ) {
10804 if (is_bulk_access_clone)
10805 {
10806 bulk_access_pre_called = FALSE;
10807 DBUG_RETURN(spider_db_bulk_direct_update(this, delete_rows));
10808 }
10809 DBUG_RETURN(bulk_access_link_exec_tgt->spider->ha_direct_delete_rows(
10810 ranges, range_count, sorted, delete_rows));
10811 }
10812#endif
10813 if (
10814 (active_index != MAX_KEY && (error_num = index_handler_init())) ||
10815 (active_index == MAX_KEY && (error_num = rnd_handler_init())) ||
10816 (error_num = spider_db_direct_delete(this, table, ranges, range_count,
10817 delete_rows))
10818 )
10819 DBUG_RETURN(check_error_mode(error_num));
10820
10821#ifdef HA_CAN_BULK_ACCESS
10822 if (bulk_access_executing && is_bulk_access_clone)
10823 {
10824 bulk_req_exec();
10825 DBUG_RETURN(spider_db_bulk_direct_update(this, delete_rows));
10826 }
10827#endif
10828 DBUG_RETURN(0);
10829}
10830#else
10831int ha_spider::direct_delete_rows(
10832 ha_rows *delete_rows
10833) {
10834 int error_num;
10835 THD *thd = ha_thd();
10836 backup_error_status();
10837 DBUG_ENTER("ha_spider::direct_delete_rows");
10838 DBUG_PRINT("info",("spider this=%p", this));
10839 if (spider_param_read_only_mode(thd, share->read_only_mode))
10840 {
10841 my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0),
10842 table_share->db.str, table_share->table_name.str);
10843 DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM);
10844 }
10845#ifdef HA_CAN_BULK_ACCESS
10846 if (
10847 bulk_access_executing &&
10848 (
10849 (
10850 !is_bulk_access_clone &&
10851 bulk_access_link_exec_tgt->called
10852 ) ||
10853 bulk_access_pre_called
10854 )
10855 ) {
10856 if (is_bulk_access_clone)
10857 {
10858 bulk_access_pre_called = FALSE;
10859 DBUG_RETURN(spider_db_bulk_direct_update(this, delete_rows));
10860 }
10861 DBUG_RETURN(bulk_access_link_exec_tgt->spider->ha_direct_delete_rows(
10862 delete_rows));
10863 }
10864#endif
10865 if (
10866 (active_index != MAX_KEY && (error_num = index_handler_init())) ||
10867 (active_index == MAX_KEY && (error_num = rnd_handler_init())) ||
10868 (error_num = spider_db_direct_delete(this, table, delete_rows))
10869 )
10870 DBUG_RETURN(check_error_mode(error_num));
10871
10872#ifdef HA_CAN_BULK_ACCESS
10873 if (bulk_access_executing && is_bulk_access_clone)
10874 {
10875 bulk_req_exec();
10876 DBUG_RETURN(spider_db_bulk_direct_update(this, delete_rows));
10877 }
10878#endif
10879 DBUG_RETURN(0);
10880}
10881#endif
10882
10883#ifdef HA_CAN_BULK_ACCESS
10884#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS
10885int ha_spider::pre_direct_delete_rows(
10886 KEY_MULTI_RANGE *ranges,
10887 uint range_count,
10888 bool sorted,
10889 ha_rows *delete_rows
10890) {
10891 DBUG_ENTER("ha_spider::pre_direct_delete_rows");
10892 DBUG_PRINT("info",("spider this=%p", this));
10893 DBUG_RETURN(bulk_access_link_current->spider->ha_direct_delete_rows(
10894 ranges, range_count, sorted, delete_rows));
10895}
10896#else
10897int ha_spider::pre_direct_delete_rows()
10898{
10899 uint delete_rows;
10900 DBUG_ENTER("ha_spider::pre_direct_delete_rows");
10901 DBUG_PRINT("info",("spider this=%p", this));
10902 DBUG_RETURN(bulk_access_link_current->spider->ha_direct_delete_rows(
10903 &delete_rows));
10904}
10905#endif
10906#endif
10907#endif
10908
10909int ha_spider::delete_all_rows()
10910{
10911 int error_num, roop_count;
10912 THD *thd = ha_thd();
10913 backup_error_status();
10914 DBUG_ENTER("ha_spider::delete_all_rows");
10915 DBUG_PRINT("info",("spider this=%p", this));
10916 if (spider_param_delete_all_rows_type(thd, share->delete_all_rows_type))
10917 DBUG_RETURN(HA_ERR_WRONG_COMMAND);
10918 if (spider_param_read_only_mode(thd, share->read_only_mode))
10919 {
10920 my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0),
10921 table_share->db.str, table_share->table_name.str);
10922 DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM);
10923 }
10924#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
10925 do_direct_update = FALSE;
10926#endif
10927 sql_kinds = SPIDER_SQL_KIND_SQL;
10928 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
10929 sql_kind[roop_count] = SPIDER_SQL_KIND_SQL;
10930 if ((error_num = spider_db_delete_all_rows(this)))
10931 DBUG_RETURN(check_error_mode(error_num));
10932 if (sql_command == SQLCOM_TRUNCATE && table->found_next_number_field)
10933 {
10934 DBUG_PRINT("info",("spider reset auto increment"));
10935 pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
10936 share->lgtm_tblhnd_share->auto_increment_lclval = 1;
10937 share->lgtm_tblhnd_share->auto_increment_init = FALSE;
10938 share->lgtm_tblhnd_share->auto_increment_value = 1;
10939 DBUG_PRINT("info",("spider init auto_increment_lclval=%llu",
10940 share->lgtm_tblhnd_share->auto_increment_lclval));
10941 DBUG_PRINT("info",("spider auto_increment_value=%llu",
10942 share->lgtm_tblhnd_share->auto_increment_value));
10943 pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
10944 }
10945 DBUG_RETURN(0);
10946}
10947
10948int ha_spider::truncate()
10949{
10950 int error_num, roop_count;
10951 THD *thd = ha_thd();
10952 backup_error_status();
10953 DBUG_ENTER("ha_spider::truncate");
10954 DBUG_PRINT("info",("spider this=%p", this));
10955 if (spider_param_read_only_mode(thd, share->read_only_mode))
10956 {
10957 my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0),
10958 table_share->db.str, table_share->table_name.str);
10959 DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM);
10960 }
10961 sql_command = SQLCOM_TRUNCATE;
10962 if ((error_num = spider_check_trx_and_get_conn(thd, this, FALSE)))
10963 {
10964 DBUG_RETURN(error_num);
10965 }
10966#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
10967 do_direct_update = FALSE;
10968#endif
10969 sql_kinds = SPIDER_SQL_KIND_SQL;
10970 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
10971 sql_kind[roop_count] = SPIDER_SQL_KIND_SQL;
10972 if ((error_num = spider_db_delete_all_rows(this)))
10973 DBUG_RETURN(check_error_mode(error_num));
10974 if (sql_command == SQLCOM_TRUNCATE && table->found_next_number_field)
10975 {
10976 DBUG_PRINT("info",("spider reset auto increment"));
10977 pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
10978 share->lgtm_tblhnd_share->auto_increment_lclval = 1;
10979 share->lgtm_tblhnd_share->auto_increment_init = FALSE;
10980 share->lgtm_tblhnd_share->auto_increment_value = 1;
10981 DBUG_PRINT("info",("spider init auto_increment_lclval=%llu",
10982 share->lgtm_tblhnd_share->auto_increment_lclval));
10983 DBUG_PRINT("info",("spider auto_increment_value=%llu",
10984 share->lgtm_tblhnd_share->auto_increment_value));
10985 pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
10986 }
10987 DBUG_RETURN(0);
10988}
10989
10990#ifdef HA_CAN_BULK_ACCESS
10991void ha_spider::bulk_req_exec()
10992{
10993 int need_mon;
10994 SPIDER_CONN *conn = trx->bulk_access_conn_first;
10995 DBUG_ENTER("ha_spider::bulk_req_exec");
10996 DBUG_PRINT("info",("spider this=%p", this));
10997 DBUG_PRINT("info",("spider trx=%p", trx));
10998 DBUG_PRINT("info",("spider first_conn=%p", conn));
10999 while (conn)
11000 {
11001 DBUG_PRINT("info",("spider conn=%p", conn));
11002 DBUG_PRINT("info",("spider conn->bulk_access_requests=%u",
11003 conn->bulk_access_requests));
11004 if (conn->bulk_access_requests)
11005 {
11006 spider_bg_conn_wait(conn);
11007 pthread_mutex_lock(&conn->mta_conn_mutex);
11008 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
11009 conn->need_mon = &need_mon;
11010 conn->mta_conn_mutex_lock_already = TRUE;
11011 conn->mta_conn_mutex_unlock_later = TRUE;
11012 /* currently only used for HS */
11013 conn->bulk_access_error_num = 0;
11014 if (spider_db_query(
11015 conn,
11016 NULL,
11017 0,
11018 -1,
11019 &need_mon)
11020 ) {
11021 conn->bulk_access_error_num = spider_db_errorno(conn);
11022 }
11023/*
11024 conn->bulk_access_sended += conn->bulk_access_requests;
11025*/
11026 conn->bulk_access_requests = 0;
11027 conn->mta_conn_mutex_lock_already = FALSE;
11028 conn->mta_conn_mutex_unlock_later = FALSE;
11029 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
11030 pthread_mutex_unlock(&conn->mta_conn_mutex);
11031 }
11032 conn = conn->bulk_access_next;
11033 }
11034 trx->bulk_access_conn_first = NULL;
11035 DBUG_VOID_RETURN;
11036}
11037#endif
11038
11039double ha_spider::scan_time()
11040{
11041 DBUG_ENTER("ha_spider::scan_time");
11042 DBUG_PRINT("info",("spider this=%p", this));
11043 DBUG_PRINT("info",("spider scan_time = %.6f",
11044 share->scan_rate * share->records * share->mean_rec_length + 2));
11045 DBUG_RETURN(share->scan_rate * share->records * share->mean_rec_length + 2);
11046}
11047
11048double ha_spider::read_time(
11049 uint index,
11050 uint ranges,
11051 ha_rows rows
11052) {
11053 DBUG_ENTER("ha_spider::read_time");
11054 DBUG_PRINT("info",("spider this=%p", this));
11055 if (keyread)
11056 {
11057 DBUG_PRINT("info",("spider read_time(keyread) = %.6f",
11058 share->read_rate * table->s->key_info[index].key_length *
11059 rows / 2 + 2));
11060 DBUG_RETURN(share->read_rate * table->s->key_info[index].key_length *
11061 rows / 2 + 2);
11062 } else {
11063 DBUG_PRINT("info",("spider read_time = %.6f",
11064 share->read_rate * share->mean_rec_length * rows + 2));
11065 DBUG_RETURN(share->read_rate * share->mean_rec_length * rows + 2);
11066 }
11067}
11068
11069const key_map *ha_spider::keys_to_use_for_scanning()
11070{
11071 DBUG_ENTER("ha_spider::keys_to_use_for_scanning");
11072 DBUG_PRINT("info",("spider this=%p", this));
11073 DBUG_RETURN(&key_map_full);
11074}
11075
11076ha_rows ha_spider::estimate_rows_upper_bound()
11077{
11078 DBUG_ENTER("ha_spider::estimate_rows_upper_bound");
11079 DBUG_PRINT("info",("spider this=%p", this));
11080 DBUG_RETURN(HA_POS_ERROR);
11081}
11082
11083void ha_spider::print_error(
11084 int error,
11085 myf errflag
11086) {
11087 DBUG_ENTER("ha_spider::print_error");
11088 DBUG_PRINT("info",("spider this=%p", this));
11089 if (!current_thd->is_error())
11090 {
11091 switch (error)
11092 {
11093 case ER_SPIDER_CON_COUNT_ERROR:
11094 my_message(error, ER_SPIDER_CON_COUNT_ERROR_STR, MYF(0));
11095 break;
11096 default:
11097 handler::print_error(error, errflag);
11098 break;
11099 }
11100 }
11101 DBUG_VOID_RETURN;
11102}
11103
11104bool ha_spider::get_error_message(
11105 int error,
11106 String *buf
11107) {
11108 DBUG_ENTER("ha_spider::get_error_message");
11109 DBUG_PRINT("info",("spider this=%p", this));
11110 switch (error)
11111 {
11112 case ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM:
11113 if (buf->reserve(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_LEN))
11114 DBUG_RETURN(TRUE);
11115 buf->q_append(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR,
11116 ER_SPIDER_REMOTE_SERVER_GONE_AWAY_LEN);
11117 break;
11118 default:
11119 if (buf->reserve(ER_SPIDER_UNKNOWN_LEN))
11120 DBUG_RETURN(TRUE);
11121 buf->q_append(ER_SPIDER_UNKNOWN_STR, ER_SPIDER_UNKNOWN_LEN);
11122 break;
11123 }
11124 DBUG_RETURN(FALSE);
11125}
11126
11127int ha_spider::create(
11128 const char *name,
11129 TABLE *form,
11130 HA_CREATE_INFO *info
11131) {
11132 int error_num, dummy;
11133 SPIDER_SHARE tmp_share;
11134 THD *thd = ha_thd();
11135 uint sql_command = thd_sql_command(thd), roop_count;
11136 SPIDER_TRX *trx;
11137 TABLE *table_tables = NULL;
11138#if MYSQL_VERSION_ID < 50500
11139 Open_tables_state open_tables_backup;
11140#else
11141 Open_tables_backup open_tables_backup;
11142#endif
11143 bool need_lock = FALSE;
11144 DBUG_ENTER("ha_spider::create");
11145 DBUG_PRINT("info",("spider this=%p", this));
11146 DBUG_PRINT("info",("spider name=%s", name));
11147 DBUG_PRINT("info",
11148 ("spider form->s->connect_string=%s", form->s->connect_string.str));
11149 DBUG_PRINT("info",
11150 ("spider info->connect_string=%s", info->connect_string.str));
11151 if (
11152 sql_command == SQLCOM_CREATE_INDEX ||
11153 sql_command == SQLCOM_DROP_INDEX
11154 )
11155 DBUG_RETURN(0);
11156 if (!(trx = spider_get_trx(thd, TRUE, &error_num)))
11157 goto error_get_trx;
11158 if (
11159 trx->locked_connections &&
11160 sql_command == SQLCOM_ALTER_TABLE
11161 ) {
11162 my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM,
11163 ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0));
11164 error_num = ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM;
11165 goto error_alter_before_unlock;
11166 }
11167 memset(&tmp_share, 0, sizeof(SPIDER_SHARE));
11168 tmp_share.table_name = (char*) name;
11169 tmp_share.table_name_length = strlen(name);
11170#ifdef SPIDER_HAS_HASH_VALUE_TYPE
11171 tmp_share.table_name_hash_value = my_calc_hash(&trx->trx_alter_table_hash,
11172 (uchar*) tmp_share.table_name, tmp_share.table_name_length);
11173 tmp_share.lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
11174 name, tmp_share.table_name_length, tmp_share.table_name_hash_value,
11175 FALSE, TRUE, &error_num);
11176#else
11177 tmp_share.lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
11178 name, tmp_share.table_name_length, FALSE, TRUE, &error_num);
11179#endif
11180 if (!tmp_share.lgtm_tblhnd_share)
11181 {
11182 goto error;
11183 }
11184 if (form->s->keys > 0)
11185 {
11186 if (!(tmp_share.static_key_cardinality = (longlong *)
11187 spider_bulk_malloc(spider_current_trx, 246, MYF(MY_WME),
11188 &tmp_share.static_key_cardinality,
11189 sizeof(*tmp_share.static_key_cardinality) * form->s->keys,
11190 NullS))
11191 ) {
11192 error_num = HA_ERR_OUT_OF_MEM;
11193 goto error;
11194 }
11195 if (!(tmp_share.key_hint = new spider_string[form->s->keys]))
11196 {
11197 error_num = HA_ERR_OUT_OF_MEM;
11198 goto error;
11199 }
11200 }
11201 for (roop_count = 0; roop_count < form->s->keys; roop_count++)
11202 tmp_share.key_hint[roop_count].init_calc_mem(85);
11203 DBUG_PRINT("info",("spider tmp_share.key_hint=%p", tmp_share.key_hint));
11204 if ((error_num = spider_parse_connect_info(&tmp_share, form->s,
11205#ifdef WITH_PARTITION_STORAGE_ENGINE
11206 form->part_info,
11207#endif
11208 1)))
11209 goto error;
11210 DBUG_PRINT("info",("spider tmp_table=%d", form->s->tmp_table));
11211 if (
11212 (sql_command == SQLCOM_CREATE_TABLE &&
11213 !(info->options & HA_LEX_CREATE_TMP_TABLE))
11214 ) {
11215 if (
11216 !(table_tables = spider_open_sys_table(
11217 current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
11218 SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE,
11219 &error_num))
11220 ) {
11221 goto error;
11222 }
11223#ifdef SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE
11224 if (
11225 thd->lex->create_info.or_replace() &&
11226 (error_num = spider_delete_tables(
11227 table_tables, tmp_share.table_name, &dummy))
11228 ) {
11229 goto error;
11230 }
11231#endif
11232 if (
11233 (error_num = spider_insert_tables(table_tables, &tmp_share))
11234 ) {
11235 goto error;
11236 }
11237 spider_close_sys_table(current_thd, table_tables,
11238 &open_tables_backup, FALSE);
11239 table_tables = NULL;
11240 } else if (
11241 sql_command == SQLCOM_ALTER_TABLE
11242 ) {
11243 SPIDER_ALTER_TABLE *alter_table;
11244 if (trx->query_id != thd->query_id)
11245 {
11246 spider_free_trx_alter_table(trx);
11247 trx->query_id = thd->query_id;
11248 }
11249#ifdef SPIDER_HAS_HASH_VALUE_TYPE
11250 if (!(alter_table =
11251 (SPIDER_ALTER_TABLE*) my_hash_search_using_hash_value(
11252 &trx->trx_alter_table_hash, tmp_share.table_name_hash_value,
11253 (uchar*) tmp_share.table_name, tmp_share.table_name_length)))
11254#else
11255 if (!(alter_table =
11256 (SPIDER_ALTER_TABLE*) my_hash_search(&trx->trx_alter_table_hash,
11257 (uchar*) tmp_share.table_name, tmp_share.table_name_length)))
11258#endif
11259 {
11260 if ((error_num = spider_create_trx_alter_table(trx, &tmp_share, TRUE)))
11261 goto error;
11262 }
11263 trx->tmp_flg = TRUE;
11264
11265 DBUG_PRINT("info",
11266 ("spider alter_info.flags: %llu alter_info.partition_flags: %lu",
11267 thd->lex->alter_info.flags, thd->lex->alter_info.partition_flags));
11268 if ((thd->lex->alter_info.partition_flags &
11269 (
11270 SPIDER_ALTER_PARTITION_ADD | SPIDER_ALTER_PARTITION_DROP |
11271 SPIDER_ALTER_PARTITION_COALESCE | SPIDER_ALTER_PARTITION_REORGANIZE |
11272 SPIDER_ALTER_PARTITION_TABLE_REORG | SPIDER_ALTER_PARTITION_REBUILD
11273 )
11274 ) &&
11275 memcmp(name + strlen(name) - 5, "#TMP#", 5)
11276 ) {
11277 need_lock = TRUE;
11278 if (
11279 !(table_tables = spider_open_sys_table(
11280 current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
11281 SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, TRUE,
11282 &error_num))
11283 ) {
11284 goto error;
11285 }
11286 if (
11287 (error_num = spider_insert_tables(table_tables, &tmp_share))
11288 ) {
11289 goto error;
11290 }
11291 spider_close_sys_table(current_thd, table_tables,
11292 &open_tables_backup, TRUE);
11293 table_tables = NULL;
11294 }
11295 }
11296
11297 if (
11298 (
11299 (info->used_fields & HA_CREATE_USED_AUTO) ||
11300 sql_command == SQLCOM_ALTER_TABLE ||
11301 sql_command == SQLCOM_CREATE_INDEX ||
11302 sql_command == SQLCOM_RENAME_TABLE
11303 ) &&
11304 info->auto_increment_value > 0
11305 ) {
11306 pthread_mutex_lock(&tmp_share.lgtm_tblhnd_share->auto_increment_mutex);
11307 tmp_share.lgtm_tblhnd_share->auto_increment_value =
11308 info->auto_increment_value;
11309 DBUG_PRINT("info",("spider auto_increment_value=%llu",
11310 tmp_share.lgtm_tblhnd_share->auto_increment_value));
11311 pthread_mutex_unlock(&tmp_share.lgtm_tblhnd_share->auto_increment_mutex);
11312 }
11313
11314 if (tmp_share.static_key_cardinality)
11315 spider_free(spider_current_trx, tmp_share.static_key_cardinality, MYF(0));
11316 spider_free_share_alloc(&tmp_share);
11317 DBUG_RETURN(0);
11318
11319error:
11320 if (table_tables)
11321 spider_close_sys_table(current_thd, table_tables,
11322 &open_tables_backup, need_lock);
11323 if (tmp_share.lgtm_tblhnd_share)
11324 spider_free_lgtm_tblhnd_share_alloc(tmp_share.lgtm_tblhnd_share, FALSE);
11325 if (tmp_share.static_key_cardinality)
11326 spider_free(spider_current_trx, tmp_share.static_key_cardinality, MYF(0));
11327 spider_free_share_alloc(&tmp_share);
11328error_alter_before_unlock:
11329error_get_trx:
11330 DBUG_RETURN(error_num);
11331}
11332
11333void ha_spider::update_create_info(
11334 HA_CREATE_INFO* create_info
11335) {
11336 DBUG_ENTER("ha_spider::update_create_info");
11337 DBUG_PRINT("info",("spider this=%p", this));
11338 if (!create_info->connect_string.str)
11339 {
11340 create_info->connect_string.str = table->s->connect_string.str;
11341 create_info->connect_string.length = table->s->connect_string.length;
11342 }
11343 DBUG_PRINT("info",
11344 ("spider create_info->connect_string=%s",
11345 create_info->connect_string.str));
11346 if (
11347 !(create_info->used_fields & HA_CREATE_USED_AUTO)
11348 ) {
11349 info(HA_STATUS_AUTO);
11350 create_info->auto_increment_value = stats.auto_increment_value;
11351 }
11352 DBUG_VOID_RETURN;
11353}
11354
11355int ha_spider::rename_table(
11356 const char *from,
11357 const char *to
11358) {
11359 int error_num, roop_count, old_link_count, from_len = strlen(from),
11360 to_len = strlen(to), tmp_error_num;
11361#ifdef SPIDER_HAS_HASH_VALUE_TYPE
11362 my_hash_value_type from_hash_value = my_calc_hash(&spider_open_tables,
11363 (uchar*) from, from_len);
11364 my_hash_value_type to_hash_value = my_calc_hash(&spider_open_tables,
11365 (uchar*) to, to_len);
11366#endif
11367 THD *thd = ha_thd();
11368 uint sql_command = thd_sql_command(thd);
11369 SPIDER_TRX *trx;
11370 TABLE *table_tables = NULL;
11371 SPIDER_ALTER_TABLE *alter_table_from, *alter_table_to;
11372 SPIDER_LGTM_TBLHND_SHARE *from_lgtm_tblhnd_share, *to_lgtm_tblhnd_share;
11373#if MYSQL_VERSION_ID < 50500
11374 Open_tables_state open_tables_backup;
11375#else
11376 Open_tables_backup open_tables_backup;
11377#endif
11378 bool need_lock = FALSE;
11379 DBUG_ENTER("ha_spider::rename_table");
11380 DBUG_PRINT("info",("spider this=%p", this));
11381 DBUG_PRINT("info",("spider from=%s", from));
11382 DBUG_PRINT("info",("spider to=%s", to));
11383 if (
11384 sql_command == SQLCOM_CREATE_INDEX ||
11385 sql_command == SQLCOM_DROP_INDEX
11386 )
11387 DBUG_RETURN(0);
11388 if (!(trx = spider_get_trx(thd, TRUE, &error_num)))
11389 goto error;
11390 if (
11391 trx->locked_connections &&
11392 /* SQLCOM_RENAME_TABLE doesn't come here */
11393 sql_command == SQLCOM_ALTER_TABLE
11394 ) {
11395 my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM,
11396 ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0));
11397 error_num = ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM;
11398 goto error;
11399 }
11400 if (
11401 sql_command == SQLCOM_RENAME_TABLE ||
11402 (sql_command == SQLCOM_ALTER_TABLE && !trx->tmp_flg) ||
11403 !(alter_table_from =
11404 (SPIDER_ALTER_TABLE*) my_hash_search(&trx->trx_alter_table_hash,
11405 (uchar*) from, from_len))
11406 ) {
11407 if (
11408 !(table_tables = spider_open_sys_table(
11409 current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
11410 SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE,
11411 &error_num))
11412 ) {
11413 goto error;
11414 }
11415 if (
11416 (error_num = spider_update_tables_name(
11417 table_tables, from, to, &old_link_count))
11418 ) {
11419 goto error;
11420 }
11421 spider_close_sys_table(current_thd, table_tables,
11422 &open_tables_backup, FALSE);
11423 table_tables = NULL;
11424
11425 /* release table mon list */
11426 for (roop_count = 0; roop_count < old_link_count; roop_count++)
11427 {
11428 if ((error_num =
11429 spider_release_ping_table_mon_list(from, from_len, roop_count)))
11430 {
11431 goto error;
11432 }
11433 }
11434 } else if (sql_command == SQLCOM_ALTER_TABLE)
11435 {
11436 DBUG_PRINT("info",("spider alter_table_from=%p", alter_table_from));
11437 if ((alter_table_to =
11438 (SPIDER_ALTER_TABLE*) my_hash_search(&trx->trx_alter_table_hash,
11439 (uchar*) to, to_len))
11440 ) {
11441 DBUG_PRINT("info",("spider copy link_statuses"));
11442 uint all_link_count = alter_table_from->all_link_count;
11443 if (all_link_count > alter_table_to->all_link_count)
11444 all_link_count = alter_table_to->all_link_count;
11445 for (roop_count = 0; roop_count < (int) all_link_count; roop_count++)
11446 {
11447 if (alter_table_from->tmp_link_statuses[roop_count] <=
11448 SPIDER_LINK_STATUS_NO_CHANGE)
11449 {
11450 DBUG_PRINT("info",("spider copy %d", roop_count));
11451 alter_table_from->tmp_link_statuses[roop_count] =
11452 alter_table_to->tmp_link_statuses[roop_count];
11453 }
11454 DBUG_PRINT("info",("spider link_status_from[%d]=%ld", roop_count,
11455 alter_table_from->tmp_link_statuses[roop_count]));
11456 DBUG_PRINT("info",("spider link_status_to[%d]=%ld", roop_count,
11457 alter_table_to->tmp_link_statuses[roop_count]));
11458 }
11459 }
11460
11461 DBUG_PRINT("info",
11462 ("spider alter_info.flags: %llu alter_info.partition_flags: %lu",
11463 thd->lex->alter_info.flags, thd->lex->alter_info.partition_flags));
11464 if (
11465 (thd->lex->alter_info.partition_flags &
11466 (
11467 SPIDER_ALTER_PARTITION_ADD | SPIDER_ALTER_PARTITION_DROP |
11468 SPIDER_ALTER_PARTITION_COALESCE | SPIDER_ALTER_PARTITION_REORGANIZE |
11469 SPIDER_ALTER_PARTITION_TABLE_REORG | SPIDER_ALTER_PARTITION_REBUILD
11470 )
11471 )
11472 )
11473 need_lock = TRUE;
11474
11475 if (
11476 !(table_tables = spider_open_sys_table(
11477 current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
11478 SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, need_lock,
11479 &error_num))
11480 ) {
11481 goto error;
11482 }
11483
11484 if (alter_table_from->now_create)
11485 {
11486 SPIDER_SHARE tmp_share;
11487 tmp_share.table_name = (char*) to;
11488 tmp_share.table_name_length = to_len;
11489 tmp_share.priority = alter_table_from->tmp_priority;
11490 tmp_share.link_count = alter_table_from->link_count;
11491 tmp_share.all_link_count = alter_table_from->all_link_count;
11492 memcpy(&tmp_share.alter_table, alter_table_from,
11493 sizeof(*alter_table_from));
11494 if (
11495 (error_num = spider_insert_tables(table_tables, &tmp_share))
11496 ) {
11497 goto error;
11498 }
11499 } else {
11500 if (
11501 (error_num = spider_update_tables_priority(
11502 table_tables, alter_table_from, to, &old_link_count))
11503 ) {
11504 goto error;
11505 }
11506 }
11507 spider_close_sys_table(current_thd, table_tables,
11508 &open_tables_backup, need_lock);
11509 table_tables = NULL;
11510
11511 if (!alter_table_from->now_create)
11512 {
11513 /* release table mon list */
11514 for (roop_count = 0; roop_count < (int) alter_table_from->all_link_count;
11515 roop_count++)
11516 {
11517 if ((error_num =
11518 spider_release_ping_table_mon_list(from, from_len, roop_count)))
11519 {
11520 goto error;
11521 }
11522 }
11523 for (roop_count = 0; roop_count < old_link_count; roop_count++)
11524 {
11525 if ((error_num =
11526 spider_release_ping_table_mon_list(to, to_len, roop_count)))
11527 {
11528 goto error;
11529 }
11530 }
11531 }
11532/*
11533 spider_free_trx_alter_table_alloc(trx, alter_table_from);
11534*/
11535 }
11536
11537 pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
11538#ifdef SPIDER_HAS_HASH_VALUE_TYPE
11539 from_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
11540 from, from_len, from_hash_value, TRUE, FALSE, &error_num);
11541#else
11542 from_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
11543 from, from_len, TRUE, FALSE, &error_num);
11544#endif
11545 if (from_lgtm_tblhnd_share)
11546 {
11547#ifdef SPIDER_HAS_HASH_VALUE_TYPE
11548 to_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
11549 to, to_len, to_hash_value, TRUE, TRUE, &error_num);
11550#else
11551 to_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
11552 to, to_len, TRUE, TRUE, &error_num);
11553#endif
11554 if (!to_lgtm_tblhnd_share)
11555 {
11556 pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
11557 goto error;
11558 }
11559 DBUG_PRINT("info",
11560 ("spider auto_increment_init=%s",
11561 from_lgtm_tblhnd_share->auto_increment_init ? "TRUE" : "FALSE"));
11562 to_lgtm_tblhnd_share->auto_increment_init =
11563 from_lgtm_tblhnd_share->auto_increment_init;
11564 to_lgtm_tblhnd_share->auto_increment_lclval =
11565 from_lgtm_tblhnd_share->auto_increment_lclval;
11566 to_lgtm_tblhnd_share->auto_increment_value =
11567 from_lgtm_tblhnd_share->auto_increment_value;
11568 spider_free_lgtm_tblhnd_share_alloc(from_lgtm_tblhnd_share, TRUE);
11569 }
11570 pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
11571 spider_delete_init_error_table(from);
11572 DBUG_RETURN(0);
11573
11574error:
11575 if (table_tables)
11576 spider_close_sys_table(current_thd, table_tables,
11577 &open_tables_backup, need_lock);
11578 pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
11579#ifdef SPIDER_HAS_HASH_VALUE_TYPE
11580 to_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
11581 to, to_len, to_hash_value, TRUE, FALSE, &tmp_error_num);
11582#else
11583 to_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
11584 to, to_len, TRUE, FALSE, &tmp_error_num);
11585#endif
11586 if (to_lgtm_tblhnd_share)
11587 spider_free_lgtm_tblhnd_share_alloc(to_lgtm_tblhnd_share, TRUE);
11588 pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
11589 DBUG_RETURN(error_num);
11590}
11591
11592int ha_spider::delete_table(
11593 const char *name
11594) {
11595 int error_num;
11596 THD *thd = ha_thd();
11597 SPIDER_TRX *trx;
11598 TABLE *table_tables = NULL;
11599 uint sql_command = thd_sql_command(thd);
11600 SPIDER_ALTER_TABLE *alter_table;
11601#if MYSQL_VERSION_ID < 50500
11602 Open_tables_state open_tables_backup;
11603#else
11604 Open_tables_backup open_tables_backup;
11605#endif
11606 bool need_lock = FALSE;
11607 DBUG_ENTER("ha_spider::delete_table");
11608 DBUG_PRINT("info",("spider this=%p", this));
11609 DBUG_PRINT("info",("spider name=%s", name));
11610 if (
11611 sql_command == SQLCOM_CREATE_INDEX ||
11612 sql_command == SQLCOM_DROP_INDEX
11613 )
11614 DBUG_RETURN(0);
11615 if (!(trx = spider_get_trx(thd, TRUE, &error_num)))
11616 goto error;
11617 if (
11618 trx->locked_connections &&
11619 /* SQLCOM_DROP_DB doesn't come here */
11620 (
11621 sql_command == SQLCOM_DROP_TABLE ||
11622 sql_command == SQLCOM_ALTER_TABLE
11623 )
11624 ) {
11625 my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM,
11626 ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0));
11627 error_num = ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM;
11628 goto error;
11629 }
11630 if (sql_command == SQLCOM_DROP_TABLE ||
11631 sql_command == SQLCOM_DROP_DB ||
11632 sql_command == SQLCOM_ALTER_TABLE ||
11633 sql_command == SQLCOM_CREATE_TABLE)
11634 {
11635 SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share;
11636 int roop_count, old_link_count = 0, name_len = strlen(name);
11637#ifdef SPIDER_HAS_HASH_VALUE_TYPE
11638 my_hash_value_type hash_value = my_calc_hash(&spider_open_tables,
11639 (uchar*) name, name_len);
11640#endif
11641 if (
11642 sql_command == SQLCOM_ALTER_TABLE &&
11643#ifdef SPIDER_HAS_HASH_VALUE_TYPE
11644 (alter_table =
11645 (SPIDER_ALTER_TABLE*) my_hash_search_using_hash_value(
11646 &trx->trx_alter_table_hash,
11647 hash_value, (uchar*) name, name_len)) &&
11648#else
11649 (alter_table =
11650 (SPIDER_ALTER_TABLE*) my_hash_search(&trx->trx_alter_table_hash,
11651 (uchar*) name, name_len)) &&
11652#endif
11653 alter_table->now_create
11654 )
11655 DBUG_RETURN(0);
11656
11657 DBUG_PRINT("info",
11658 ("spider alter_info.flags: %llu alter_info.partition_flags: %lu",
11659 thd->lex->alter_info.flags, thd->lex->alter_info.partition_flags));
11660 if (
11661 sql_command == SQLCOM_ALTER_TABLE &&
11662 (thd->lex->alter_info.partition_flags &
11663 (
11664 SPIDER_ALTER_PARTITION_ADD | SPIDER_ALTER_PARTITION_DROP |
11665 SPIDER_ALTER_PARTITION_COALESCE | SPIDER_ALTER_PARTITION_REORGANIZE |
11666 SPIDER_ALTER_PARTITION_TABLE_REORG | SPIDER_ALTER_PARTITION_REBUILD
11667 )
11668 )
11669 )
11670 need_lock = TRUE;
11671
11672 if ((error_num = spider_sys_delete_table_sts(
11673 current_thd, name, name_len, need_lock)))
11674 goto error;
11675 if ((error_num = spider_sys_delete_table_crd(
11676 current_thd, name, name_len, need_lock)))
11677 goto error;
11678 if (
11679 !(table_tables = spider_open_sys_table(
11680 current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
11681 SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, need_lock,
11682 &error_num))
11683 ) {
11684 goto error;
11685 }
11686 if (
11687 (error_num = spider_delete_tables(
11688 table_tables, name, &old_link_count))
11689 ) {
11690 goto error;
11691 }
11692 spider_close_sys_table(current_thd, table_tables,
11693 &open_tables_backup, need_lock);
11694 table_tables = NULL;
11695
11696 /* release table mon list */
11697 for (roop_count = 0; roop_count < old_link_count; roop_count++)
11698 {
11699 if ((error_num =
11700 spider_release_ping_table_mon_list(name, name_len, roop_count)))
11701 goto error;
11702 }
11703
11704 pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
11705#ifdef SPIDER_HAS_HASH_VALUE_TYPE
11706 lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
11707 name, name_len, hash_value, TRUE, FALSE, &error_num);
11708#else
11709 lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
11710 name, name_len, TRUE, FALSE, &error_num);
11711#endif
11712 if (lgtm_tblhnd_share)
11713 spider_free_lgtm_tblhnd_share_alloc(lgtm_tblhnd_share, TRUE);
11714 pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
11715 }
11716
11717 spider_delete_init_error_table(name);
11718 DBUG_RETURN(0);
11719
11720error:
11721 if (table_tables)
11722 spider_close_sys_table(current_thd, table_tables,
11723 &open_tables_backup, need_lock);
11724 DBUG_RETURN(error_num);
11725}
11726
11727bool ha_spider::is_crashed() const
11728{
11729 DBUG_ENTER("ha_spider::is_crashed");
11730 DBUG_PRINT("info",("spider this=%p", this));
11731 DBUG_RETURN(FALSE);
11732}
11733
11734#ifdef SPIDER_HANDLER_AUTO_REPAIR_HAS_ERROR
11735bool ha_spider::auto_repair(int error) const
11736#else
11737bool ha_spider::auto_repair() const
11738#endif
11739{
11740 DBUG_ENTER("ha_spider::auto_repair");
11741 DBUG_PRINT("info",("spider this=%p", this));
11742 DBUG_RETURN(FALSE);
11743}
11744
11745int ha_spider::disable_indexes(
11746 uint mode
11747) {
11748 int error_num;
11749 backup_error_status();
11750 DBUG_ENTER("ha_spider::disable_indexes");
11751 DBUG_PRINT("info",("spider this=%p", this));
11752 if ((error_num = spider_db_disable_keys(this)))
11753 DBUG_RETURN(check_error_mode(error_num));
11754 DBUG_RETURN(0);
11755}
11756
11757int ha_spider::enable_indexes(
11758 uint mode
11759) {
11760 int error_num;
11761 backup_error_status();
11762 DBUG_ENTER("ha_spider::enable_indexes");
11763 DBUG_PRINT("info",("spider this=%p", this));
11764 if ((error_num = spider_db_enable_keys(this)))
11765 DBUG_RETURN(check_error_mode(error_num));
11766 DBUG_RETURN(0);
11767}
11768
11769
11770int ha_spider::check(
11771 THD* thd,
11772 HA_CHECK_OPT* check_opt
11773) {
11774 int error_num;
11775 backup_error_status();
11776 DBUG_ENTER("ha_spider::check");
11777 DBUG_PRINT("info",("spider this=%p", this));
11778 if ((error_num = spider_db_check_table(this, check_opt)))
11779 DBUG_RETURN(check_error_mode(error_num));
11780 DBUG_RETURN(0);
11781}
11782
11783int ha_spider::repair(
11784 THD* thd,
11785 HA_CHECK_OPT* check_opt
11786) {
11787 int error_num;
11788 backup_error_status();
11789 DBUG_ENTER("ha_spider::repair");
11790 DBUG_PRINT("info",("spider this=%p", this));
11791 if ((error_num = spider_db_repair_table(this, check_opt)))
11792 DBUG_RETURN(check_error_mode(error_num));
11793 DBUG_RETURN(0);
11794}
11795
11796bool ha_spider::check_and_repair(
11797 THD *thd
11798) {
11799 HA_CHECK_OPT check_opt;
11800 DBUG_ENTER("ha_spider::check_and_repair");
11801 DBUG_PRINT("info",("spider this=%p", this));
11802 check_opt.init();
11803 check_opt.flags = T_MEDIUM;
11804 if (spider_db_check_table(this, &check_opt))
11805 {
11806 check_opt.flags = T_QUICK;
11807 if (spider_db_repair_table(this, &check_opt))
11808 DBUG_RETURN(TRUE);
11809 }
11810 DBUG_RETURN(FALSE);
11811}
11812
11813int ha_spider::analyze(
11814 THD* thd,
11815 HA_CHECK_OPT* check_opt
11816) {
11817 int error_num;
11818 backup_error_status();
11819 DBUG_ENTER("ha_spider::analyze");
11820 DBUG_PRINT("info",("spider this=%p", this));
11821 if ((error_num = spider_db_analyze_table(this)))
11822 DBUG_RETURN(check_error_mode(error_num));
11823 DBUG_RETURN(0);
11824}
11825
11826int ha_spider::optimize(
11827 THD* thd,
11828 HA_CHECK_OPT* check_opt
11829) {
11830 int error_num;
11831 backup_error_status();
11832 DBUG_ENTER("ha_spider::optimize");
11833 DBUG_PRINT("info",("spider this=%p", this));
11834 if ((error_num = spider_db_optimize_table(this)))
11835 DBUG_RETURN(check_error_mode(error_num));
11836 DBUG_RETURN(0);
11837}
11838
11839bool ha_spider::is_fatal_error(
11840 int error_num,
11841 uint flags
11842) {
11843 DBUG_ENTER("ha_spider::is_fatal_error");
11844 DBUG_PRINT("info",("spider error_num=%d", error_num));
11845 DBUG_PRINT("info",("spider flags=%u", flags));
11846 if (
11847 !handler::is_fatal_error(error_num, flags)
11848 ) {
11849 DBUG_PRINT("info",("spider FALSE"));
11850 DBUG_RETURN(FALSE);
11851 }
11852 DBUG_PRINT("info",("spider TRUE"));
11853 DBUG_RETURN(TRUE);
11854}
11855
11856Field *ha_spider::get_top_table_field(
11857 uint16 field_index
11858) {
11859 Field *field;
11860 DBUG_ENTER("ha_spider::get_top_table_field");
11861#ifdef HA_CAN_BULK_ACCESS
11862 if (is_bulk_access_clone)
11863 {
11864 DBUG_RETURN(pt_clone_source_handler->get_top_table_field(field_index));
11865 }
11866#endif
11867 DBUG_PRINT("info",("spider field_index=%u", field_index));
11868#ifdef HANDLER_HAS_TOP_TABLE_FIELDS
11869 if (set_top_table_fields)
11870 {
11871 field = top_table->field[field_index];
11872 } else {
11873#endif
11874 field = table->field[field_index];
11875#ifdef HANDLER_HAS_TOP_TABLE_FIELDS
11876 }
11877#endif
11878 DBUG_PRINT("info",("spider out field=%p", field));
11879 DBUG_RETURN(field);
11880}
11881
11882Field *ha_spider::field_exchange(
11883 Field *field
11884) {
11885 DBUG_ENTER("ha_spider::field_exchange");
11886#ifdef HA_CAN_BULK_ACCESS
11887 if (is_bulk_access_clone)
11888 {
11889 DBUG_RETURN(pt_clone_source_handler->field_exchange(field));
11890 }
11891#endif
11892 DBUG_PRINT("info",("spider in field=%p", field));
11893 DBUG_PRINT("info",("spider in field->table=%p", field->table));
11894#ifdef HANDLER_HAS_TOP_TABLE_FIELDS
11895 if (set_top_table_fields)
11896 {
11897 DBUG_PRINT("info",("spider top_table=%p", top_table));
11898 if (field->table != top_table)
11899 DBUG_RETURN(NULL);
11900 if (!(field = top_table_field[field->field_index]))
11901 DBUG_RETURN(NULL);
11902 } else {
11903#endif
11904 DBUG_PRINT("info",("spider table=%p", table));
11905 if (field->table != table)
11906 DBUG_RETURN(NULL);
11907#ifdef HANDLER_HAS_TOP_TABLE_FIELDS
11908 }
11909#endif
11910 DBUG_PRINT("info",("spider out field=%p", field));
11911 DBUG_RETURN(field);
11912}
11913
11914const COND *ha_spider::cond_push(
11915 const COND *cond
11916) {
11917 DBUG_ENTER("ha_spider::cond_push");
11918 cond_check = FALSE;
11919 if (cond)
11920 {
11921 SPIDER_CONDITION *tmp_cond;
11922 if (!(tmp_cond = (SPIDER_CONDITION *)
11923 spider_malloc(spider_current_trx, 3, sizeof(*tmp_cond), MYF(MY_WME)))
11924 )
11925 DBUG_RETURN(cond);
11926 tmp_cond->cond = (COND *) cond;
11927 tmp_cond->next = condition;
11928 condition = tmp_cond;
11929 }
11930 DBUG_RETURN(NULL);
11931}
11932
11933void ha_spider::cond_pop()
11934{
11935 DBUG_ENTER("ha_spider::cond_pop");
11936 if (condition)
11937 {
11938 SPIDER_CONDITION *tmp_cond = condition->next;
11939 spider_free(spider_current_trx, condition, MYF(0));
11940 condition = tmp_cond;
11941 }
11942 DBUG_VOID_RETURN;
11943}
11944
11945int ha_spider::info_push(
11946 uint info_type,
11947 void *info
11948) {
11949 int error_num = 0;
11950 DBUG_ENTER("ha_spider::info_push");
11951 DBUG_PRINT("info",("spider this=%p", this));
11952#ifdef HA_CAN_BULK_ACCESS
11953 if (
11954#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
11955#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
11956 info_type != INFO_KIND_HS_RET_FIELDS &&
11957#endif
11958#endif
11959 info_type != INFO_KIND_BULK_ACCESS_BEGIN &&
11960 info_type != INFO_KIND_BULK_ACCESS_CURRENT &&
11961 info_type != INFO_KIND_BULK_ACCESS_END
11962 ) {
11963 if (!is_bulk_access_clone)
11964 {
11965 if (
11966 bulk_access_executing &&
11967 bulk_access_link_exec_tgt->called
11968 ) {
11969 DBUG_RETURN(bulk_access_link_exec_tgt->spider->info_push(info_type,
11970 info));
11971 } else if (bulk_access_started)
11972 {
11973 DBUG_RETURN(bulk_access_link_current->spider->info_push(info_type,
11974 info));
11975 }
11976 }
11977 }
11978#endif
11979
11980#if defined(HANDLER_HAS_DIRECT_UPDATE_ROWS) || defined(HA_CAN_BULK_ACCESS)
11981 switch (info_type)
11982 {
11983#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
11984#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
11985 case INFO_KIND_HS_RET_FIELDS:
11986 {
11987 DBUG_PRINT("info",("spider INFO_KIND_HS_RET_FIELDS"));
11988 size_t roop_count;
11989 Field *field;
11990 SPIDER_HS_UINT32_INFO *tmp_info = (SPIDER_HS_UINT32_INFO *) info;
11991 hs_pushed_ret_fields_num = tmp_info->info_size;
11992 if (hs_pushed_ret_fields_size < hs_pushed_ret_fields_num)
11993 {
11994 if (hs_pushed_ret_fields)
11995 spider_free(spider_current_trx, hs_pushed_ret_fields, MYF(0));
11996 if (!(hs_pushed_ret_fields = (uint32 *)
11997 spider_bulk_malloc(spider_current_trx, 17, MYF(MY_WME),
11998 &hs_pushed_ret_fields, sizeof(uint32) * hs_pushed_ret_fields_num,
11999 NullS))
12000 ) {
12001 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
12002 }
12003 hs_pushed_ret_fields_size = hs_pushed_ret_fields_num;
12004 }
12005 memcpy(hs_pushed_ret_fields, tmp_info->info,
12006 sizeof(uint32) * hs_pushed_ret_fields_num);
12007 bitmap_clear_all(table->read_set);
12008 bitmap_clear_all(table->write_set);
12009 hs_pushed_lcl_fields_num = 0;
12010 for (roop_count = 0; roop_count < hs_pushed_ret_fields_num; roop_count++)
12011 {
12012 field = get_top_table_field(hs_pushed_ret_fields[roop_count]);
12013 if ((field = field_exchange(field)))
12014 {
12015 if (!bitmap_is_set(table->read_set, field->field_index))
12016 {
12017 ++hs_pushed_lcl_fields_num;
12018 bitmap_set_bit(table->read_set, field->field_index);
12019 bitmap_set_bit(table->write_set, field->field_index);
12020 }
12021 }
12022 }
12023 }
12024 break;
12025 case INFO_KIND_HS_APPEND_STRING_REF:
12026 {
12027 DBUG_PRINT("info",("spider INFO_KIND_HS_APPEND_STRING_REF"));
12028#ifndef DBUG_OFF
12029 SPIDER_HS_STRING_REF *tmp_ref = (SPIDER_HS_STRING_REF*) info;
12030 char print_buf[MAX_FIELD_WIDTH];
12031 if (tmp_ref->size() < MAX_FIELD_WIDTH)
12032 {
12033 memcpy(print_buf, tmp_ref->begin(), tmp_ref->size());
12034 print_buf[tmp_ref->size()] = '\0';
12035 DBUG_PRINT("info",("spider info=%s", print_buf));
12036 }
12037#endif
12038 Field *field;
12039 if (hs_pushed_ret_fields)
12040 {
12041 field = get_top_table_field(
12042 hs_pushed_ret_fields[hs_pushed_strref_num]);
12043 } else {
12044 field = get_top_table_field(
12045 pt_clone_source_handler->hs_pushed_ret_fields[hs_pushed_strref_num]);
12046 }
12047 if (!field_exchange(field))
12048 {
12049 hs_pushed_strref_num++;
12050 break;
12051 }
12052 hs_pushed_strref_num++;
12053 if ((error_num = push_back_hs_upds(*((SPIDER_HS_STRING_REF*) info))))
12054 {
12055 DBUG_RETURN(error_num);
12056 }
12057 break;
12058 }
12059 case INFO_KIND_HS_CLEAR_STRING_REF:
12060 DBUG_PRINT("info",("spider INFO_KIND_HS_CLEAR_STRING_REF"));
12061 hs_pushed_strref_num = 0;
12062 if ((error_num = reset_hs_upds(SPIDER_SQL_TYPE_UPDATE_HS)))
12063 {
12064 DBUG_RETURN(error_num);
12065 }
12066 break;
12067 case INFO_KIND_HS_INCREMENT_BEGIN:
12068 DBUG_PRINT("info",("spider INFO_KIND_HS_INCREMENT_BEGIN"));
12069 hs_increment = TRUE;
12070 break;
12071 case INFO_KIND_HS_INCREMENT_END:
12072 DBUG_PRINT("info",("spider INFO_KIND_HS_INCREMENT_END"));
12073 hs_increment = FALSE;
12074 break;
12075 case INFO_KIND_HS_DECREMENT_BEGIN:
12076 DBUG_PRINT("info",("spider INFO_KIND_HS_DECREMENT_BEGIN"));
12077 hs_decrement = TRUE;
12078 break;
12079 case INFO_KIND_HS_DECREMENT_END:
12080 DBUG_PRINT("info",("spider INFO_KIND_HS_DECREMENT_END"));
12081 hs_decrement = FALSE;
12082 break;
12083#endif
12084#ifdef INFO_KIND_UPDATE_FIELDS
12085 case INFO_KIND_UPDATE_FIELDS:
12086 DBUG_PRINT("info",("spider INFO_KIND_UPDATE_FIELDS"));
12087 direct_update_fields = (List<Item> *) info;
12088 update_request = TRUE;
12089#ifdef WITH_PARTITION_STORAGE_ENGINE
12090 if (keyread && check_partitioned())
12091 keyread = FALSE;
12092#endif
12093 break;
12094#endif
12095#ifdef INFO_KIND_UPDATE_VALUES
12096 case INFO_KIND_UPDATE_VALUES:
12097 DBUG_PRINT("info",("spider INFO_KIND_UPDATE_VALUES"));
12098 direct_update_values = (List<Item> *) info;
12099 break;
12100#endif
12101#ifdef INFO_KIND_FORCE_LIMIT_BEGIN
12102 case INFO_KIND_FORCE_LIMIT_BEGIN:
12103 DBUG_PRINT("info",("spider INFO_KIND_FORCE_LIMIT_BEGIN"));
12104 info_limit = *((longlong *) info);
12105/*
12106 trx->direct_aggregate_count++;
12107*/
12108 break;
12109 case INFO_KIND_FORCE_LIMIT_END:
12110 DBUG_PRINT("info",("spider INFO_KIND_FORCE_LIMIT_END"));
12111 info_limit = 9223372036854775807LL;
12112 break;
12113#endif
12114#endif
12115#ifdef HA_CAN_BULK_ACCESS
12116 case INFO_KIND_BULK_ACCESS_BEGIN:
12117 DBUG_PRINT("info",("spider INFO_KIND_BULK_ACCESS_BEGIN"));
12118 if (bulk_access_started)
12119 {
12120 if (!bulk_access_link_current->next)
12121 {
12122 if (!(bulk_access_link_current->next = create_bulk_access_link()))
12123 {
12124 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
12125 }
12126 bulk_access_link_current->next->sequence_num =
12127 bulk_access_link_current->sequence_num + 1;
12128 }
12129 bulk_access_link_current = bulk_access_link_current->next;
12130 } else {
12131 if (!bulk_access_link_first)
12132 {
12133 if (!(bulk_access_link_first = create_bulk_access_link()))
12134 {
12135 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
12136 }
12137 bulk_access_link_first->sequence_num = 0;
12138 }
12139 bulk_access_link_current = bulk_access_link_first;
12140 bulk_access_started = TRUE;
12141 bulk_access_executing = FALSE;
12142 }
12143 if (
12144 (error_num = bulk_access_link_current->spider->
12145 sync_from_clone_source(this)) ||
12146 (error_num = bulk_access_link_current->spider->
12147 check_access_kind(trx->thd, (lock_type >= TL_WRITE_ALLOW_WRITE)))
12148 ) {
12149 DBUG_RETURN(error_num);
12150 }
12151#ifdef HA_CAN_BULK_ACCESS
12152#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
12153 memset(
12154 bulk_access_link_current->spider->result_list.hs_r_bulk_open_index, 0,
12155 share->link_bitmap_size);
12156 memset(
12157 bulk_access_link_current->spider->result_list.hs_w_bulk_open_index, 0,
12158 share->link_bitmap_size);
12159#endif
12160#endif
12161/*
12162#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
12163 if ((error_num = bulk_access_link_current->spider->reset_hs_strs_pos(
12164 SPIDER_SQL_TYPE_UPDATE_HS)))
12165 {
12166 DBUG_RETURN(error_num);
12167 }
12168#endif
12169*/
12170 bulk_access_link_current->spider->bulk_access_executing = FALSE;
12171 bulk_access_link_current->spider->bulk_access_pre_called = FALSE;
12172 bulk_access_link_current->used = TRUE;
12173 bulk_access_link_current->called = FALSE;
12174 *((void **) info) = bulk_access_link_current;
12175 break;
12176 case INFO_KIND_BULK_ACCESS_CURRENT:
12177 DBUG_PRINT("info",("spider INFO_KIND_BULK_ACCESS_CURRENT"));
12178 bulk_access_executing = TRUE;
12179 bulk_access_link_exec_tgt = (SPIDER_BULK_ACCESS_LINK *) info;
12180 if (bulk_access_link_exec_tgt->spider->pt_clone_source_handler != this)
12181 {
12182 DBUG_PRINT("info",("spider this=%p", this));
12183 DBUG_PRINT("info",("spider pt_clone_source_handler=%p",
12184 bulk_access_link_exec_tgt->spider->pt_clone_source_handler));
12185 /* partitioned */
12186 uint sequence_num = bulk_access_link_exec_tgt->sequence_num;
12187 for (
12188 bulk_access_link_exec_tgt = bulk_access_link_first;
12189 bulk_access_link_exec_tgt;
12190 bulk_access_link_exec_tgt = bulk_access_link_exec_tgt->next
12191 ) {
12192 if (bulk_access_link_exec_tgt->sequence_num >= sequence_num)
12193 {
12194 DBUG_ASSERT(
12195 bulk_access_link_exec_tgt->sequence_num == sequence_num);
12196 break;
12197 }
12198 }
12199 }
12200 bulk_access_link_exec_tgt->spider->bulk_access_executing = TRUE;
12201 break;
12202 case INFO_KIND_BULK_ACCESS_END:
12203 DBUG_PRINT("info",("spider INFO_KIND_BULK_ACCESS_END"));
12204 bulk_access_started = FALSE;
12205 break;
12206#endif
12207 default:
12208 break;
12209 }
12210#endif
12211 DBUG_RETURN(error_num);
12212}
12213
12214#ifdef HANDLER_HAS_DIRECT_AGGREGATE
12215void ha_spider::return_record_by_parent()
12216{
12217 DBUG_ENTER("ha_spider::return_record_by_parent");
12218 DBUG_PRINT("info",("spider this=%p", this));
12219 spider_db_refetch_for_item_sum_funcs(this);
12220 DBUG_VOID_RETURN;
12221}
12222#endif
12223
12224TABLE *ha_spider::get_table()
12225{
12226 DBUG_ENTER("ha_spider::get_table");
12227 DBUG_RETURN(table);
12228}
12229
12230TABLE *ha_spider::get_top_table()
12231{
12232 DBUG_ENTER("ha_spider::get_top_table");
12233#ifdef HANDLER_HAS_TOP_TABLE_FIELDS
12234 if (set_top_table_fields)
12235 DBUG_RETURN(top_table);
12236#endif
12237 DBUG_RETURN(table);
12238}
12239
12240void ha_spider::set_ft_discard_bitmap()
12241{
12242 DBUG_ENTER("ha_spider::set_ft_discard_bitmap");
12243 TABLE_LIST *table_list = spider_get_parent_table_list(this);
12244 if (table_list)
12245 {
12246 st_select_lex *select_lex = table_list->select_lex;
12247 if (select_lex && select_lex->ftfunc_list)
12248 {
12249 uint roop_count;
12250 Field *field;
12251 Item *item, *item_next;
12252 Item_func_match *item_func_match;
12253 Item_field *item_field;
12254 {
12255 List_iterator_fast<Item_func_match> fmi(*select_lex->ftfunc_list);
12256 while ((item_func_match = fmi++))
12257 {
12258 DBUG_PRINT("info",("spider item_func_match=%p", item_func_match));
12259 uint item_count = item_func_match->argument_count();
12260 Item **item_list = item_func_match->arguments();
12261 for (roop_count = 1; roop_count < item_count; roop_count++)
12262 {
12263 item_field = (Item_field *) item_list[roop_count];
12264 DBUG_PRINT("info",("spider item_field=%p", item_field));
12265 field = item_field->field;
12266 DBUG_PRINT("info",("spider field=%p", field));
12267 if (!field || !(field = field_exchange(field)))
12268 continue;
12269 DBUG_PRINT("info",("spider clear_bit=%u", field->field_index));
12270 spider_clear_bit(ft_discard_bitmap, field->field_index);
12271 }
12272 }
12273 }
12274 THD *thd = ha_thd();
12275 Statement *stmt = thd->stmt_map.find(thd->id);
12276 if (stmt && stmt->free_list)
12277 {
12278 DBUG_PRINT("info",("spider item from stmt"));
12279 item_next = stmt->free_list;
12280 } else {
12281 DBUG_PRINT("info",("spider item from thd"));
12282 item_next = thd->free_list;
12283 }
12284 while ((item = item_next))
12285 {
12286 DBUG_PRINT("info",("spider item=%p", item));
12287 DBUG_PRINT("info",("spider itemtype=%u", item->type()));
12288 item_next = item->next;
12289 if (item->type() != Item::FIELD_ITEM)
12290 continue;
12291 field = ((Item_field *) item)->field;
12292 DBUG_PRINT("info",("spider field=%p", field));
12293 if (!field || !(field = field_exchange(field)))
12294 continue;
12295 DBUG_PRINT("info",("spider field_index=%u", field->field_index));
12296 if (!spider_bit_is_set(ft_discard_bitmap, field->field_index))
12297 {
12298 bool match_flag = FALSE;
12299 List_iterator_fast<Item_func_match> fmi(*select_lex->ftfunc_list);
12300 while ((item_func_match = fmi++))
12301 {
12302 DBUG_PRINT("info",("spider item_func_match=%p", item_func_match));
12303 uint item_count = item_func_match->argument_count();
12304 Item **item_list = item_func_match->arguments();
12305 for (roop_count = 1; roop_count < item_count; roop_count++)
12306 {
12307 DBUG_PRINT("info",("spider item_list[%u]=%p", roop_count,
12308 item_list[roop_count]));
12309 if (item == item_list[roop_count])
12310 {
12311 DBUG_PRINT("info",("spider matched"));
12312 match_flag = TRUE;
12313 break;
12314 }
12315 }
12316 if (match_flag)
12317 break;
12318 }
12319 if (!match_flag)
12320 {
12321 DBUG_PRINT("info",("spider set_bit=%u", field->field_index));
12322 spider_set_bit(ft_discard_bitmap, field->field_index);
12323 }
12324 }
12325 }
12326 }
12327 }
12328 DBUG_VOID_RETURN;
12329}
12330
12331void ha_spider::set_searched_bitmap()
12332{
12333 int roop_count;
12334 DBUG_ENTER("ha_spider::set_searched_bitmap");
12335 for (roop_count = 0; roop_count < (int) ((table_share->fields + 7) / 8);
12336 roop_count++)
12337 {
12338 searched_bitmap[roop_count] =
12339 ((uchar *) table->read_set->bitmap)[roop_count] |
12340 ((uchar *) table->write_set->bitmap)[roop_count];
12341 DBUG_PRINT("info",("spider roop_count=%d", roop_count));
12342 DBUG_PRINT("info",("spider searched_bitmap=%d",
12343 searched_bitmap[roop_count]));
12344 DBUG_PRINT("info",("spider read_set=%d",
12345 ((uchar *) table->read_set->bitmap)[roop_count]));
12346 DBUG_PRINT("info",("spider write_set=%d",
12347 ((uchar *) table->write_set->bitmap)[roop_count]));
12348 }
12349 if (sql_command == SQLCOM_UPDATE || sql_command == SQLCOM_UPDATE_MULTI)
12350 {
12351 DBUG_PRINT("info",("spider update option start"));
12352 Item *item;
12353 st_select_lex *select_lex = spider_get_select_lex(this);
12354 List_iterator_fast<Item> fi(select_lex->item_list);
12355 while ((item = fi++))
12356 {
12357 if (item->type() == Item::FIELD_ITEM)
12358 {
12359 Field *field = ((Item_field *)item)->field;
12360 if (!(field = field_exchange(field)))
12361 {
12362 DBUG_PRINT("info",("spider field is for different table"));
12363 continue;
12364 }
12365 spider_set_bit(searched_bitmap, field->field_index);
12366 DBUG_PRINT("info",("spider set searched_bitmap=%u",
12367 field->field_index));
12368 } else {
12369 DBUG_PRINT("info",("spider item type is not field"));
12370 }
12371 }
12372 }
12373 DBUG_VOID_RETURN;
12374}
12375
12376void ha_spider::set_clone_searched_bitmap()
12377{
12378 DBUG_ENTER("ha_spider::set_clone_searched_bitmap");
12379 DBUG_PRINT("info",("spider searched_bitmap=%p", searched_bitmap));
12380#ifndef DBUG_OFF
12381 int roop_count;
12382 for (roop_count = 0; roop_count < (int) ((table_share->fields + 7) / 8);
12383 roop_count++)
12384 DBUG_PRINT("info", ("spider before searched_bitmap is %x",
12385 ((uchar *) searched_bitmap)[roop_count]));
12386#endif
12387 memcpy(searched_bitmap, pt_clone_source_handler->searched_bitmap,
12388 (table_share->fields + 7) / 8);
12389#ifndef DBUG_OFF
12390 for (roop_count = 0; roop_count < (int) ((table_share->fields + 7) / 8);
12391 roop_count++)
12392 DBUG_PRINT("info", ("spider after searched_bitmap is %x",
12393 ((uchar *) searched_bitmap)[roop_count]));
12394#endif
12395 memcpy(ft_discard_bitmap, pt_clone_source_handler->ft_discard_bitmap,
12396 (table_share->fields + 7) / 8);
12397 DBUG_VOID_RETURN;
12398}
12399
12400void ha_spider::set_searched_bitmap_from_item_list()
12401{
12402 DBUG_ENTER("ha_spider::set_searched_bitmap_from_item_list");
12403 Field *field;
12404 Item *item, *item_next;
12405 THD *thd = ha_thd();
12406 Statement *stmt = thd->stmt_map.find(thd->id);
12407 if (stmt && stmt->free_list)
12408 {
12409 DBUG_PRINT("info",("spider item from stmt"));
12410 item_next = stmt->free_list;
12411 } else {
12412 DBUG_PRINT("info",("spider item from thd"));
12413 item_next = thd->free_list;
12414 }
12415 while ((item = item_next))
12416 {
12417 DBUG_PRINT("info",("spider item=%p", item));
12418 DBUG_PRINT("info",("spider itemtype=%u", item->type()));
12419 item_next = item->next;
12420 if (item->type() != Item::FIELD_ITEM)
12421 continue;
12422 field = ((Item_field *) item)->field;
12423 DBUG_PRINT("info",("spider field=%p", field));
12424 if (!field || !(field = field_exchange(field)))
12425 continue;
12426 DBUG_PRINT("info",("spider field_index=%u", field->field_index));
12427 spider_set_bit(searched_bitmap, field->field_index);
12428 }
12429 DBUG_VOID_RETURN;
12430}
12431
12432void ha_spider::set_select_column_mode()
12433{
12434 int roop_count;
12435 KEY *key_info;
12436 KEY_PART_INFO *key_part;
12437 Field *field;
12438 THD *thd = trx->thd;
12439 DBUG_ENTER("ha_spider::set_select_column_mode");
12440 position_bitmap_init = FALSE;
12441#ifndef DBUG_OFF
12442 for (roop_count = 0; roop_count < (int) ((table_share->fields + 7) / 8);
12443 roop_count++)
12444 DBUG_PRINT("info", ("spider bitmap is %x",
12445 ((uchar *) table->read_set->bitmap)[roop_count]));
12446#endif
12447 select_column_mode = spider_param_select_column_mode(thd,
12448 share->select_column_mode);
12449 if (select_column_mode)
12450 {
12451 DBUG_PRINT("info",("spider searched_bitmap=%p", searched_bitmap));
12452#ifdef WITH_PARTITION_STORAGE_ENGINE
12453 if (
12454 partition_handler_share &&
12455 partition_handler_share->searched_bitmap
12456 ) {
12457 if (partition_handler_share->searched_bitmap != searched_bitmap)
12458 {
12459 memcpy(searched_bitmap, partition_handler_share->searched_bitmap,
12460 (table_share->fields + 7) / 8);
12461 memcpy(ft_discard_bitmap, partition_handler_share->ft_discard_bitmap,
12462 (table_share->fields + 7) / 8);
12463 }
12464 partition_handler_share->between_flg = FALSE;
12465 DBUG_PRINT("info",("spider copy searched_bitmap"));
12466 } else {
12467#endif
12468 set_searched_bitmap();
12469 set_searched_bitmap_from_item_list();
12470 if (result_list.lock_type == F_WRLCK && sql_command != SQLCOM_SELECT)
12471 {
12472#ifdef WITH_PARTITION_STORAGE_ENGINE
12473 uint part_num = 0;
12474 if (update_request)
12475 part_num = check_partitioned();
12476#endif
12477 if (
12478#ifdef WITH_PARTITION_STORAGE_ENGINE
12479 part_num ||
12480#endif
12481 table_share->primary_key == MAX_KEY
12482 ) {
12483 /* need all columns */
12484 for (roop_count = 0; roop_count < (int) table_share->fields;
12485 roop_count++)
12486 spider_set_bit(searched_bitmap, roop_count);
12487 } else {
12488 /* need primary key columns */
12489 key_info = &table_share->key_info[table_share->primary_key];
12490 key_part = key_info->key_part;
12491 for (roop_count = 0;
12492 roop_count < (int) spider_user_defined_key_parts(key_info);
12493 roop_count++)
12494 {
12495 field = key_part[roop_count].field;
12496 spider_set_bit(searched_bitmap, field->field_index);
12497 }
12498 }
12499#ifndef DBUG_OFF
12500 for (roop_count = 0;
12501 roop_count < (int) ((table_share->fields + 7) / 8);
12502 roop_count++)
12503 DBUG_PRINT("info", ("spider change bitmap is %x",
12504 searched_bitmap[roop_count]));
12505#endif
12506 }
12507#ifdef WITH_PARTITION_STORAGE_ENGINE
12508 if (partition_handler_share)
12509 {
12510 partition_handler_share->searched_bitmap = searched_bitmap;
12511 partition_handler_share->ft_discard_bitmap = ft_discard_bitmap;
12512 partition_handler_share->between_flg = TRUE;
12513 DBUG_PRINT("info",("spider set searched_bitmap"));
12514 }
12515 }
12516#endif
12517 }
12518 DBUG_VOID_RETURN;
12519}
12520
12521#ifdef WITH_PARTITION_STORAGE_ENGINE
12522void ha_spider::check_select_column(bool rnd)
12523{
12524 THD *thd = trx->thd;
12525 DBUG_ENTER("ha_spider::check_select_column");
12526 select_column_mode = spider_param_select_column_mode(thd,
12527 share->select_column_mode);
12528 if (select_column_mode && partition_handler_share)
12529 {
12530 if (!rnd)
12531 {
12532 if (partition_handler_share->between_flg)
12533 {
12534 memcpy(partition_handler_share->idx_read_bitmap,
12535 table->read_set->bitmap, (table_share->fields + 7) / 8);
12536 memcpy(partition_handler_share->idx_write_bitmap,
12537 table->write_set->bitmap, (table_share->fields + 7) / 8);
12538 partition_handler_share->between_flg = FALSE;
12539 partition_handler_share->idx_bitmap_is_set = TRUE;
12540 DBUG_PRINT("info",("spider set idx_bitmap"));
12541 } else if (partition_handler_share->idx_bitmap_is_set)
12542 {
12543 memcpy(table->read_set->bitmap,
12544 partition_handler_share->idx_read_bitmap,
12545 (table_share->fields + 7) / 8);
12546 memcpy(table->write_set->bitmap,
12547 partition_handler_share->idx_write_bitmap,
12548 (table_share->fields + 7) / 8);
12549 DBUG_PRINT("info",("spider copy idx_bitmap"));
12550 }
12551 } else {
12552 if (
12553 !partition_handler_share->rnd_bitmap_is_set &&
12554 (
12555 partition_handler_share->between_flg ||
12556 partition_handler_share->idx_bitmap_is_set
12557 )
12558 ) {
12559 memcpy(partition_handler_share->rnd_read_bitmap,
12560 table->read_set->bitmap, (table_share->fields + 7) / 8);
12561 memcpy(partition_handler_share->rnd_write_bitmap,
12562 table->write_set->bitmap, (table_share->fields + 7) / 8);
12563 partition_handler_share->between_flg = FALSE;
12564 partition_handler_share->rnd_bitmap_is_set = TRUE;
12565 DBUG_PRINT("info",("spider set rnd_bitmap"));
12566 } else if (partition_handler_share->rnd_bitmap_is_set)
12567 {
12568 memcpy(table->read_set->bitmap,
12569 partition_handler_share->rnd_read_bitmap,
12570 (table_share->fields + 7) / 8);
12571 memcpy(table->write_set->bitmap,
12572 partition_handler_share->rnd_write_bitmap,
12573 (table_share->fields + 7) / 8);
12574 DBUG_PRINT("info",("spider copy rnd_bitmap"));
12575 }
12576 }
12577 }
12578 DBUG_VOID_RETURN;
12579}
12580#endif
12581
12582bool ha_spider::check_and_start_bulk_update(
12583 spider_bulk_upd_start bulk_upd_start
12584) {
12585 DBUG_ENTER("ha_spider::check_and_start_bulk_update");
12586 DBUG_PRINT("info",("spider this=%p", this));
12587 DBUG_PRINT("info",("spider bulk_update_start=%d",
12588 result_list.bulk_update_start));
12589 if (
12590 result_list.bulk_update_start == SPD_BU_NOT_START ||
12591 (
12592 !result_list.bulk_update_mode &&
12593 bulk_upd_start == SPD_BU_START_BY_BULK_INIT
12594 )
12595 ) {
12596 THD *thd = ha_thd();
12597 int bulk_update_mode = spider_param_bulk_update_mode(thd,
12598 share->bulk_update_mode);
12599/*
12600 longlong split_read = spider_split_read_param(this);
12601*/
12602 result_list.bulk_update_size = spider_param_bulk_update_size(thd,
12603 share->bulk_update_size);
12604/*
12605#ifndef WITHOUT_SPIDER_BG_SEARCH
12606 int bgs_mode = spider_param_bgs_mode(thd, share->bgs_mode);
12607#endif
12608*/
12609 if (!support_bulk_update_sql())
12610 {
12611 result_list.bulk_update_mode = 0;
12612 DBUG_PRINT("info",("spider result_list.bulk_update_mode=%d 1",
12613 result_list.bulk_update_mode));
12614/*
12615 } else if (
12616#ifndef WITHOUT_SPIDER_BG_SEARCH
12617 bgs_mode ||
12618#endif
12619 split_read != 9223372036854775807LL
12620 ) {
12621 result_list.bulk_update_mode = 2;
12622 DBUG_PRINT("info",("spider result_list.bulk_update_mode=%d 2",
12623 result_list.bulk_update_mode));
12624*/
12625 } else {
12626 if (result_list.bulk_update_start == SPD_BU_NOT_START)
12627 {
12628 result_list.bulk_update_mode = bulk_update_mode;
12629 DBUG_PRINT("info",("spider result_list.bulk_update_mode=%d 3",
12630 result_list.bulk_update_mode));
12631 } else {
12632 result_list.bulk_update_mode = 1;
12633 DBUG_PRINT("info",("spider result_list.bulk_update_mode=%d 4",
12634 result_list.bulk_update_mode));
12635 }
12636 }
12637 result_list.bulk_update_start = bulk_upd_start;
12638 DBUG_RETURN(FALSE);
12639 }
12640 DBUG_RETURN(TRUE);
12641}
12642
12643int ha_spider::check_and_end_bulk_update(
12644 spider_bulk_upd_start bulk_upd_start
12645) {
12646 int error_num = 0;
12647 ha_rows dup_key_found = 0;
12648 DBUG_ENTER("ha_spider::check_and_end_bulk_update");
12649 DBUG_PRINT("info",("spider this=%p", this));
12650 DBUG_PRINT("info",("spider bulk_update_start=%d",
12651 result_list.bulk_update_start));
12652 DBUG_PRINT("info",("spider bulk_update_mode=%d",
12653 result_list.bulk_update_mode));
12654 if (result_list.bulk_update_start == bulk_upd_start)
12655 {
12656 if (result_list.bulk_update_mode)
12657 error_num = spider_db_bulk_update_end(this, &dup_key_found);
12658 result_list.bulk_update_size = 0;
12659 result_list.bulk_update_mode = 0;
12660 result_list.bulk_update_start = SPD_BU_NOT_START;
12661 }
12662 DBUG_RETURN(error_num);
12663}
12664
12665uint ha_spider::check_partitioned()
12666{
12667 uint part_num;
12668 DBUG_ENTER("ha_spider::check_partitioned");
12669 DBUG_PRINT("info",("spider this=%p", this));
12670 table->file->get_no_parts("", &part_num);
12671 if (part_num)
12672 DBUG_RETURN(part_num);
12673
12674 TABLE_LIST *tmp_table_list = table->pos_in_table_list;
12675 while ((tmp_table_list = tmp_table_list->parent_l))
12676 {
12677 tmp_table_list->table->file->get_no_parts("", &part_num);
12678 if (part_num)
12679 DBUG_RETURN(part_num);
12680 }
12681 DBUG_RETURN(0);
12682}
12683
12684void ha_spider::check_direct_order_limit()
12685{
12686 int roop_count;
12687 DBUG_ENTER("ha_spider::check_direct_order_limit");
12688 DBUG_PRINT("info",("spider this=%p", this));
12689 if (!result_list.check_direct_order_limit)
12690 {
12691 if (spider_check_direct_order_limit(this))
12692 {
12693 result_list.direct_order_limit = TRUE;
12694 sql_kinds = SPIDER_SQL_KIND_SQL;
12695 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
12696 sql_kind[roop_count] = SPIDER_SQL_KIND_SQL;
12697 } else
12698 result_list.direct_order_limit = FALSE;
12699
12700 spider_set_direct_limit_offset(this);
12701 result_list.check_direct_order_limit = TRUE;
12702 }
12703 DBUG_VOID_RETURN;
12704}
12705
12706/********************************************************************
12707 * Check whether the current query is a SELECT DISTINCT using an
12708 * index in a non-partitioned Spider configuration, with a
12709 * projection list that consists solely of the first key prefix
12710 * column.
12711 *
12712 * For a SELECT DISTINCT query using an index in a non-partitioned
12713 * Spider configuration, with a projection list that consists
12714 * solely of the first key prefix, set the internal row retrieval
12715 * limit to avoid visiting each row multiple times.
12716 ********************************************************************/
12717void ha_spider::check_distinct_key_query()
12718{
12719 DBUG_ENTER( "ha_spider::check_distinct_key_query" );
12720
12721 if ( result_list.direct_distinct && !partition_handler_share->handlers &&
12722 result_list.keyread && result_list.check_direct_order_limit )
12723 {
12724 // SELECT DISTINCT query using an index in a non-partitioned configuration
12725 KEY_PART_INFO* key_part = result_list.key_info->key_part;
12726 Field* key_field = key_part->field;
12727
12728 if ( is_sole_projection_field( key_field->field_index ) )
12729 {
12730 // Projection list consists solely of the first key prefix column
12731
12732 // Set the internal row retrieval limit to avoid visiting each row
12733 // multiple times. This fixes a Spider performance bug that
12734 // caused each row to be visited multiple times.
12735 result_list.internal_limit = 1;
12736 }
12737 }
12738
12739 DBUG_VOID_RETURN;
12740}
12741
12742/********************************************************************
12743 * Determine whether the current query's projection list
12744 * consists solely of the specified column.
12745 *
12746 * Params IN - field_index:
12747 * Field index of the column of interest within
12748 * its table.
12749 *
12750 * Returns TRUE - if the query's projection list consists
12751 * solely of the specified column.
12752 * FALSE - otherwise.
12753 ********************************************************************/
12754bool ha_spider::is_sole_projection_field(
12755 uint16 field_index
12756) {
12757 // NOTE: It is assumed that spider_db_append_select_columns() has already been called
12758 // to build the bitmap of projection fields
12759 bool is_ha_sole_projection_field;
12760 uint loop_index, dbton_id;
12761 spider_db_handler* dbton_hdl;
12762 DBUG_ENTER( "ha_spider::is_sole_projection_field" );
12763
12764 for ( loop_index = 0; loop_index < share->use_sql_dbton_count; loop_index++ )
12765 {
12766 dbton_id = share->use_sql_dbton_ids[ loop_index ];
12767 dbton_hdl = dbton_handler[ dbton_id ];
12768
12769 if ( dbton_hdl->first_link_idx >= 0 )
12770 {
12771 is_ha_sole_projection_field = dbton_hdl->is_sole_projection_field( field_index );
12772 if ( !is_ha_sole_projection_field )
12773 {
12774 DBUG_RETURN( FALSE );
12775 }
12776 }
12777 }
12778
12779 DBUG_RETURN( TRUE );
12780}
12781
12782int ha_spider::check_ha_range_eof()
12783{
12784 DBUG_ENTER("ha_spider::check_ha_range_eof");
12785 DBUG_PRINT("info",("spider this=%p", this));
12786 const key_range *end_key = result_list.end_key;
12787 DBUG_PRINT("info",("spider use_both_key=%s",
12788 result_list.use_both_key ? "TRUE" : "FALSE"));
12789 DBUG_PRINT("info",("spider sql_kind[%u]=%u",
12790 search_link_idx, sql_kind[search_link_idx]));
12791 DBUG_PRINT("info",("spider sql_command=%u", sql_command));
12792 if (
12793 result_list.use_both_key &&
12794 (sql_kind[search_link_idx] & SPIDER_SQL_KIND_HANDLER) &&
12795 sql_command != SQLCOM_HA_READ
12796 ) {
12797 int cmp_result = key_cmp(result_list.key_info->key_part,
12798 end_key->key, end_key->length);
12799 DBUG_PRINT("info",("spider cmp_result=%d", cmp_result));
12800 if (
12801 cmp_result > 0 ||
12802 (end_key->flag == HA_READ_BEFORE_KEY && !cmp_result)
12803 ) {
12804 table->status = STATUS_NOT_FOUND;
12805 DBUG_RETURN(HA_ERR_END_OF_FILE);
12806 }
12807 }
12808 DBUG_RETURN(0);
12809}
12810
12811int ha_spider::drop_tmp_tables()
12812{
12813 int error_num = 0, tmp_error_num, need_mon;
12814 DBUG_ENTER("ha_spider::drop_tmp_tables");
12815 DBUG_PRINT("info",("spider this=%p", this));
12816 if (result_list.tmp_tables_created)
12817 {
12818 int roop_start, roop_end, roop_count, tmp_lock_mode;
12819 tmp_lock_mode = spider_conn_lock_mode(this);
12820 if (tmp_lock_mode)
12821 {
12822 /* "for update" or "lock in share mode" */
12823 roop_start = spider_conn_link_idx_next(share->link_statuses,
12824 conn_link_idx, -1, share->link_count,
12825 SPIDER_LINK_STATUS_RECOVERY);
12826 roop_end = share->link_count;
12827 } else {
12828 roop_start = search_link_idx;
12829 roop_end = search_link_idx + 1;
12830 }
12831
12832 for (roop_count = roop_start; roop_count < roop_end;
12833 roop_count = spider_conn_link_idx_next(share->link_statuses,
12834 conn_link_idx, roop_count, share->link_count,
12835 SPIDER_LINK_STATUS_RECOVERY)
12836 ) {
12837 if (spider_bit_is_set(result_list.tmp_table_created, roop_count))
12838 {
12839 uint dbton_id = share->use_sql_dbton_ids[roop_count];
12840 spider_db_handler *dbton_hdl = dbton_handler[dbton_id];
12841 SPIDER_CONN *conn = conns[roop_count];
12842 if (dbton_hdl->need_lock_before_set_sql_for_exec(
12843 SPIDER_SQL_TYPE_TMP_SQL))
12844 {
12845 pthread_mutex_lock(&conn->mta_conn_mutex);
12846 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
12847 }
12848 if ((error_num = dbton_hdl->set_sql_for_exec(
12849 SPIDER_SQL_TYPE_TMP_SQL, roop_count)))
12850 {
12851 DBUG_RETURN(error_num);
12852 }
12853 if (!dbton_hdl->need_lock_before_set_sql_for_exec(
12854 SPIDER_SQL_TYPE_TMP_SQL))
12855 {
12856 pthread_mutex_lock(&conn->mta_conn_mutex);
12857 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
12858 }
12859 conn->need_mon = &need_mon;
12860 conn->mta_conn_mutex_lock_already = TRUE;
12861 conn->mta_conn_mutex_unlock_later = TRUE;
12862 if ((tmp_error_num = spider_db_set_names(this, conn, roop_count)))
12863 {
12864 conn->mta_conn_mutex_lock_already = FALSE;
12865 conn->mta_conn_mutex_unlock_later = FALSE;
12866 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
12867 pthread_mutex_unlock(&conn->mta_conn_mutex);
12868 if (
12869 share->monitoring_kind[roop_count] &&
12870 need_mons[roop_count]
12871 ) {
12872 tmp_error_num = spider_ping_table_mon_from_table(
12873 trx,
12874 trx->thd,
12875 share,
12876 roop_count,
12877 (uint32) share->monitoring_sid[roop_count],
12878 share->table_name,
12879 share->table_name_length,
12880 conn_link_idx[roop_count],
12881 NULL,
12882 0,
12883 share->monitoring_kind[roop_count],
12884 share->monitoring_limit[roop_count],
12885 share->monitoring_flag[roop_count],
12886 TRUE
12887 );
12888 }
12889 error_num = tmp_error_num;
12890 }
12891 if (!tmp_error_num)
12892 {
12893 spider_conn_set_timeout_from_share(conn, roop_count,
12894 trx->thd, share);
12895 if (dbton_hdl->execute_sql(
12896 SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL,
12897 conn,
12898 -1,
12899 &need_mons[roop_count])
12900 ) {
12901 conn->mta_conn_mutex_lock_already = FALSE;
12902 conn->mta_conn_mutex_unlock_later = FALSE;
12903 tmp_error_num = spider_db_errorno(conn);
12904 if (
12905 share->monitoring_kind[roop_count] &&
12906 need_mons[roop_count]
12907 ) {
12908 tmp_error_num = spider_ping_table_mon_from_table(
12909 trx,
12910 trx->thd,
12911 share,
12912 roop_count,
12913 (uint32) share->monitoring_sid[roop_count],
12914 share->table_name,
12915 share->table_name_length,
12916 conn_link_idx[roop_count],
12917 NULL,
12918 0,
12919 share->monitoring_kind[roop_count],
12920 share->monitoring_limit[roop_count],
12921 share->monitoring_flag[roop_count],
12922 TRUE
12923 );
12924 }
12925 error_num = tmp_error_num;
12926 } else {
12927 conn->mta_conn_mutex_lock_already = FALSE;
12928 conn->mta_conn_mutex_unlock_later = FALSE;
12929 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
12930 pthread_mutex_unlock(&conn->mta_conn_mutex);
12931 }
12932 }
12933 spider_clear_bit(result_list.tmp_table_created, roop_count);
12934 }
12935 }
12936 result_list.tmp_tables_created = FALSE;
12937 }
12938 DBUG_RETURN(error_num);
12939}
12940
12941bool ha_spider::handler_opened(
12942 int link_idx,
12943 uint tgt_conn_kind
12944) {
12945 DBUG_ENTER("ha_spider::handler_opened");
12946 DBUG_PRINT("info",("spider this=%p", this));
12947 DBUG_PRINT("info",("spider link_idx=%d", link_idx));
12948 DBUG_PRINT("info",("spider tgt_conn_kind=%u", tgt_conn_kind));
12949 if (
12950#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
12951 (
12952 tgt_conn_kind == SPIDER_CONN_KIND_MYSQL &&
12953#endif
12954 spider_bit_is_set(m_handler_opened, link_idx)
12955#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
12956 ) ||
12957 (
12958 tgt_conn_kind == SPIDER_CONN_KIND_HS_READ &&
12959 spider_bit_is_set(r_handler_opened, link_idx)
12960 ) ||
12961 (
12962 tgt_conn_kind == SPIDER_CONN_KIND_HS_WRITE &&
12963 spider_bit_is_set(w_handler_opened, link_idx)
12964 )
12965#endif
12966 ) {
12967 DBUG_PRINT("info",("spider TRUE"));
12968 DBUG_RETURN(TRUE);
12969 }
12970 DBUG_PRINT("info",("spider FALSE"));
12971 DBUG_RETURN(FALSE);
12972}
12973
12974void ha_spider::set_handler_opened(
12975 int link_idx
12976) {
12977 DBUG_ENTER("ha_spider::set_handler_opened");
12978 DBUG_PRINT("info",("spider this=%p", this));
12979#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
12980 if (conn_kind[link_idx] == SPIDER_CONN_KIND_MYSQL)
12981#endif
12982 spider_set_bit(m_handler_opened, link_idx);
12983#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
12984 else if (conn_kind[link_idx] == SPIDER_CONN_KIND_HS_READ)
12985 spider_set_bit(r_handler_opened, link_idx);
12986 else
12987 spider_set_bit(w_handler_opened, link_idx);
12988#endif
12989 DBUG_VOID_RETURN;
12990}
12991
12992void ha_spider::clear_handler_opened(
12993 int link_idx,
12994 uint tgt_conn_kind
12995) {
12996 DBUG_ENTER("ha_spider::clear_handler_opened");
12997 DBUG_PRINT("info",("spider this=%p", this));
12998#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
12999 if (tgt_conn_kind == SPIDER_CONN_KIND_MYSQL)
13000#endif
13001 spider_clear_bit(m_handler_opened, link_idx);
13002#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13003 else if (tgt_conn_kind == SPIDER_CONN_KIND_HS_READ)
13004 spider_clear_bit(r_handler_opened, link_idx);
13005 else
13006 spider_clear_bit(w_handler_opened, link_idx);
13007#endif
13008 DBUG_VOID_RETURN;
13009}
13010
13011int ha_spider::close_opened_handler(
13012 int link_idx,
13013 bool release_conn
13014) {
13015 int error_num = 0, error_num2;
13016 DBUG_ENTER("ha_spider::close_opened_handler");
13017 DBUG_PRINT("info",("spider this=%p", this));
13018
13019 if (spider_bit_is_set(m_handler_opened, link_idx))
13020 {
13021 if ((error_num2 = spider_db_close_handler(this,
13022 conns[link_idx], link_idx, SPIDER_CONN_KIND_MYSQL))
13023 ) {
13024 if (
13025 share->monitoring_kind[link_idx] &&
13026 need_mons[link_idx]
13027 ) {
13028 error_num2 = spider_ping_table_mon_from_table(
13029 trx,
13030 trx->thd,
13031 share,
13032 link_idx,
13033 (uint32) share->monitoring_sid[link_idx],
13034 share->table_name,
13035 share->table_name_length,
13036 conn_link_idx[link_idx],
13037 NULL,
13038 0,
13039 share->monitoring_kind[link_idx],
13040 share->monitoring_limit[link_idx],
13041 share->monitoring_flag[link_idx],
13042 TRUE
13043 );
13044 }
13045 error_num = error_num2;
13046 }
13047 spider_clear_bit(m_handler_opened, link_idx);
13048 if (release_conn)
13049 {
13050 spider_free_conn_from_trx(trx, conns[link_idx], FALSE, FALSE, NULL);
13051 conns[link_idx] = NULL;
13052 }
13053 }
13054#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13055 if (spider_bit_is_set(r_handler_opened, link_idx))
13056 {
13057 if ((error_num2 = spider_db_close_handler(this,
13058 hs_r_conns[link_idx], link_idx, SPIDER_CONN_KIND_HS_READ))
13059 ) {
13060 if (
13061 share->monitoring_kind[link_idx] &&
13062 need_mons[link_idx]
13063 ) {
13064 error_num2 = spider_ping_table_mon_from_table(
13065 trx,
13066 trx->thd,
13067 share,
13068 link_idx,
13069 (uint32) share->monitoring_sid[link_idx],
13070 share->table_name,
13071 share->table_name_length,
13072 conn_link_idx[link_idx],
13073 NULL,
13074 0,
13075 share->monitoring_kind[link_idx],
13076 share->monitoring_limit[link_idx],
13077 share->monitoring_flag[link_idx],
13078 TRUE
13079 );
13080 }
13081 error_num = error_num2;
13082 }
13083 spider_clear_bit(r_handler_opened, link_idx);
13084 if (release_conn)
13085 {
13086 if (
13087 !hs_r_conns[link_idx]->opened_handlers &&
13088 trx->trx_hs_r_conn_adjustment == trx_hs_r_conn_adjustment &&
13089 spider_param_hs_r_conn_recycle_mode(trx->thd) != 2
13090 ) {
13091 trx->trx_hs_r_conn_adjustment++;
13092 }
13093 spider_free_conn_from_trx(trx, hs_r_conns[link_idx], FALSE, FALSE, NULL);
13094 hs_r_conns[link_idx] = NULL;
13095 }
13096 }
13097 if (spider_bit_is_set(w_handler_opened, link_idx))
13098 {
13099 if ((error_num2 = spider_db_close_handler(this,
13100 hs_w_conns[link_idx], link_idx, SPIDER_CONN_KIND_HS_WRITE))
13101 ) {
13102 if (
13103 share->monitoring_kind[link_idx] &&
13104 need_mons[link_idx]
13105 ) {
13106 error_num2 = spider_ping_table_mon_from_table(
13107 trx,
13108 trx->thd,
13109 share,
13110 link_idx,
13111 (uint32) share->monitoring_sid[link_idx],
13112 share->table_name,
13113 share->table_name_length,
13114 conn_link_idx[link_idx],
13115 NULL,
13116 0,
13117 share->monitoring_kind[link_idx],
13118 share->monitoring_limit[link_idx],
13119 share->monitoring_flag[link_idx],
13120 TRUE
13121 );
13122 }
13123 error_num = error_num2;
13124 }
13125 spider_clear_bit(w_handler_opened, link_idx);
13126 if (release_conn)
13127 {
13128 if (
13129 !hs_w_conns[link_idx]->opened_handlers &&
13130 trx->trx_hs_w_conn_adjustment == trx_hs_w_conn_adjustment &&
13131 spider_param_hs_w_conn_recycle_mode(trx->thd) != 2
13132 ) {
13133 trx->trx_hs_w_conn_adjustment++;
13134 }
13135 spider_free_conn_from_trx(trx, hs_w_conns[link_idx], FALSE, FALSE, NULL);
13136 hs_w_conns[link_idx] = NULL;
13137 }
13138 }
13139#endif
13140 DBUG_RETURN(error_num);
13141}
13142
13143int ha_spider::index_handler_init()
13144{
13145 int lock_mode, error_num;
13146 int roop_start, roop_end, roop_count;
13147 DBUG_ENTER("ha_spider::index_handler_init");
13148 DBUG_PRINT("info",("spider this=%p", this));
13149 if (!init_index_handler)
13150 {
13151 init_index_handler = TRUE;
13152 lock_mode = spider_conn_lock_mode(this);
13153 if (lock_mode)
13154 {
13155 /* "for update" or "lock in share mode" */
13156 roop_start = spider_conn_link_idx_next(share->link_statuses,
13157 conn_link_idx, -1, share->link_count,
13158 SPIDER_LINK_STATUS_RECOVERY);
13159 roop_end = share->link_count;
13160 } else {
13161 roop_start = search_link_idx;
13162 roop_end = search_link_idx + 1;
13163 }
13164 sql_kinds = 0;
13165#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
13166 direct_update_kinds = 0;
13167#endif
13168 for (roop_count = roop_start; roop_count < roop_end;
13169 roop_count = spider_conn_link_idx_next(share->link_statuses,
13170 conn_link_idx, roop_count, share->link_count,
13171 SPIDER_LINK_STATUS_RECOVERY)
13172 ) {
13173 if (
13174 spider_conn_use_handler(this, lock_mode, roop_count) &&
13175 spider_conn_need_open_handler(this, active_index, roop_count)
13176 ) {
13177#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13178 uint tmp_conn_kind1;
13179#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
13180 if (
13181 do_direct_update &&
13182 spider_bit_is_set(do_hs_direct_update, roop_count)
13183 ) {
13184 tmp_conn_kind1 = SPIDER_CONN_KIND_HS_WRITE;
13185 } else {
13186#endif
13187 tmp_conn_kind1 = conn_kind[roop_count];
13188#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
13189 }
13190#endif
13191#endif
13192 if ((error_num = spider_db_open_handler(this,
13193#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13194 (tmp_conn_kind1 == SPIDER_CONN_KIND_MYSQL ?
13195#endif
13196 conns[roop_count]
13197#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13198 : tmp_conn_kind1 == SPIDER_CONN_KIND_HS_READ ?
13199 hs_r_conns[roop_count] : hs_w_conns[roop_count]
13200 )
13201#endif
13202 , roop_count))
13203 ) {
13204 if (
13205 share->monitoring_kind[roop_count] &&
13206 need_mons[roop_count]
13207 ) {
13208 error_num = spider_ping_table_mon_from_table(
13209 trx,
13210 trx->thd,
13211 share,
13212 roop_count,
13213 (uint32) share->monitoring_sid[roop_count],
13214 share->table_name,
13215 share->table_name_length,
13216 conn_link_idx[roop_count],
13217 NULL,
13218 0,
13219 share->monitoring_kind[roop_count],
13220 share->monitoring_limit[roop_count],
13221 share->monitoring_flag[roop_count],
13222 TRUE
13223 );
13224 }
13225 DBUG_RETURN(error_num);
13226 }
13227#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13228#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
13229 uint tmp_conn_kind2 = conn_kind[roop_count];
13230 conn_kind[roop_count] = tmp_conn_kind1;
13231#endif
13232#endif
13233 set_handler_opened(roop_count);
13234#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13235#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
13236 conn_kind[roop_count] = tmp_conn_kind2;
13237#endif
13238#endif
13239 }
13240 }
13241 if (sql_kinds & SPIDER_SQL_KIND_HANDLER)
13242 {
13243 st_select_lex *select_lex;
13244 longlong select_limit;
13245 longlong offset_limit;
13246 spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit);
13247 DBUG_PRINT("info",("spider SPIDER_SQL_KIND_HANDLER"));
13248 result_list.semi_split_read = 1;
13249 result_list.semi_split_read_limit = 9223372036854775807LL;
13250 if (select_limit == 9223372036854775807LL)
13251 {
13252 DBUG_PRINT("info",("spider set limit to 1"));
13253 result_list.semi_split_read_base = 1;
13254 result_list.split_read = 1;
13255 } else {
13256 DBUG_PRINT("info",("spider set limit to %lld", select_limit));
13257 result_list.semi_split_read_base = select_limit;
13258 result_list.split_read = select_limit;
13259 }
13260 }
13261 }
13262 DBUG_RETURN(0);
13263}
13264
13265int ha_spider::rnd_handler_init()
13266{
13267 int error_num, lock_mode;
13268 int roop_start, roop_end, roop_count;
13269 DBUG_ENTER("ha_spider::rnd_handler_init");
13270 DBUG_PRINT("info",("spider this=%p", this));
13271 if (!init_rnd_handler)
13272 {
13273 init_rnd_handler = TRUE;
13274 lock_mode = spider_conn_lock_mode(this);
13275 if (lock_mode)
13276 {
13277 /* "for update" or "lock in share mode" */
13278 roop_start = spider_conn_link_idx_next(share->link_statuses,
13279 conn_link_idx, -1, share->link_count,
13280 SPIDER_LINK_STATUS_RECOVERY);
13281 roop_end = share->link_count;
13282 } else {
13283 roop_start = search_link_idx;
13284 roop_end = search_link_idx + 1;
13285 }
13286 sql_kinds = 0;
13287#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
13288 direct_update_kinds = 0;
13289#endif
13290 for (roop_count = roop_start; roop_count < roop_end;
13291 roop_count = spider_conn_link_idx_next(share->link_statuses,
13292 conn_link_idx, roop_count, share->link_count,
13293 SPIDER_LINK_STATUS_RECOVERY)
13294 ) {
13295 if (
13296 spider_conn_use_handler(this, lock_mode, roop_count) &&
13297 spider_conn_need_open_handler(this, MAX_KEY, roop_count)
13298 ) {
13299 if ((error_num = spider_db_open_handler(this,
13300#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13301 (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL ?
13302#endif
13303 conns[roop_count]
13304#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13305 : conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ ?
13306 hs_r_conns[roop_count] : hs_w_conns[roop_count]
13307 )
13308#endif
13309 , roop_count))
13310 ) {
13311 if (
13312 share->monitoring_kind[roop_count] &&
13313 need_mons[roop_count]
13314 ) {
13315 error_num = spider_ping_table_mon_from_table(
13316 trx,
13317 trx->thd,
13318 share,
13319 roop_count,
13320 (uint32) share->monitoring_sid[roop_count],
13321 share->table_name,
13322 share->table_name_length,
13323 conn_link_idx[roop_count],
13324 NULL,
13325 0,
13326 share->monitoring_kind[roop_count],
13327 share->monitoring_limit[roop_count],
13328 share->monitoring_flag[roop_count],
13329 TRUE
13330 );
13331 }
13332 DBUG_RETURN(error_num);
13333 }
13334 set_handler_opened(roop_count);
13335 }
13336 }
13337 if (sql_kinds & SPIDER_SQL_KIND_HANDLER)
13338 {
13339 st_select_lex *select_lex;
13340 longlong select_limit;
13341 longlong offset_limit;
13342 spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit);
13343 DBUG_PRINT("info",("spider SPIDER_SQL_KIND_HANDLER"));
13344 result_list.semi_split_read = 1;
13345 result_list.semi_split_read_limit = 9223372036854775807LL;
13346 if (select_limit == 9223372036854775807LL)
13347 {
13348 DBUG_PRINT("info",("spider set limit to 1"));
13349 result_list.semi_split_read_base = 1;
13350 result_list.split_read = 1;
13351 } else {
13352 DBUG_PRINT("info",("spider set limit to %lld", select_limit));
13353 result_list.semi_split_read_base = select_limit;
13354 result_list.split_read = select_limit;
13355 }
13356 }
13357 }
13358 DBUG_RETURN(0);
13359}
13360
13361void ha_spider::set_error_mode()
13362{
13363 THD *thd = ha_thd();
13364 DBUG_ENTER("ha_spider::set_error_mode");
13365 DBUG_PRINT("info",("spider this=%p", this));
13366 switch (thd_sql_command(thd))
13367 {
13368 case SQLCOM_SELECT:
13369 case SQLCOM_SHOW_DATABASES:
13370 case SQLCOM_SHOW_TABLES:
13371 case SQLCOM_SHOW_FIELDS:
13372 case SQLCOM_SHOW_KEYS:
13373 case SQLCOM_SHOW_VARIABLES:
13374 case SQLCOM_SHOW_STATUS:
13375 case SQLCOM_SHOW_ENGINE_LOGS:
13376 case SQLCOM_SHOW_ENGINE_STATUS:
13377 case SQLCOM_SHOW_ENGINE_MUTEX:
13378 case SQLCOM_SHOW_PROCESSLIST:
13379 case SQLCOM_SHOW_MASTER_STAT:
13380 case SQLCOM_SHOW_SLAVE_STAT:
13381 case SQLCOM_SHOW_GRANTS:
13382 case SQLCOM_SHOW_CREATE:
13383 case SQLCOM_SHOW_CHARSETS:
13384 case SQLCOM_SHOW_COLLATIONS:
13385 case SQLCOM_SHOW_CREATE_DB:
13386 case SQLCOM_SHOW_TABLE_STATUS:
13387 case SQLCOM_SHOW_TRIGGERS:
13388 case SQLCOM_CHANGE_DB:
13389 case SQLCOM_HA_OPEN:
13390 case SQLCOM_HA_CLOSE:
13391 case SQLCOM_HA_READ:
13392 case SQLCOM_SHOW_SLAVE_HOSTS:
13393 case SQLCOM_SHOW_BINLOG_EVENTS:
13394 case SQLCOM_SHOW_WARNS:
13395 case SQLCOM_EMPTY_QUERY:
13396 case SQLCOM_SHOW_ERRORS:
13397 case SQLCOM_SHOW_STORAGE_ENGINES:
13398 case SQLCOM_SHOW_PRIVILEGES:
13399 case SQLCOM_HELP:
13400 case SQLCOM_SHOW_CREATE_PROC:
13401 case SQLCOM_SHOW_CREATE_FUNC:
13402 case SQLCOM_SHOW_STATUS_PROC:
13403 case SQLCOM_SHOW_STATUS_FUNC:
13404 case SQLCOM_SHOW_PROC_CODE:
13405 case SQLCOM_SHOW_FUNC_CODE:
13406 case SQLCOM_SHOW_AUTHORS:
13407 case SQLCOM_SHOW_PLUGINS:
13408 case SQLCOM_SHOW_CONTRIBUTORS:
13409 case SQLCOM_SHOW_CREATE_EVENT:
13410 case SQLCOM_SHOW_EVENTS:
13411 case SQLCOM_SHOW_CREATE_TRIGGER:
13412 case SQLCOM_SHOW_PROFILE:
13413 case SQLCOM_SHOW_PROFILES:
13414#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13415 case SQLCOM_HS_READ:
13416#endif
13417 error_mode = spider_param_error_read_mode(thd, share->error_read_mode);
13418 DBUG_PRINT("info",("spider read error_mode=%d", error_mode));
13419 break;
13420 default:
13421 error_mode = spider_param_error_write_mode(thd, share->error_write_mode);
13422 DBUG_PRINT("info",("spider write error_mode=%d", error_mode));
13423 break;
13424 }
13425 DBUG_VOID_RETURN;
13426}
13427
13428void ha_spider::backup_error_status()
13429{
13430 THD *thd = ha_thd();
13431 DBUG_ENTER("ha_spider::backup_error_status");
13432 if (thd)
13433 da_status = thd->is_error();
13434 DBUG_VOID_RETURN;
13435}
13436
13437int ha_spider::check_error_mode(
13438 int error_num
13439) {
13440 THD *thd = ha_thd();
13441 DBUG_ENTER("ha_spider::check_error_mode");
13442 DBUG_PRINT("info",("spider this=%p", this));
13443 DBUG_PRINT("info",("spider error_num=%d", error_num));
13444 if (!thd || !error_mode)
13445 DBUG_RETURN(error_num);
13446 DBUG_PRINT("info",("spider error reset"));
13447 SPIDER_RESTORE_DASTATUS;
13448 DBUG_RETURN(0);
13449}
13450
13451int ha_spider::check_error_mode_eof(
13452 int error_num
13453) {
13454 DBUG_ENTER("ha_spider::check_error_mode_eof");
13455 DBUG_PRINT("info",("spider this=%p", this));
13456 DBUG_PRINT("info",("spider error_num=%d", error_num));
13457 if (error_num == HA_ERR_END_OF_FILE)
13458 DBUG_RETURN(HA_ERR_END_OF_FILE);
13459 if (check_error_mode(error_num))
13460 DBUG_RETURN(error_num);
13461 DBUG_PRINT("info",("spider result_list.finish_flg = TRUE"));
13462 result_list.finish_flg = TRUE;
13463 if (result_list.current)
13464 {
13465 DBUG_PRINT("info",("spider result_list.current->finish_flg = TRUE"));
13466 result_list.current->finish_flg = TRUE;
13467 }
13468 table->status = STATUS_NOT_FOUND;
13469 DBUG_RETURN(HA_ERR_END_OF_FILE);
13470}
13471
13472void ha_spider::check_pre_call(
13473 bool use_parallel
13474) {
13475 THD* thd = ha_thd();
13476 st_select_lex *select_lex = spider_get_select_lex(this);
13477 int skip_parallel_search =
13478 spider_param_skip_parallel_search(thd, share->skip_parallel_search);
13479 DBUG_ENTER("ha_spider::check_pre_call");
13480 DBUG_PRINT("info",("spider this=%p", this));
13481 if (
13482 (
13483 (skip_parallel_search & 1) &&
13484 thd->lex && thd->lex->sql_command != SQLCOM_SELECT // such like insert .. select ..
13485 ) ||
13486 (
13487 (skip_parallel_search & 2) &&
13488 select_lex && select_lex->sql_cache == SELECT_LEX::SQL_NO_CACHE // for mysqldump
13489 )
13490 ) {
13491 use_pre_call = FALSE;
13492 DBUG_VOID_RETURN;
13493 }
13494 if (
13495 use_parallel &&
13496 thd->query_id != partition_handler_share->parallel_search_query_id
13497 ) {
13498 partition_handler_share->parallel_search_query_id = thd->query_id;
13499 ++trx->parallel_search_count;
13500 }
13501 use_pre_call = use_parallel;
13502 if (!use_pre_call)
13503 {
13504 longlong select_limit;
13505 longlong offset_limit;
13506 spider_get_select_limit_from_select_lex(
13507 select_lex, &select_limit, &offset_limit);
13508 if (
13509 select_lex &&
13510 (!select_lex->explicit_limit || !select_limit)
13511 ) {
13512 use_pre_call = TRUE;
13513 }
13514 }
13515 DBUG_VOID_RETURN;
13516}
13517
13518#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
13519void ha_spider::check_insert_dup_update_pushdown()
13520{
13521 THD *thd = trx->thd;
13522 DBUG_ENTER("ha_spider::check_insert_dup_update_pushdown");
13523 DBUG_PRINT("info",("spider this=%p", this));
13524 if (!spider_param_direct_dup_insert(thd, share->direct_dup_insert))
13525 {
13526 DBUG_PRINT("info",("spider FALSE by direct_dup_insert"));
13527 DBUG_VOID_RETURN;
13528 }
13529 direct_update_fields = &thd->lex->update_list;
13530 direct_update_values = &thd->lex->value_list;
13531 if (!append_dup_update_pushdown_sql_part(NULL, 0))
13532 {
13533 result_list.insert_dup_update_pushdown = TRUE;
13534 }
13535 DBUG_VOID_RETURN;
13536}
13537#endif
13538
13539#ifdef HA_CAN_BULK_ACCESS
13540SPIDER_BULK_ACCESS_LINK *ha_spider::create_bulk_access_link()
13541{
13542 uchar *ref;
13543 ha_spider *spider;
13544 SPIDER_BULK_ACCESS_LINK *bulk_access_link;
13545 DBUG_ENTER("ha_spider::create_bulk_access_link");
13546 DBUG_PRINT("info",("spider this=%p", this));
13547/*
13548 if (!init_ha_mem_root)
13549 {
13550 SPD_INIT_ALLOC_ROOT(&ha_mem_root, sizeof(ha_spider) * 16,
13551 sizeof(ha_spider) * 16, MYF(MY_WME));
13552 init_ha_mem_root = TRUE;
13553 }
13554*/
13555 if (!(bulk_access_link = (SPIDER_BULK_ACCESS_LINK *)
13556 spider_bulk_malloc(spider_current_trx, 168, MYF(MY_WME),
13557 &bulk_access_link, sizeof(SPIDER_BULK_ACCESS_LINK),
13558 &ref, ALIGN_SIZE(ref_length) * 2,
13559 NullS))
13560 ) {
13561 goto error_bulk_malloc;
13562 }
13563 SPD_INIT_ALLOC_ROOT(&bulk_access_link->mem_root, sizeof(ha_spider), 0,
13564 MYF(MY_WME));
13565/*
13566 if (!(spider = new ha_spider(spider_hton_ptr, table_share)))
13567 if (!(spider = (ha_spider *) spider_create_handler(
13568 spider_hton_ptr, table_share, &ha_mem_root)))
13569*/
13570 if (!(spider = (ha_spider *) spider_create_handler(
13571 spider_hton_ptr, table_share, &bulk_access_link->mem_root)))
13572 {
13573 goto error_new_spider;
13574 }
13575 DBUG_PRINT("info",("spider spider=%p", spider));
13576 bulk_access_link->spider = spider;
13577 spider->ref = ref;
13578 bulk_access_link->next = NULL;
13579 spider->is_clone = TRUE;
13580 spider->is_bulk_access_clone = TRUE;
13581 spider->pt_clone_source_handler = this;
13582 if (spider->ha_open(table, share->table_name, table->db_stat,
13583 HA_OPEN_IGNORE_IF_LOCKED))
13584 {
13585 goto error_ha_open;
13586 }
13587 DBUG_RETURN(bulk_access_link);
13588
13589error_ha_open:
13590 delete spider;
13591error_new_spider:
13592 free_root(&bulk_access_link->mem_root, MYF(0));
13593 spider_free(spider_current_trx, bulk_access_link, MYF(0));
13594error_bulk_malloc:
13595 DBUG_RETURN(NULL);
13596}
13597
13598void ha_spider::delete_bulk_access_link(
13599 SPIDER_BULK_ACCESS_LINK *bulk_access_link
13600) {
13601 ha_spider *spider = bulk_access_link->spider;
13602 DBUG_ENTER("ha_spider::delete_bulk_access_link");
13603 DBUG_PRINT("info",("spider this=%p", this));
13604 DBUG_PRINT("info",("spider spider=%p", spider));
13605 DBUG_PRINT("info",("spider bulk_access_link->spider->dbton_handler=%p",
13606 spider->dbton_handler));
13607 DBUG_PRINT("info",("spider ptr bulk_access_link->spider->dbton_handler=%p",
13608 &spider->dbton_handler));
13609 spider->close();
13610 delete spider;
13611 free_root(&bulk_access_link->mem_root, MYF(0));
13612 spider_free(spider_current_trx, bulk_access_link, MYF(0));
13613 DBUG_VOID_RETURN;
13614}
13615
13616int ha_spider::sync_from_clone_source(
13617 ha_spider *spider
13618) {
13619 int error_num;
13620 DBUG_ENTER("ha_spider::sync_from_clone_source");
13621 sync_from_clone_source_base(spider);
13622 if (!synced_from_clone_source)
13623 {
13624 DBUG_PRINT("info",("spider synced from clone source all"));
13625 trx = spider->trx;
13626 sql_command = spider->sql_command;
13627#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13628 conn_kinds = spider->conn_kinds;
13629 memcpy(conn_kind, spider->conn_kind, sizeof(uint) * share->link_count);
13630#endif
13631 result_list.lock_type = spider->result_list.lock_type;
13632 lock_type = spider->lock_type;
13633 selupd_lock_mode = spider->selupd_lock_mode;
13634 update_request = spider->update_request;
13635 lock_mode = spider->lock_mode;
13636 high_priority = spider->high_priority;
13637 insert_delayed = spider->insert_delayed;
13638 low_priority = spider->low_priority;
13639 memcpy(conns, spider->conns,
13640 sizeof(SPIDER_CONN *) * share->link_count);
13641#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13642 memcpy(hs_r_conns, spider->hs_r_conns,
13643 sizeof(SPIDER_CONN *) * share->link_count);
13644 memcpy(hs_w_conns, spider->hs_w_conns,
13645 sizeof(SPIDER_CONN *) * share->link_count);
13646#endif
13647 spider_thread_id = spider->spider_thread_id;
13648 trx_conn_adjustment = spider->trx_conn_adjustment;
13649#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13650 trx_hs_r_conn_adjustment = spider->trx_hs_r_conn_adjustment;
13651 trx_hs_w_conn_adjustment = spider->trx_hs_w_conn_adjustment;
13652#endif
13653 search_link_idx = spider->search_link_idx;
13654 external_lock_cnt = spider->external_lock_cnt;
13655 uint roop_count, dbton_id;
13656 spider_db_handler *dbton_hdl, *dbton_hdl2;
13657 for (roop_count = 0; roop_count < share->use_dbton_count; roop_count++)
13658 {
13659 dbton_id = share->use_dbton_ids[roop_count];
13660 dbton_hdl = dbton_handler[dbton_id];
13661 dbton_hdl2 = spider->dbton_handler[dbton_id];
13662 dbton_hdl->sync_from_clone_source(dbton_hdl2);
13663 }
13664 synced_from_clone_source = TRUE;
13665 } else if (external_lock_cnt != spider->external_lock_cnt)
13666 {
13667 DBUG_PRINT("info",("spider synced from clone source"));
13668 sql_command = spider->sql_command;
13669#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13670 conn_kinds = spider->conn_kinds;
13671 memcpy(conn_kind, spider->conn_kind, sizeof(uint) * share->link_count);
13672#endif
13673 result_list.lock_type = spider->result_list.lock_type;
13674 lock_type = spider->lock_type;
13675 selupd_lock_mode = spider->selupd_lock_mode;
13676 update_request = spider->update_request;
13677 lock_mode = spider->lock_mode;
13678 high_priority = spider->high_priority;
13679 insert_delayed = spider->insert_delayed;
13680 low_priority = spider->low_priority;
13681
13682 if ((error_num = spider_check_trx_and_get_conn(spider->trx->thd,
13683 this, TRUE)))
13684 {
13685 DBUG_RETURN(error_num);
13686 }
13687 external_lock_cnt = spider->external_lock_cnt;
13688 }
13689
13690#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
13691#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13692 if (spider->hs_pushed_ret_fields_num < MAX_FIELDS)
13693 {
13694 SPIDER_HS_UINT32_INFO tmp_info;
13695 tmp_info.info_size = spider->hs_pushed_ret_fields_num;
13696 tmp_info.info = spider->hs_pushed_ret_fields;
13697 if ((error_num = info_push(INFO_KIND_HS_RET_FIELDS, &tmp_info)))
13698 {
13699 DBUG_RETURN(error_num);
13700 }
13701 }
13702#endif
13703#endif
13704 DBUG_PRINT("info",("spider bulk_access_link->spider->dbton_handler=%p",
13705 dbton_handler));
13706 DBUG_PRINT("info",("spider ptr bulk_access_link->spider->dbton_handler=%p",
13707 &dbton_handler));
13708 DBUG_RETURN(0);
13709}
13710#endif
13711
13712void ha_spider::sync_from_clone_source_base(
13713 ha_spider *spider
13714) {
13715 uint roop_count2, dbton_id;
13716 spider_db_handler *dbton_hdl, *dbton_hdl2;
13717 DBUG_ENTER("ha_spider::sync_from_clone_source_base");
13718 for (roop_count2 = 0; roop_count2 < share->use_dbton_count; roop_count2++)
13719 {
13720 dbton_id = share->use_dbton_ids[roop_count2];
13721 dbton_hdl = dbton_handler[dbton_id];
13722 dbton_hdl2 = spider->dbton_handler[dbton_id];
13723 dbton_hdl->first_link_idx = dbton_hdl2->first_link_idx;
13724 }
13725 DBUG_VOID_RETURN;
13726}
13727
13728void ha_spider::set_first_link_idx()
13729{
13730 int roop_count, all_link_idx;
13731 uint roop_count2, dbton_id;
13732 spider_db_handler *dbton_hdl;
13733 DBUG_ENTER("ha_spider::set_first_link_idx");
13734 for (roop_count2 = 0; roop_count2 < share->use_dbton_count; roop_count2++)
13735 {
13736 dbton_id = share->use_dbton_ids[roop_count2];
13737 dbton_hdl = dbton_handler[dbton_id];
13738 dbton_hdl->first_link_idx = -1;
13739 }
13740 for (
13741 roop_count = spider_conn_link_idx_next(share->link_statuses,
13742 conn_link_idx, -1, share->link_count, SPIDER_LINK_STATUS_RECOVERY);
13743 roop_count < (int) share->link_count;
13744 roop_count = spider_conn_link_idx_next(share->link_statuses,
13745 conn_link_idx, roop_count, share->link_count,
13746 SPIDER_LINK_STATUS_RECOVERY)
13747 ) {
13748 all_link_idx = conn_link_idx[roop_count];
13749 dbton_id = share->sql_dbton_ids[all_link_idx];
13750 if (dbton_id < SPIDER_DBTON_SIZE)
13751 {
13752 dbton_hdl = dbton_handler[dbton_id];
13753 if (dbton_hdl->first_link_idx == -1)
13754 {
13755 dbton_hdl->first_link_idx = roop_count;
13756 }
13757 }
13758#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13759 dbton_id = share->hs_dbton_ids[all_link_idx];
13760 if (dbton_id < SPIDER_DBTON_SIZE)
13761 {
13762 dbton_hdl = dbton_handler[dbton_id];
13763 if (dbton_hdl->first_link_idx == -1)
13764 {
13765 dbton_hdl->first_link_idx = roop_count;
13766 }
13767 }
13768#endif
13769 }
13770 DBUG_VOID_RETURN;
13771}
13772
13773void ha_spider::reset_first_link_idx()
13774{
13775 int all_link_idx;
13776 uint roop_count2, dbton_id;
13777 spider_db_handler *dbton_hdl;
13778 int lock_mode = spider_conn_lock_mode(this);
13779 DBUG_ENTER("ha_spider::reset_first_link_idx");
13780 if (!lock_mode)
13781 {
13782 DBUG_PRINT("info",("spider use only search_link_idx"));
13783 for (roop_count2 = 0; roop_count2 < share->use_dbton_count; roop_count2++)
13784 {
13785 dbton_id = share->use_dbton_ids[roop_count2];
13786 dbton_hdl = dbton_handler[dbton_id];
13787 dbton_hdl->first_link_idx = -1;
13788 }
13789 all_link_idx = conn_link_idx[search_link_idx];
13790 dbton_id = share->sql_dbton_ids[all_link_idx];
13791 if (dbton_id < SPIDER_DBTON_SIZE)
13792 {
13793 dbton_hdl = dbton_handler[dbton_id];
13794 if (dbton_hdl->first_link_idx == -1)
13795 {
13796 dbton_hdl->first_link_idx = search_link_idx;
13797 }
13798 }
13799#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13800 dbton_id = share->hs_dbton_ids[all_link_idx];
13801 if (dbton_id < SPIDER_DBTON_SIZE)
13802 {
13803 dbton_hdl = dbton_handler[dbton_id];
13804 if (dbton_hdl->first_link_idx == -1)
13805 {
13806 dbton_hdl->first_link_idx = search_link_idx;
13807 }
13808 }
13809#endif
13810 }
13811 DBUG_VOID_RETURN;
13812}
13813
13814int ha_spider::reset_sql_sql(
13815 ulong sql_type
13816) {
13817 int error_num;
13818 uint roop_count, dbton_id;
13819 DBUG_ENTER("ha_spider::reset_sql_sql");
13820 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
13821 {
13822 dbton_id = share->use_sql_dbton_ids[roop_count];
13823 if ((error_num = dbton_handler[dbton_id]->reset_sql(sql_type)))
13824 {
13825 DBUG_RETURN(error_num);
13826 }
13827 }
13828
13829 if (sql_type & SPIDER_SQL_TYPE_BULK_UPDATE_SQL)
13830 {
13831 for (roop_count = 0; roop_count < share->link_count; roop_count++)
13832 {
13833 result_list.update_sqls[roop_count].length(0);
13834 }
13835 }
13836 DBUG_RETURN(0);
13837}
13838
13839#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
13840int ha_spider::reset_hs_sql(
13841 ulong sql_type
13842) {
13843 int error_num;
13844 uint roop_count, dbton_id;
13845 DBUG_ENTER("ha_spider::reset_hs_sql");
13846 for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++)
13847 {
13848 dbton_id = share->use_hs_dbton_ids[roop_count];
13849 if ((error_num = dbton_handler[dbton_id]->reset_sql(sql_type)))
13850 {
13851 DBUG_RETURN(error_num);
13852 }
13853 }
13854 DBUG_RETURN(0);
13855}
13856
13857int ha_spider::reset_hs_keys(
13858 ulong sql_type
13859) {
13860 int error_num;
13861 uint roop_count, dbton_id;
13862 DBUG_ENTER("ha_spider::reset_hs_keys");
13863 for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++)
13864 {
13865 dbton_id = share->use_hs_dbton_ids[roop_count];
13866 if ((error_num = dbton_handler[dbton_id]->reset_keys(sql_type)))
13867 {
13868 DBUG_RETURN(error_num);
13869 }
13870 }
13871 DBUG_RETURN(0);
13872}
13873
13874int ha_spider::reset_hs_upds(
13875 ulong sql_type
13876) {
13877 int error_num;
13878 uint roop_count, dbton_id;
13879 DBUG_ENTER("ha_spider::reset_hs_upds");
13880 for (roop_count = 0; roop_count < share->use_dbton_count; roop_count++)
13881 {
13882 dbton_id = share->use_dbton_ids[roop_count];
13883 if ((error_num = dbton_handler[dbton_id]->reset_upds(sql_type)))
13884 {
13885 DBUG_RETURN(error_num);
13886 }
13887 }
13888 DBUG_RETURN(0);
13889}
13890
13891int ha_spider::reset_hs_strs(
13892 ulong sql_type
13893) {
13894 int error_num;
13895 uint roop_count, dbton_id;
13896 DBUG_ENTER("ha_spider::reset_hs_strs");
13897 for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++)
13898 {
13899 dbton_id = share->use_hs_dbton_ids[roop_count];
13900 if ((error_num = dbton_handler[dbton_id]->reset_strs(sql_type)))
13901 {
13902 DBUG_RETURN(error_num);
13903 }
13904 }
13905 DBUG_RETURN(0);
13906}
13907
13908int ha_spider::reset_hs_strs_pos(
13909 ulong sql_type
13910) {
13911 int error_num;
13912 uint roop_count, dbton_id;
13913 DBUG_ENTER("ha_spider::reset_hs_strs_pos");
13914 for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++)
13915 {
13916 dbton_id = share->use_hs_dbton_ids[roop_count];
13917 if ((error_num = dbton_handler[dbton_id]->reset_strs_pos(sql_type)))
13918 {
13919 DBUG_RETURN(error_num);
13920 }
13921 }
13922 DBUG_RETURN(0);
13923}
13924
13925int ha_spider::push_back_hs_upds(
13926 SPIDER_HS_STRING_REF &info
13927) {
13928 int error_num;
13929 uint roop_count, dbton_id;
13930 DBUG_ENTER("ha_spider::push_back_hs_upds");
13931 for (roop_count = 0; roop_count < share->use_dbton_count; roop_count++)
13932 {
13933 dbton_id = share->use_dbton_ids[roop_count];
13934 if ((error_num = dbton_handler[dbton_id]->push_back_upds(info)))
13935 {
13936 DBUG_RETURN(error_num);
13937 }
13938 }
13939 DBUG_RETURN(0);
13940}
13941#endif
13942
13943int ha_spider::append_tmp_table_and_sql_for_bka(
13944 const key_range *start_key
13945) {
13946 int error_num;
13947 uint roop_count, dbton_id;
13948 spider_db_handler *dbton_hdl;
13949 DBUG_ENTER("ha_spider::append_tmp_table_and_sql_for_bka");
13950 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
13951 {
13952 dbton_id = share->use_sql_dbton_ids[roop_count];
13953 dbton_hdl = dbton_handler[dbton_id];
13954 if (
13955 dbton_hdl->first_link_idx >= 0 &&
13956 (error_num = dbton_hdl->append_tmp_table_and_sql_for_bka(start_key))
13957 ) {
13958 DBUG_RETURN(error_num);
13959 }
13960 }
13961 DBUG_RETURN(0);
13962}
13963
13964int ha_spider::reuse_tmp_table_and_sql_for_bka()
13965{
13966 int error_num;
13967 uint roop_count, dbton_id;
13968 spider_db_handler *dbton_hdl;
13969 DBUG_ENTER("ha_spider::reuse_tmp_table_and_sql_for_bka");
13970 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
13971 {
13972 dbton_id = share->use_sql_dbton_ids[roop_count];
13973 dbton_hdl = dbton_handler[dbton_id];
13974 if (
13975 dbton_hdl->first_link_idx >= 0 &&
13976 (error_num = dbton_hdl->reuse_tmp_table_and_sql_for_bka())
13977 ) {
13978 DBUG_RETURN(error_num);
13979 }
13980 }
13981 DBUG_RETURN(0);
13982}
13983
13984int ha_spider::append_union_table_and_sql_for_bka(
13985 const key_range *start_key
13986) {
13987 int error_num;
13988 uint roop_count, dbton_id;
13989 spider_db_handler *dbton_hdl;
13990 DBUG_ENTER("ha_spider::append_union_table_and_sql_for_bka");
13991 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
13992 {
13993 dbton_id = share->use_sql_dbton_ids[roop_count];
13994 dbton_hdl = dbton_handler[dbton_id];
13995 if (
13996 dbton_hdl->first_link_idx >= 0 &&
13997 (error_num = dbton_hdl->append_union_table_and_sql_for_bka(start_key))
13998 ) {
13999 DBUG_RETURN(error_num);
14000 }
14001 }
14002 DBUG_RETURN(0);
14003}
14004
14005int ha_spider::reuse_union_table_and_sql_for_bka()
14006{
14007 int error_num;
14008 uint roop_count, dbton_id;
14009 spider_db_handler *dbton_hdl;
14010 DBUG_ENTER("ha_spider::reuse_union_table_and_sql_for_bka");
14011 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14012 {
14013 dbton_id = share->use_sql_dbton_ids[roop_count];
14014 dbton_hdl = dbton_handler[dbton_id];
14015 if (
14016 dbton_hdl->first_link_idx >= 0 &&
14017 (error_num = dbton_hdl->reuse_union_table_and_sql_for_bka())
14018 ) {
14019 DBUG_RETURN(error_num);
14020 }
14021 }
14022 DBUG_RETURN(0);
14023}
14024
14025int ha_spider::append_insert_sql_part()
14026{
14027 int error_num;
14028 uint roop_count, dbton_id;
14029 spider_db_handler *dbton_hdl;
14030 DBUG_ENTER("ha_spider::append_insert_sql_part");
14031 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14032 {
14033 dbton_id = share->use_sql_dbton_ids[roop_count];
14034 dbton_hdl = dbton_handler[dbton_id];
14035 if (
14036 dbton_hdl->first_link_idx >= 0 &&
14037 (error_num = dbton_hdl->append_insert_part())
14038 ) {
14039 DBUG_RETURN(error_num);
14040 }
14041 }
14042 DBUG_RETURN(0);
14043}
14044
14045int ha_spider::append_update_sql_part()
14046{
14047 int error_num;
14048 uint roop_count, dbton_id;
14049 spider_db_handler *dbton_hdl;
14050 DBUG_ENTER("ha_spider::append_update_sql_part");
14051 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14052 {
14053 dbton_id = share->use_sql_dbton_ids[roop_count];
14054 dbton_hdl = dbton_handler[dbton_id];
14055 if (
14056 dbton_hdl->first_link_idx >= 0 &&
14057 (error_num = dbton_hdl->append_update_part())
14058 ) {
14059 DBUG_RETURN(error_num);
14060 }
14061 }
14062 DBUG_RETURN(0);
14063}
14064
14065#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
14066#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
14067int ha_spider::append_increment_update_set_sql_part()
14068{
14069 int error_num;
14070 uint roop_count, dbton_id;
14071 spider_db_handler *dbton_hdl;
14072 DBUG_ENTER("ha_spider::append_increment_update_set_sql_part");
14073 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14074 {
14075 dbton_id = share->use_sql_dbton_ids[roop_count];
14076 dbton_hdl = dbton_handler[dbton_id];
14077 if (
14078 dbton_hdl->first_link_idx >= 0 &&
14079 (error_num = dbton_hdl->append_increment_update_set_part())
14080 ) {
14081 DBUG_RETURN(error_num);
14082 }
14083 }
14084 DBUG_RETURN(0);
14085}
14086#endif
14087#endif
14088
14089int ha_spider::append_update_set_sql_part()
14090{
14091 int error_num;
14092 uint roop_count, dbton_id;
14093 spider_db_handler *dbton_hdl;
14094 DBUG_ENTER("ha_spider::append_update_set_sql_part");
14095 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14096 {
14097 dbton_id = share->use_sql_dbton_ids[roop_count];
14098 dbton_hdl = dbton_handler[dbton_id];
14099 if (
14100 dbton_hdl->first_link_idx >= 0 &&
14101 (error_num = dbton_hdl->append_update_set_part())
14102 ) {
14103 DBUG_RETURN(error_num);
14104 }
14105 }
14106 DBUG_RETURN(0);
14107}
14108
14109#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
14110int ha_spider::append_direct_update_set_sql_part()
14111{
14112 int error_num;
14113 uint roop_count, dbton_id;
14114 spider_db_handler *dbton_hdl;
14115 DBUG_ENTER("ha_spider::append_direct_update_set_sql_part");
14116 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14117 {
14118 dbton_id = share->use_sql_dbton_ids[roop_count];
14119 dbton_hdl = dbton_handler[dbton_id];
14120 if (
14121 dbton_hdl->first_link_idx >= 0 &&
14122 (error_num = dbton_hdl->append_direct_update_set_part())
14123 ) {
14124 DBUG_RETURN(error_num);
14125 }
14126 }
14127 DBUG_RETURN(0);
14128}
14129
14130#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
14131int ha_spider::append_direct_update_set_hs_part()
14132{
14133 int error_num;
14134 uint roop_count, dbton_id;
14135 spider_db_handler *dbton_hdl;
14136 DBUG_ENTER("ha_spider::append_direct_update_set_hs_part");
14137 for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++)
14138 {
14139 dbton_id = share->use_hs_dbton_ids[roop_count];
14140 dbton_hdl = dbton_handler[dbton_id];
14141 if (
14142 dbton_hdl->first_link_idx >= 0 &&
14143 (error_num = dbton_hdl->append_direct_update_set_part())
14144 ) {
14145 DBUG_RETURN(error_num);
14146 }
14147 }
14148 DBUG_RETURN(0);
14149}
14150#endif
14151#endif
14152
14153#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
14154int ha_spider::append_dup_update_pushdown_sql_part(
14155 const char *alias,
14156 uint alias_length
14157) {
14158 int error_num;
14159 uint roop_count, dbton_id;
14160 spider_db_handler *dbton_hdl;
14161 DBUG_ENTER("ha_spider::append_dup_update_pushdown_sql_part");
14162 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14163 {
14164 dbton_id = share->use_sql_dbton_ids[roop_count];
14165 dbton_hdl = dbton_handler[dbton_id];
14166 if (
14167 dbton_hdl->first_link_idx >= 0 &&
14168 (error_num = dbton_hdl->append_dup_update_pushdown_part(
14169 alias, alias_length))
14170 ) {
14171 DBUG_RETURN(error_num);
14172 }
14173 }
14174 DBUG_RETURN(0);
14175}
14176
14177int ha_spider::append_update_columns_sql_part(
14178 const char *alias,
14179 uint alias_length
14180) {
14181 int error_num;
14182 uint roop_count, dbton_id;
14183 spider_db_handler *dbton_hdl;
14184 DBUG_ENTER("ha_spider::append_update_columns_sql_part");
14185 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14186 {
14187 dbton_id = share->use_sql_dbton_ids[roop_count];
14188 dbton_hdl = dbton_handler[dbton_id];
14189 if (
14190 dbton_hdl->first_link_idx >= 0 &&
14191 (error_num = dbton_hdl->append_update_columns_part(
14192 alias, alias_length))
14193 ) {
14194 DBUG_RETURN(error_num);
14195 }
14196 }
14197 DBUG_RETURN(0);
14198}
14199
14200int ha_spider::check_update_columns_sql_part()
14201{
14202 int error_num;
14203 uint roop_count, dbton_id;
14204 spider_db_handler *dbton_hdl;
14205 DBUG_ENTER("ha_spider::check_update_columns_sql_part");
14206 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14207 {
14208 dbton_id = share->use_sql_dbton_ids[roop_count];
14209 dbton_hdl = dbton_handler[dbton_id];
14210 if (
14211 dbton_hdl->first_link_idx >= 0 &&
14212 (error_num = dbton_hdl->check_update_columns_part())
14213 ) {
14214 DBUG_RETURN(error_num);
14215 }
14216 }
14217 DBUG_RETURN(0);
14218}
14219#endif
14220
14221int ha_spider::append_delete_sql_part()
14222{
14223 int error_num;
14224 uint roop_count, dbton_id;
14225 spider_db_handler *dbton_hdl;
14226 DBUG_ENTER("ha_spider::append_delete_sql_part");
14227 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14228 {
14229 dbton_id = share->use_sql_dbton_ids[roop_count];
14230 dbton_hdl = dbton_handler[dbton_id];
14231 if (
14232 dbton_hdl->first_link_idx >= 0 &&
14233 (error_num = dbton_hdl->append_delete_part())
14234 ) {
14235 DBUG_RETURN(error_num);
14236 }
14237 }
14238 DBUG_RETURN(0);
14239}
14240
14241int ha_spider::append_select_sql_part(
14242 ulong sql_type
14243) {
14244 int error_num;
14245 uint roop_count, dbton_id;
14246 spider_db_handler *dbton_hdl;
14247 DBUG_ENTER("ha_spider::append_select_sql_part");
14248 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14249 {
14250 dbton_id = share->use_sql_dbton_ids[roop_count];
14251 dbton_hdl = dbton_handler[dbton_id];
14252 if (
14253 dbton_hdl->first_link_idx >= 0 &&
14254 (error_num = dbton_hdl->append_select_part(sql_type))
14255 ) {
14256 DBUG_RETURN(error_num);
14257 }
14258 }
14259 DBUG_RETURN(0);
14260}
14261
14262int ha_spider::append_table_select_sql_part(
14263 ulong sql_type
14264) {
14265 int error_num;
14266 uint roop_count, dbton_id;
14267 spider_db_handler *dbton_hdl;
14268 DBUG_ENTER("ha_spider::append_table_select_sql_part");
14269 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14270 {
14271 dbton_id = share->use_sql_dbton_ids[roop_count];
14272 dbton_hdl = dbton_handler[dbton_id];
14273 if (
14274 dbton_hdl->first_link_idx >= 0 &&
14275 (error_num = dbton_hdl->append_table_select_part(sql_type))
14276 ) {
14277 DBUG_RETURN(error_num);
14278 }
14279 }
14280 DBUG_RETURN(0);
14281}
14282
14283int ha_spider::append_key_select_sql_part(
14284 ulong sql_type,
14285 uint idx
14286) {
14287 int error_num;
14288 uint roop_count, dbton_id;
14289 spider_db_handler *dbton_hdl;
14290 DBUG_ENTER("ha_spider::append_key_select_sql_part");
14291 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14292 {
14293 dbton_id = share->use_sql_dbton_ids[roop_count];
14294 dbton_hdl = dbton_handler[dbton_id];
14295 if (
14296 dbton_hdl->first_link_idx >= 0 &&
14297 (error_num = dbton_hdl->append_key_select_part(sql_type, idx))
14298 ) {
14299 DBUG_RETURN(error_num);
14300 }
14301 }
14302 DBUG_RETURN(0);
14303}
14304
14305int ha_spider::append_minimum_select_sql_part(
14306 ulong sql_type
14307) {
14308 int error_num;
14309 uint roop_count, dbton_id;
14310 spider_db_handler *dbton_hdl;
14311 DBUG_ENTER("ha_spider::append_minimum_select_sql_part");
14312 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14313 {
14314 dbton_id = share->use_sql_dbton_ids[roop_count];
14315 dbton_hdl = dbton_handler[dbton_id];
14316 if (
14317 dbton_hdl->first_link_idx >= 0 &&
14318 (error_num = dbton_hdl->append_minimum_select_part(sql_type))
14319 ) {
14320 DBUG_RETURN(error_num);
14321 }
14322 }
14323 DBUG_RETURN(0);
14324}
14325
14326int ha_spider::append_from_sql_part(
14327 ulong sql_type
14328) {
14329 int error_num;
14330 uint roop_count, dbton_id;
14331 spider_db_handler *dbton_hdl;
14332 DBUG_ENTER("ha_spider::append_from_sql_part");
14333 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14334 {
14335 dbton_id = share->use_sql_dbton_ids[roop_count];
14336 dbton_hdl = dbton_handler[dbton_id];
14337 if (
14338 dbton_hdl->first_link_idx >= 0 &&
14339 (error_num = dbton_hdl->append_from_part(sql_type,
14340 dbton_hdl->first_link_idx))
14341 ) {
14342 DBUG_RETURN(error_num);
14343 }
14344 }
14345 DBUG_RETURN(0);
14346}
14347
14348int ha_spider::append_hint_after_table_sql_part(
14349 ulong sql_type
14350) {
14351 int error_num;
14352 uint roop_count, dbton_id;
14353 spider_db_handler *dbton_hdl;
14354 DBUG_ENTER("ha_spider::append_hint_after_table_sql_part");
14355 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14356 {
14357 dbton_id = share->use_sql_dbton_ids[roop_count];
14358 dbton_hdl = dbton_handler[dbton_id];
14359 if (
14360 dbton_hdl->first_link_idx >= 0 &&
14361 (error_num = dbton_hdl->append_hint_after_table_part(sql_type))
14362 ) {
14363 DBUG_RETURN(error_num);
14364 }
14365 }
14366 DBUG_RETURN(0);
14367}
14368
14369void ha_spider::set_where_pos_sql(
14370 ulong sql_type
14371) {
14372 uint roop_count, dbton_id;
14373 spider_db_handler *dbton_hdl;
14374 DBUG_ENTER("ha_spider::set_where_pos_sql");
14375 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14376 {
14377 dbton_id = share->use_sql_dbton_ids[roop_count];
14378 dbton_hdl = dbton_handler[dbton_id];
14379 if (dbton_hdl->first_link_idx >= 0)
14380 dbton_hdl->set_where_pos(sql_type);
14381 }
14382 DBUG_VOID_RETURN;
14383}
14384
14385void ha_spider::set_where_to_pos_sql(
14386 ulong sql_type
14387) {
14388 uint roop_count, dbton_id;
14389 spider_db_handler *dbton_hdl;
14390 DBUG_ENTER("ha_spider::set_where_to_pos_sql");
14391 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14392 {
14393 dbton_id = share->use_sql_dbton_ids[roop_count];
14394 dbton_hdl = dbton_handler[dbton_id];
14395 if (dbton_hdl->first_link_idx >= 0)
14396 dbton_hdl->set_where_to_pos(sql_type);
14397 }
14398 DBUG_VOID_RETURN;
14399}
14400
14401int ha_spider::check_item_type_sql(
14402 Item *item
14403) {
14404 int error_num;
14405 uint roop_count, dbton_id;
14406 spider_db_handler *dbton_hdl;
14407 DBUG_ENTER("ha_spider::check_item_type_sql");
14408 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14409 {
14410 dbton_id = share->use_sql_dbton_ids[roop_count];
14411 dbton_hdl = dbton_handler[dbton_id];
14412 if (
14413 dbton_hdl->first_link_idx >= 0 &&
14414 (error_num = dbton_hdl->check_item_type(item))
14415 ) {
14416 DBUG_RETURN(error_num);
14417 }
14418 }
14419 DBUG_RETURN(0);
14420}
14421
14422int ha_spider::append_values_connector_sql_part(
14423 ulong sql_type
14424) {
14425 int error_num;
14426 uint roop_count, dbton_id;
14427 spider_db_handler *dbton_hdl;
14428 DBUG_ENTER("ha_spider::append_values_connector_sql_part");
14429 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14430 {
14431 dbton_id = share->use_sql_dbton_ids[roop_count];
14432 dbton_hdl = dbton_handler[dbton_id];
14433 if (
14434 dbton_hdl->first_link_idx >= 0 &&
14435 (error_num =
14436 dbton_hdl->append_values_connector_part(sql_type))
14437 ) {
14438 DBUG_RETURN(error_num);
14439 }
14440 }
14441 DBUG_RETURN(0);
14442}
14443
14444int ha_spider::append_values_terminator_sql_part(
14445 ulong sql_type
14446) {
14447 int error_num;
14448 uint roop_count, dbton_id;
14449 spider_db_handler *dbton_hdl;
14450 DBUG_ENTER("ha_spider::append_values_terminator_sql_part");
14451 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14452 {
14453 dbton_id = share->use_sql_dbton_ids[roop_count];
14454 dbton_hdl = dbton_handler[dbton_id];
14455 if (
14456 dbton_hdl->first_link_idx >= 0 &&
14457 (error_num =
14458 dbton_hdl->append_values_terminator_part(sql_type))
14459 ) {
14460 DBUG_RETURN(error_num);
14461 }
14462 }
14463 DBUG_RETURN(0);
14464}
14465
14466int ha_spider::append_union_table_connector_sql_part(
14467 ulong sql_type
14468) {
14469 int error_num;
14470 uint roop_count, dbton_id;
14471 spider_db_handler *dbton_hdl;
14472 DBUG_ENTER("ha_spider::append_union_table_connector_sql_part");
14473 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14474 {
14475 dbton_id = share->use_sql_dbton_ids[roop_count];
14476 dbton_hdl = dbton_handler[dbton_id];
14477 if (
14478 dbton_hdl->first_link_idx >= 0 &&
14479 (error_num =
14480 dbton_hdl->append_union_table_connector_part(sql_type))
14481 ) {
14482 DBUG_RETURN(error_num);
14483 }
14484 }
14485 DBUG_RETURN(0);
14486}
14487
14488int ha_spider::append_union_table_terminator_sql_part(
14489 ulong sql_type
14490) {
14491 int error_num;
14492 uint roop_count, dbton_id;
14493 spider_db_handler *dbton_hdl;
14494 DBUG_ENTER("ha_spider::append_union_table_terminator_sql_part");
14495 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14496 {
14497 dbton_id = share->use_sql_dbton_ids[roop_count];
14498 dbton_hdl = dbton_handler[dbton_id];
14499 if (
14500 dbton_hdl->first_link_idx >= 0 &&
14501 (error_num =
14502 dbton_hdl->append_union_table_terminator_part(sql_type))
14503 ) {
14504 DBUG_RETURN(error_num);
14505 }
14506 }
14507 DBUG_RETURN(0);
14508}
14509
14510int ha_spider::append_key_column_values_sql_part(
14511 const key_range *start_key,
14512 ulong sql_type
14513) {
14514 int error_num;
14515 uint roop_count, dbton_id;
14516 spider_db_handler *dbton_hdl;
14517 DBUG_ENTER("ha_spider::append_key_column_values_sql_part");
14518 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14519 {
14520 dbton_id = share->use_sql_dbton_ids[roop_count];
14521 dbton_hdl = dbton_handler[dbton_id];
14522 if (
14523 dbton_hdl->first_link_idx >= 0 &&
14524 (error_num =
14525 dbton_hdl->append_key_column_values_part(start_key, sql_type))
14526 ) {
14527 DBUG_RETURN(error_num);
14528 }
14529 }
14530 DBUG_RETURN(0);
14531}
14532
14533int ha_spider::append_key_column_values_with_name_sql_part(
14534 const key_range *start_key,
14535 ulong sql_type
14536) {
14537 int error_num;
14538 uint roop_count, dbton_id;
14539 spider_db_handler *dbton_hdl;
14540 DBUG_ENTER("ha_spider::append_key_column_values_with_name_sql_part");
14541 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14542 {
14543 dbton_id = share->use_sql_dbton_ids[roop_count];
14544 dbton_hdl = dbton_handler[dbton_id];
14545 if (
14546 dbton_hdl->first_link_idx >= 0 &&
14547 (error_num =
14548 dbton_hdl->append_key_column_values_with_name_part(
14549 start_key, sql_type))
14550 ) {
14551 DBUG_RETURN(error_num);
14552 }
14553 }
14554 DBUG_RETURN(0);
14555}
14556
14557int ha_spider::append_key_where_sql_part(
14558 const key_range *start_key,
14559 const key_range *end_key,
14560 ulong sql_type
14561) {
14562 int error_num;
14563 uint roop_count, dbton_id;
14564 spider_db_handler *dbton_hdl;
14565 DBUG_ENTER("ha_spider::append_key_where_sql_part");
14566 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14567 {
14568 dbton_id = share->use_sql_dbton_ids[roop_count];
14569 dbton_hdl = dbton_handler[dbton_id];
14570 if (
14571 dbton_hdl->first_link_idx >= 0 &&
14572 (error_num = dbton_hdl->append_key_where_part(start_key, end_key,
14573 sql_type))
14574 ) {
14575 DBUG_RETURN(error_num);
14576 }
14577 }
14578 DBUG_RETURN(0);
14579}
14580
14581#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
14582int ha_spider::append_key_where_hs_part(
14583 const key_range *start_key,
14584 const key_range *end_key,
14585 ulong sql_type
14586) {
14587 int error_num;
14588 uint roop_count, dbton_id;
14589 spider_db_handler *dbton_hdl;
14590 DBUG_ENTER("ha_spider::append_key_where_hs_part");
14591 for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++)
14592 {
14593 dbton_id = share->use_hs_dbton_ids[roop_count];
14594 dbton_hdl = dbton_handler[dbton_id];
14595 if (
14596 dbton_hdl->first_link_idx >= 0 &&
14597 (error_num = dbton_hdl->append_key_where_part(start_key, end_key,
14598 sql_type))
14599 ) {
14600 DBUG_RETURN(error_num);
14601 }
14602 }
14603 DBUG_RETURN(0);
14604}
14605#endif
14606
14607int ha_spider::append_match_where_sql_part(
14608 ulong sql_type
14609) {
14610 int error_num;
14611 uint roop_count, dbton_id;
14612 spider_db_handler *dbton_hdl;
14613 DBUG_ENTER("ha_spider::append_match_where_sql_part");
14614 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14615 {
14616 dbton_id = share->use_sql_dbton_ids[roop_count];
14617 dbton_hdl = dbton_handler[dbton_id];
14618 if (
14619 dbton_hdl->first_link_idx >= 0 &&
14620 (error_num = dbton_hdl->append_match_where_part(sql_type))
14621 ) {
14622 DBUG_RETURN(error_num);
14623 }
14624 }
14625 DBUG_RETURN(0);
14626}
14627
14628int ha_spider::append_condition_sql_part(
14629 const char *alias,
14630 uint alias_length,
14631 ulong sql_type,
14632 bool test_flg
14633) {
14634 int error_num;
14635 uint roop_count, dbton_id;
14636 spider_db_handler *dbton_hdl;
14637 DBUG_ENTER("ha_spider::append_condition_sql_part");
14638 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14639 {
14640 dbton_id = share->use_sql_dbton_ids[roop_count];
14641 dbton_hdl = dbton_handler[dbton_id];
14642 if (
14643 dbton_hdl->first_link_idx >= 0 &&
14644 (error_num = dbton_hdl->append_condition_part(alias, alias_length,
14645 sql_type, test_flg))
14646 ) {
14647 DBUG_RETURN(error_num);
14648 }
14649 }
14650 DBUG_RETURN(0);
14651}
14652
14653#ifdef HANDLER_HAS_DIRECT_AGGREGATE
14654int ha_spider::append_sum_select_sql_part(
14655 ulong sql_type,
14656 const char *alias,
14657 uint alias_length
14658) {
14659 int error_num;
14660 uint roop_count, dbton_id;
14661 spider_db_handler *dbton_hdl;
14662 DBUG_ENTER("ha_spider::append_sum_select_sql_part");
14663 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14664 {
14665 dbton_id = share->use_sql_dbton_ids[roop_count];
14666 dbton_hdl = dbton_handler[dbton_id];
14667 if (
14668 dbton_hdl->first_link_idx >= 0 &&
14669 (error_num = dbton_hdl->append_sum_select_part(sql_type,
14670 alias, alias_length))
14671 ) {
14672 DBUG_RETURN(error_num);
14673 }
14674 }
14675 trx->direct_aggregate_count++;
14676 DBUG_RETURN(0);
14677}
14678#endif
14679
14680int ha_spider::append_match_select_sql_part(
14681 ulong sql_type,
14682 const char *alias,
14683 uint alias_length
14684) {
14685 int error_num;
14686 uint roop_count, dbton_id;
14687 spider_db_handler *dbton_hdl;
14688 DBUG_ENTER("ha_spider::append_match_select_sql_part");
14689 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14690 {
14691 dbton_id = share->use_sql_dbton_ids[roop_count];
14692 dbton_hdl = dbton_handler[dbton_id];
14693 if (
14694 dbton_hdl->first_link_idx >= 0 &&
14695 (error_num = dbton_hdl->append_match_select_part(sql_type,
14696 alias, alias_length))
14697 ) {
14698 DBUG_RETURN(error_num);
14699 }
14700 }
14701 DBUG_RETURN(0);
14702}
14703
14704void ha_spider::set_order_pos_sql(
14705 ulong sql_type
14706) {
14707 uint roop_count, dbton_id;
14708 spider_db_handler *dbton_hdl;
14709 DBUG_ENTER("ha_spider::set_order_pos_sql");
14710 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14711 {
14712 dbton_id = share->use_sql_dbton_ids[roop_count];
14713 dbton_hdl = dbton_handler[dbton_id];
14714 if (dbton_hdl->first_link_idx >= 0)
14715 dbton_hdl->set_order_pos(sql_type);
14716 }
14717 DBUG_VOID_RETURN;
14718}
14719
14720void ha_spider::set_order_to_pos_sql(
14721 ulong sql_type
14722) {
14723 uint roop_count, dbton_id;
14724 spider_db_handler *dbton_hdl;
14725 DBUG_ENTER("ha_spider::set_order_to_pos_sql");
14726 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14727 {
14728 dbton_id = share->use_sql_dbton_ids[roop_count];
14729 dbton_hdl = dbton_handler[dbton_id];
14730 if (dbton_hdl->first_link_idx >= 0)
14731 dbton_hdl->set_order_to_pos(sql_type);
14732 }
14733 DBUG_VOID_RETURN;
14734}
14735
14736#ifdef HANDLER_HAS_DIRECT_AGGREGATE
14737int ha_spider::append_group_by_sql_part(
14738 const char *alias,
14739 uint alias_length,
14740 ulong sql_type
14741) {
14742 int error_num;
14743 uint roop_count, dbton_id;
14744 spider_db_handler *dbton_hdl;
14745 DBUG_ENTER("ha_spider::append_group_by_sql_part");
14746 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14747 {
14748 dbton_id = share->use_sql_dbton_ids[roop_count];
14749 dbton_hdl = dbton_handler[dbton_id];
14750 if (
14751 dbton_hdl->first_link_idx >= 0 &&
14752 (error_num = dbton_hdl->append_group_by_part(
14753 alias, alias_length, sql_type))
14754 ) {
14755 DBUG_RETURN(error_num);
14756 }
14757 }
14758 DBUG_RETURN(0);
14759}
14760#endif
14761
14762int ha_spider::append_key_order_for_merge_with_alias_sql_part(
14763 const char *alias,
14764 uint alias_length,
14765 ulong sql_type
14766) {
14767 int error_num;
14768 uint roop_count, dbton_id;
14769 spider_db_handler *dbton_hdl;
14770 DBUG_ENTER("ha_spider::append_key_order_for_merge_with_alias_sql_part");
14771#ifdef HANDLER_HAS_DIRECT_AGGREGATE
14772 if (result_list.direct_aggregate)
14773 {
14774 st_select_lex *select_lex = spider_get_select_lex(this);
14775 ORDER *group = (ORDER *) select_lex->group_list.first;
14776 if (!group && *(select_lex->join->sum_funcs))
14777 {
14778 DBUG_PRINT("info",("spider skip order by"));
14779 DBUG_RETURN(0);
14780 }
14781 }
14782#endif
14783 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14784 {
14785 dbton_id = share->use_sql_dbton_ids[roop_count];
14786 dbton_hdl = dbton_handler[dbton_id];
14787 if (
14788 dbton_hdl->first_link_idx >= 0 &&
14789 (error_num = dbton_hdl->append_key_order_for_merge_with_alias_part(
14790 alias, alias_length, sql_type))
14791 ) {
14792 DBUG_RETURN(error_num);
14793 }
14794 }
14795 DBUG_RETURN(0);
14796}
14797
14798int ha_spider::append_key_order_for_direct_order_limit_with_alias_sql_part(
14799 const char *alias,
14800 uint alias_length,
14801 ulong sql_type
14802) {
14803 int error_num;
14804 uint roop_count, dbton_id;
14805 spider_db_handler *dbton_hdl;
14806 DBUG_ENTER("ha_spider::append_key_order_for_direct_order_limit_with_alias_sql_part");
14807 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14808 {
14809 dbton_id = share->use_sql_dbton_ids[roop_count];
14810 dbton_hdl = dbton_handler[dbton_id];
14811 if (
14812 dbton_hdl->first_link_idx >= 0 &&
14813 (error_num =
14814 dbton_hdl->append_key_order_for_direct_order_limit_with_alias_part(
14815 alias, alias_length, sql_type))
14816 ) {
14817 DBUG_RETURN(error_num);
14818 }
14819 }
14820 DBUG_RETURN(0);
14821}
14822
14823int ha_spider::append_key_order_with_alias_sql_part(
14824 const char *alias,
14825 uint alias_length,
14826 ulong sql_type
14827) {
14828 int error_num;
14829 uint roop_count, dbton_id;
14830 spider_db_handler *dbton_hdl;
14831 DBUG_ENTER("ha_spider::append_key_order_with_alias_sql_part");
14832#ifdef HANDLER_HAS_DIRECT_AGGREGATE
14833 if (result_list.direct_aggregate)
14834 {
14835 st_select_lex *select_lex = spider_get_select_lex(this);
14836 ORDER *group = (ORDER *) select_lex->group_list.first;
14837 if (!group && *(select_lex->join->sum_funcs))
14838 {
14839 DBUG_PRINT("info",("spider skip order by"));
14840 DBUG_RETURN(0);
14841 }
14842 }
14843#endif
14844 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14845 {
14846 dbton_id = share->use_sql_dbton_ids[roop_count];
14847 dbton_hdl = dbton_handler[dbton_id];
14848 if (
14849 dbton_hdl->first_link_idx >= 0 &&
14850 (error_num = dbton_hdl->append_key_order_with_alias_part(
14851 alias, alias_length, sql_type))
14852 ) {
14853 DBUG_RETURN(error_num);
14854 }
14855 }
14856 DBUG_RETURN(0);
14857}
14858
14859int ha_spider::append_limit_sql_part(
14860 longlong offset,
14861 longlong limit,
14862 ulong sql_type
14863) {
14864 int error_num;
14865 uint roop_count, dbton_id;
14866 spider_db_handler *dbton_hdl;
14867 DBUG_ENTER("ha_spider::append_limit_sql_part");
14868 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14869 {
14870 dbton_id = share->use_sql_dbton_ids[roop_count];
14871 dbton_hdl = dbton_handler[dbton_id];
14872 if (
14873 dbton_hdl->first_link_idx >= 0 &&
14874 (error_num = dbton_hdl->append_limit_part(offset, limit, sql_type))
14875 ) {
14876 DBUG_RETURN(error_num);
14877 }
14878 }
14879 DBUG_RETURN(0);
14880}
14881
14882#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
14883int ha_spider::append_limit_hs_part(
14884 longlong offset,
14885 longlong limit,
14886 ulong sql_type
14887) {
14888 int error_num;
14889 uint roop_count, dbton_id;
14890 spider_db_handler *dbton_hdl;
14891 DBUG_ENTER("ha_spider::append_limit_hs_part");
14892 for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++)
14893 {
14894 dbton_id = share->use_hs_dbton_ids[roop_count];
14895 dbton_hdl = dbton_handler[dbton_id];
14896 if (
14897 dbton_hdl->first_link_idx >= 0 &&
14898 (error_num = dbton_hdl->append_limit_part(offset, limit, sql_type))
14899 ) {
14900 DBUG_RETURN(error_num);
14901 }
14902 }
14903 DBUG_RETURN(0);
14904}
14905#endif
14906
14907int ha_spider::reappend_limit_sql_part(
14908 longlong offset,
14909 longlong limit,
14910 ulong sql_type
14911) {
14912 int error_num;
14913 uint roop_count, dbton_id;
14914 spider_db_handler *dbton_hdl;
14915 DBUG_ENTER("ha_spider::reappend_limit_sql_part");
14916 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14917 {
14918 dbton_id = share->use_sql_dbton_ids[roop_count];
14919 dbton_hdl = dbton_handler[dbton_id];
14920 if (
14921 dbton_hdl->first_link_idx >= 0 &&
14922 (error_num = dbton_hdl->reappend_limit_part(offset, limit, sql_type))
14923 ) {
14924 DBUG_RETURN(error_num);
14925 }
14926 }
14927 DBUG_RETURN(0);
14928}
14929
14930int ha_spider::append_insert_terminator_sql_part(
14931 ulong sql_type
14932) {
14933 int error_num;
14934 uint roop_count, dbton_id;
14935 spider_db_handler *dbton_hdl;
14936 DBUG_ENTER("ha_spider::append_insert_terminator_sql_part");
14937 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14938 {
14939 dbton_id = share->use_sql_dbton_ids[roop_count];
14940 dbton_hdl = dbton_handler[dbton_id];
14941 if (
14942 dbton_hdl->first_link_idx >= 0 &&
14943 (error_num = dbton_hdl->append_insert_terminator_part(sql_type))
14944 ) {
14945 DBUG_RETURN(error_num);
14946 }
14947 }
14948 DBUG_RETURN(0);
14949}
14950
14951int ha_spider::append_insert_values_sql_part(
14952 ulong sql_type
14953) {
14954 int error_num;
14955 uint roop_count, dbton_id;
14956 spider_db_handler *dbton_hdl;
14957 DBUG_ENTER("ha_spider::append_insert_values_sql_part");
14958 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
14959 {
14960 dbton_id = share->use_sql_dbton_ids[roop_count];
14961 dbton_hdl = dbton_handler[dbton_id];
14962 if (
14963 dbton_hdl->first_link_idx >= 0 &&
14964 (error_num = dbton_hdl->append_insert_values_part(sql_type))
14965 ) {
14966 DBUG_RETURN(error_num);
14967 }
14968 }
14969 DBUG_RETURN(0);
14970}
14971
14972#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
14973int ha_spider::append_insert_values_hs_part(
14974 ulong sql_type
14975) {
14976 int error_num;
14977 uint roop_count, dbton_id;
14978 spider_db_handler *dbton_hdl;
14979 DBUG_ENTER("ha_spider::append_insert_values_hs_part");
14980 for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++)
14981 {
14982 dbton_id = share->use_hs_dbton_ids[roop_count];
14983 dbton_hdl = dbton_handler[dbton_id];
14984 if (
14985 dbton_hdl->first_link_idx >= 0 &&
14986 (error_num = dbton_hdl->append_insert_values_part(sql_type))
14987 ) {
14988 DBUG_RETURN(error_num);
14989 }
14990 }
14991 DBUG_RETURN(0);
14992}
14993#endif
14994
14995int ha_spider::append_into_sql_part(
14996 ulong sql_type
14997) {
14998 int error_num;
14999 uint roop_count, dbton_id;
15000 spider_db_handler *dbton_hdl;
15001 DBUG_ENTER("ha_spider::append_into_sql_part");
15002 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15003 {
15004 dbton_id = share->use_sql_dbton_ids[roop_count];
15005 dbton_hdl = dbton_handler[dbton_id];
15006 if (
15007 dbton_hdl->first_link_idx >= 0 &&
15008 (error_num = dbton_hdl->append_into_part(sql_type))
15009 ) {
15010 DBUG_RETURN(error_num);
15011 }
15012 }
15013 DBUG_RETURN(0);
15014}
15015
15016void ha_spider::set_insert_to_pos_sql(
15017 ulong sql_type
15018) {
15019 uint roop_count, dbton_id;
15020 spider_db_handler *dbton_hdl;
15021 DBUG_ENTER("ha_spider::set_insert_to_pos_sql");
15022 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15023 {
15024 dbton_id = share->use_sql_dbton_ids[roop_count];
15025 dbton_hdl = dbton_handler[dbton_id];
15026 if (dbton_hdl->first_link_idx >= 0)
15027 dbton_hdl->set_insert_to_pos(sql_type);
15028 }
15029 DBUG_VOID_RETURN;
15030}
15031
15032bool ha_spider::is_bulk_insert_exec_period(
15033 bool bulk_end
15034) {
15035 uint roop_count, dbton_id;
15036 spider_db_handler *dbton_hdl;
15037 DBUG_ENTER("ha_spider::is_bulk_insert_exec_period");
15038#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
15039 if (sql_kinds & SPIDER_SQL_KIND_SQL)
15040 {
15041#endif
15042 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15043 {
15044 dbton_id = share->use_sql_dbton_ids[roop_count];
15045 dbton_hdl = dbton_handler[dbton_id];
15046 if (
15047 dbton_hdl->first_link_idx >= 0 &&
15048 dbton_hdl->is_bulk_insert_exec_period(bulk_end)
15049 ) {
15050 DBUG_RETURN(TRUE);
15051 }
15052 }
15053#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
15054 }
15055 if (sql_kinds & SPIDER_SQL_KIND_HS)
15056 {
15057 for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++)
15058 {
15059 dbton_id = share->use_hs_dbton_ids[roop_count];
15060 dbton_hdl = dbton_handler[dbton_id];
15061 if (
15062 dbton_hdl->first_link_idx >= 0 &&
15063 dbton_hdl->is_bulk_insert_exec_period(bulk_end)
15064 ) {
15065 DBUG_RETURN(TRUE);
15066 }
15067 }
15068 }
15069#endif
15070 DBUG_RETURN(FALSE);
15071}
15072
15073int ha_spider::append_select_lock_sql_part(
15074 ulong sql_type
15075) {
15076 int error_num;
15077 uint roop_count, dbton_id;
15078 spider_db_handler *dbton_hdl;
15079 DBUG_ENTER("ha_spider::append_select_lock_sql_part");
15080 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15081 {
15082 dbton_id = share->use_sql_dbton_ids[roop_count];
15083 dbton_hdl = dbton_handler[dbton_id];
15084 if (
15085 dbton_hdl->first_link_idx >= 0 &&
15086 (error_num = dbton_hdl->append_select_lock_part(sql_type))
15087 ) {
15088 DBUG_RETURN(error_num);
15089 }
15090 }
15091 DBUG_RETURN(0);
15092}
15093
15094int ha_spider::append_union_all_start_sql_part(
15095 ulong sql_type
15096) {
15097 int error_num;
15098 uint roop_count, dbton_id;
15099 spider_db_handler *dbton_hdl;
15100 DBUG_ENTER("ha_spider::append_union_all_start_sql_part");
15101 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15102 {
15103 dbton_id = share->use_sql_dbton_ids[roop_count];
15104 dbton_hdl = dbton_handler[dbton_id];
15105 if (
15106 dbton_hdl->first_link_idx >= 0 &&
15107 (error_num = dbton_hdl->append_union_all_start_part(sql_type))
15108 ) {
15109 DBUG_RETURN(error_num);
15110 }
15111 }
15112 DBUG_RETURN(0);
15113}
15114
15115int ha_spider::append_union_all_sql_part(
15116 ulong sql_type
15117) {
15118 int error_num;
15119 uint roop_count, dbton_id;
15120 spider_db_handler *dbton_hdl;
15121 DBUG_ENTER("ha_spider::append_union_all_sql_part");
15122 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15123 {
15124 dbton_id = share->use_sql_dbton_ids[roop_count];
15125 dbton_hdl = dbton_handler[dbton_id];
15126 if (
15127 dbton_hdl->first_link_idx >= 0 &&
15128 (error_num = dbton_hdl->append_union_all_part(sql_type))
15129 ) {
15130 DBUG_RETURN(error_num);
15131 }
15132 }
15133 DBUG_RETURN(0);
15134}
15135
15136int ha_spider::append_union_all_end_sql_part(
15137 ulong sql_type
15138) {
15139 int error_num;
15140 uint roop_count, dbton_id;
15141 spider_db_handler *dbton_hdl;
15142 DBUG_ENTER("ha_spider::append_union_all_end_sql_part");
15143 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15144 {
15145 dbton_id = share->use_sql_dbton_ids[roop_count];
15146 dbton_hdl = dbton_handler[dbton_id];
15147 if (
15148 dbton_hdl->first_link_idx >= 0 &&
15149 (error_num = dbton_hdl->append_union_all_end_part(sql_type))
15150 ) {
15151 DBUG_RETURN(error_num);
15152 }
15153 }
15154 DBUG_RETURN(0);
15155}
15156
15157int ha_spider::append_multi_range_cnt_sql_part(
15158 ulong sql_type,
15159 uint multi_range_cnt,
15160 bool with_comma
15161) {
15162 int error_num;
15163 uint roop_count, dbton_id;
15164 spider_db_handler *dbton_hdl;
15165 DBUG_ENTER("ha_spider::append_multi_range_cnt_sql_part");
15166 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15167 {
15168 dbton_id = share->use_sql_dbton_ids[roop_count];
15169 dbton_hdl = dbton_handler[dbton_id];
15170 if (
15171 dbton_hdl->first_link_idx >= 0 &&
15172 (error_num = dbton_hdl->append_multi_range_cnt_part(
15173 sql_type, multi_range_cnt, with_comma))
15174 ) {
15175 DBUG_RETURN(error_num);
15176 }
15177 }
15178 DBUG_RETURN(0);
15179}
15180
15181int ha_spider::append_multi_range_cnt_with_name_sql_part(
15182 ulong sql_type,
15183 uint multi_range_cnt
15184) {
15185 int error_num;
15186 uint roop_count, dbton_id;
15187 spider_db_handler *dbton_hdl;
15188 DBUG_ENTER("ha_spider::append_multi_range_cnt_with_name_sql_part");
15189 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15190 {
15191 dbton_id = share->use_sql_dbton_ids[roop_count];
15192 dbton_hdl = dbton_handler[dbton_id];
15193 if (
15194 dbton_hdl->first_link_idx >= 0 &&
15195 (error_num = dbton_hdl->append_multi_range_cnt_with_name_part(
15196 sql_type, multi_range_cnt))
15197 ) {
15198 DBUG_RETURN(error_num);
15199 }
15200 }
15201 DBUG_RETURN(0);
15202}
15203
15204int ha_spider::append_delete_all_rows_sql_part(
15205 ulong sql_type
15206) {
15207 int error_num;
15208 uint roop_count, dbton_id;
15209 spider_db_handler *dbton_hdl;
15210 DBUG_ENTER("ha_spider::append_delete_all_rows_sql_part");
15211 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15212 {
15213 dbton_id = share->use_sql_dbton_ids[roop_count];
15214 dbton_hdl = dbton_handler[dbton_id];
15215 if (
15216 dbton_hdl->first_link_idx >= 0 &&
15217 (error_num = dbton_hdl->append_delete_all_rows_part(sql_type))
15218 ) {
15219 DBUG_RETURN(error_num);
15220 }
15221 }
15222 DBUG_RETURN(0);
15223}
15224
15225int ha_spider::append_update_sql(
15226 const TABLE *table,
15227 my_ptrdiff_t ptr_diff,
15228 bool bulk
15229) {
15230 int error_num;
15231 uint roop_count, dbton_id;
15232 spider_db_handler *dbton_hdl;
15233 DBUG_ENTER("ha_spider::append_update");
15234 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15235 {
15236 dbton_id = share->use_sql_dbton_ids[roop_count];
15237 dbton_hdl = dbton_handler[dbton_id];
15238 if (
15239 dbton_hdl->first_link_idx >= 0 &&
15240 (error_num = dbton_hdl->append_update(table, ptr_diff))
15241 ) {
15242 DBUG_RETURN(error_num);
15243 }
15244 }
15245 if (!bulk)
15246 {
15247 DBUG_RETURN(0);
15248 }
15249
15250 for (
15251 roop_count = spider_conn_link_idx_next(share->link_statuses,
15252 conn_link_idx, -1, share->link_count,
15253 SPIDER_LINK_STATUS_RECOVERY);
15254 roop_count < share->link_count;
15255 roop_count = spider_conn_link_idx_next(share->link_statuses,
15256 conn_link_idx, roop_count, share->link_count,
15257 SPIDER_LINK_STATUS_RECOVERY)
15258 ) {
15259 dbton_id = share->sql_dbton_ids[conn_link_idx[roop_count]];
15260 dbton_hdl = dbton_handler[dbton_id];
15261 if (
15262 dbton_hdl->first_link_idx >= 0 &&
15263 dbton_hdl->need_copy_for_update(roop_count)
15264 ) {
15265 if ((error_num = dbton_hdl->append_update(table, ptr_diff, roop_count)))
15266 {
15267 DBUG_RETURN(error_num);
15268 }
15269 }
15270 }
15271 DBUG_RETURN(0);
15272}
15273
15274int ha_spider::append_delete_sql(
15275 const TABLE *table,
15276 my_ptrdiff_t ptr_diff,
15277 bool bulk
15278) {
15279 int error_num;
15280 uint roop_count, dbton_id;
15281 spider_db_handler *dbton_hdl;
15282 DBUG_ENTER("ha_spider::append_delete");
15283 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15284 {
15285 dbton_id = share->use_sql_dbton_ids[roop_count];
15286 dbton_hdl = dbton_handler[dbton_id];
15287 if (
15288 dbton_hdl->first_link_idx >= 0 &&
15289 (error_num = dbton_hdl->append_delete(table, ptr_diff))
15290 ) {
15291 DBUG_RETURN(error_num);
15292 }
15293 }
15294 if (!bulk)
15295 {
15296 DBUG_RETURN(0);
15297 }
15298
15299 for (
15300 roop_count = spider_conn_link_idx_next(share->link_statuses,
15301 conn_link_idx, -1, share->link_count, SPIDER_LINK_STATUS_RECOVERY);
15302 roop_count < share->link_count;
15303 roop_count = spider_conn_link_idx_next(share->link_statuses,
15304 conn_link_idx, roop_count, share->link_count,
15305 SPIDER_LINK_STATUS_RECOVERY)
15306 ) {
15307 dbton_id = share->sql_dbton_ids[conn_link_idx[roop_count]];
15308 dbton_hdl = dbton_handler[dbton_id];
15309 if (
15310 dbton_hdl->first_link_idx >= 0 &&
15311 dbton_hdl->need_copy_for_update(roop_count)
15312 ) {
15313 if ((error_num = dbton_hdl->append_delete(table, ptr_diff, roop_count)))
15314 {
15315 DBUG_RETURN(error_num);
15316 }
15317 }
15318 }
15319 DBUG_RETURN(0);
15320}
15321
15322bool ha_spider::sql_is_filled_up(
15323 ulong sql_type
15324) {
15325 uint roop_count, dbton_id;
15326 spider_db_handler *dbton_hdl;
15327 DBUG_ENTER("ha_spider::sql_is_filled_up");
15328 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15329 {
15330 dbton_id = share->use_sql_dbton_ids[roop_count];
15331 dbton_hdl = dbton_handler[dbton_id];
15332 if (
15333 dbton_hdl->first_link_idx >= 0 &&
15334 dbton_hdl->sql_is_filled_up(sql_type)
15335 ) {
15336 DBUG_RETURN(TRUE);
15337 }
15338 }
15339 DBUG_RETURN(FALSE);
15340}
15341
15342bool ha_spider::sql_is_empty(
15343 ulong sql_type
15344) {
15345 uint roop_count, dbton_id;
15346 spider_db_handler *dbton_hdl;
15347 DBUG_ENTER("ha_spider::sql_is_empty");
15348 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15349 {
15350 dbton_id = share->use_sql_dbton_ids[roop_count];
15351 dbton_hdl = dbton_handler[dbton_id];
15352 if (
15353 dbton_hdl->first_link_idx >= 0 &&
15354 !dbton_hdl->sql_is_empty(sql_type)
15355 ) {
15356 DBUG_RETURN(FALSE);
15357 }
15358 }
15359 DBUG_RETURN(TRUE);
15360}
15361
15362bool ha_spider::support_multi_split_read_sql()
15363{
15364 uint roop_count, dbton_id;
15365 spider_db_handler *dbton_hdl;
15366 DBUG_ENTER("ha_spider::support_multi_split_read_sql");
15367 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15368 {
15369 dbton_id = share->use_sql_dbton_ids[roop_count];
15370 dbton_hdl = dbton_handler[dbton_id];
15371 if (
15372 dbton_hdl->first_link_idx >= 0 &&
15373 !dbton_hdl->support_multi_split_read()
15374 ) {
15375 DBUG_RETURN(FALSE);
15376 }
15377 }
15378 DBUG_RETURN(TRUE);
15379}
15380
15381bool ha_spider::support_bulk_update_sql()
15382{
15383 uint roop_count, dbton_id;
15384 spider_db_handler *dbton_hdl;
15385 DBUG_ENTER("ha_spider::support_bulk_update_sql");
15386 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15387 {
15388 dbton_id = share->use_sql_dbton_ids[roop_count];
15389 dbton_hdl = dbton_handler[dbton_id];
15390 if (
15391 dbton_hdl->first_link_idx >= 0 &&
15392 !dbton_hdl->support_bulk_update()
15393 ) {
15394 DBUG_RETURN(FALSE);
15395 }
15396 }
15397 DBUG_RETURN(TRUE);
15398}
15399
15400int ha_spider::bulk_tmp_table_insert()
15401{
15402 int error_num;
15403 uint roop_count, dbton_id;
15404 spider_db_handler *dbton_hdl;
15405 TABLE **tmp_table = result_list.upd_tmp_tbls;
15406 DBUG_ENTER("ha_spider::bulk_tmp_table_insert");
15407 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15408 {
15409 dbton_id = share->use_sql_dbton_ids[roop_count];
15410 dbton_hdl = dbton_handler[dbton_id];
15411 if (
15412 dbton_hdl->first_link_idx >= 0 &&
15413 (error_num = dbton_hdl->bulk_tmp_table_insert())
15414 ) {
15415 DBUG_RETURN(error_num);
15416 }
15417 }
15418
15419 for (roop_count = 0; roop_count < share->link_count; roop_count++)
15420 {
15421 if (tmp_table[roop_count])
15422 {
15423 dbton_id = share->sql_dbton_ids[conn_link_idx[roop_count]];
15424 dbton_hdl = dbton_handler[dbton_id];
15425 if (
15426 dbton_hdl->first_link_idx >= 0 &&
15427 (error_num = dbton_hdl->bulk_tmp_table_insert(roop_count))
15428 ) {
15429 DBUG_RETURN(error_num);
15430 }
15431 }
15432 }
15433 DBUG_RETURN(0);
15434}
15435
15436int ha_spider::bulk_tmp_table_end_bulk_insert()
15437{
15438 int error_num = 0, error_num2;
15439 uint roop_count, dbton_id;
15440 spider_db_handler *dbton_hdl;
15441 TABLE **tmp_table = result_list.upd_tmp_tbls;
15442 DBUG_ENTER("ha_spider::bulk_tmp_table_end_bulk_insert");
15443 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15444 {
15445 dbton_id = share->use_sql_dbton_ids[roop_count];
15446 dbton_hdl = dbton_handler[dbton_id];
15447 if (
15448 dbton_hdl->first_link_idx >= 0 &&
15449 (error_num2 = dbton_hdl->bulk_tmp_table_end_bulk_insert())
15450 ) {
15451 error_num = error_num2;
15452 }
15453 }
15454
15455 for (roop_count = 0; roop_count < share->link_count; roop_count++)
15456 {
15457 if (tmp_table[roop_count])
15458 {
15459 if (
15460 (error_num2 = tmp_table[roop_count]->file->ha_end_bulk_insert())
15461 ) {
15462 error_num = error_num2;
15463 }
15464 }
15465 }
15466 DBUG_RETURN(error_num);
15467}
15468
15469int ha_spider::bulk_tmp_table_rnd_init()
15470{
15471 int error_num;
15472 uint roop_count, dbton_id;
15473 spider_db_handler *dbton_hdl;
15474 TABLE **tmp_table = result_list.upd_tmp_tbls;
15475 DBUG_ENTER("ha_spider::bulk_tmp_table_rnd_init");
15476 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15477 {
15478 dbton_id = share->use_sql_dbton_ids[roop_count];
15479 dbton_hdl = dbton_handler[dbton_id];
15480 if (
15481 dbton_hdl->first_link_idx >= 0 &&
15482 (error_num = dbton_hdl->bulk_tmp_table_rnd_init())
15483 ) {
15484 goto error_1;
15485 }
15486 }
15487
15488 for (roop_count = 0; roop_count < share->link_count; roop_count++)
15489 {
15490 if (tmp_table[roop_count])
15491 {
15492 tmp_table[roop_count]->file->extra(HA_EXTRA_CACHE);
15493 if (
15494 (error_num = tmp_table[roop_count]->file->ha_rnd_init(TRUE))
15495 )
15496 goto error_2;
15497 }
15498 }
15499 DBUG_RETURN(0);
15500
15501error_2:
15502 for (; roop_count > 0; roop_count--)
15503 {
15504 if (tmp_table[roop_count - 1])
15505 {
15506 tmp_table[roop_count - 1]->file->ha_rnd_end();
15507 }
15508 }
15509 roop_count = share->use_sql_dbton_count;
15510error_1:
15511 for (; roop_count > 0; roop_count--)
15512 {
15513 dbton_id = share->use_sql_dbton_ids[roop_count - 1];
15514 dbton_hdl = dbton_handler[dbton_id];
15515 if (dbton_hdl->first_link_idx >= 0)
15516 dbton_hdl->bulk_tmp_table_rnd_end();
15517 }
15518 DBUG_RETURN(error_num);
15519}
15520
15521int ha_spider::bulk_tmp_table_rnd_next()
15522{
15523 int error_num;
15524 uint roop_count, dbton_id;
15525 spider_db_handler *dbton_hdl;
15526 TABLE **tmp_table = result_list.upd_tmp_tbls;
15527 DBUG_ENTER("ha_spider::bulk_tmp_table_rnd_next");
15528 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15529 {
15530 dbton_id = share->use_sql_dbton_ids[roop_count];
15531 dbton_hdl = dbton_handler[dbton_id];
15532 if (
15533 dbton_hdl->first_link_idx >= 0 &&
15534 (error_num = dbton_hdl->bulk_tmp_table_rnd_next())
15535 ) {
15536 DBUG_RETURN(error_num);
15537 }
15538 }
15539
15540 for (roop_count = 0; roop_count < share->link_count; roop_count++)
15541 {
15542 if (tmp_table[roop_count])
15543 {
15544 if (
15545#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
15546 !(error_num = tmp_table[roop_count]->file->ha_rnd_next(
15547 tmp_table[roop_count]->record[0]))
15548#else
15549 !(error_num = tmp_table[roop_count]->file->rnd_next(
15550 tmp_table[roop_count]->record[0]))
15551#endif
15552 ) {
15553 DBUG_RETURN(error_num);
15554 }
15555 }
15556 }
15557 DBUG_RETURN(0);
15558}
15559
15560int ha_spider::bulk_tmp_table_rnd_end()
15561{
15562 int error_num = 0, error_num2;
15563 uint roop_count, dbton_id;
15564 spider_db_handler *dbton_hdl;
15565 TABLE **tmp_table = result_list.upd_tmp_tbls;
15566 DBUG_ENTER("ha_spider::bulk_tmp_table_rnd_end");
15567 for (roop_count = share->link_count; roop_count > 0; roop_count--)
15568 {
15569 if (tmp_table[roop_count - 1])
15570 {
15571 if ((error_num2 = tmp_table[roop_count - 1]->file->ha_rnd_end()))
15572 {
15573 error_num = error_num2;
15574 }
15575 }
15576 }
15577
15578 for (roop_count = share->use_sql_dbton_count; roop_count > 0; roop_count--)
15579 {
15580 dbton_id = share->use_sql_dbton_ids[roop_count - 1];
15581 dbton_hdl = dbton_handler[dbton_id];
15582 if (
15583 dbton_hdl->first_link_idx >= 0 &&
15584 (error_num2 = dbton_hdl->bulk_tmp_table_rnd_end())
15585 ) {
15586 error_num = error_num2;
15587 }
15588 }
15589 DBUG_RETURN(error_num);
15590}
15591
15592int ha_spider::mk_bulk_tmp_table_and_bulk_start()
15593{
15594 int error_num;
15595 uint roop_count, dbton_id;
15596 spider_db_handler *dbton_hdl;
15597 TABLE **tmp_table = result_list.upd_tmp_tbls;
15598 DBUG_ENTER("ha_spider::mk_bulk_tmp_table_and_bulk_start");
15599 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15600 {
15601 dbton_id = share->use_sql_dbton_ids[roop_count];
15602 dbton_hdl = dbton_handler[dbton_id];
15603 if (dbton_hdl->first_link_idx >= 0)
15604 {
15605 if (dbton_hdl->bulk_tmp_table_created())
15606 {
15607 DBUG_RETURN(0);
15608 } else {
15609 break;
15610 }
15611 }
15612 }
15613
15614 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15615 {
15616 dbton_id = share->use_sql_dbton_ids[roop_count];
15617 dbton_hdl = dbton_handler[dbton_id];
15618 if (
15619 dbton_hdl->first_link_idx >= 0 &&
15620 (error_num = dbton_hdl->mk_bulk_tmp_table_and_bulk_start())
15621 ) {
15622 goto error_1;
15623 }
15624 }
15625
15626 for (roop_count = 0; roop_count < share->link_count; roop_count++)
15627 {
15628 dbton_id = share->sql_dbton_ids[conn_link_idx[roop_count]];
15629 dbton_hdl = dbton_handler[dbton_id];
15630 if (
15631 dbton_hdl->first_link_idx >= 0 &&
15632 dbton_hdl->need_copy_for_update(roop_count)
15633 ) {
15634 if (
15635 !tmp_table[roop_count] &&
15636 !(tmp_table[roop_count] = spider_mk_sys_tmp_table(
15637 trx->thd, table, &result_list.upd_tmp_tbl_prms[roop_count], "a",
15638 result_list.update_sqls[roop_count].charset()))
15639 ) {
15640 error_num = HA_ERR_OUT_OF_MEM;
15641 goto error_2;
15642 }
15643 tmp_table[roop_count]->file->extra(HA_EXTRA_WRITE_CACHE);
15644 tmp_table[roop_count]->file->ha_start_bulk_insert((ha_rows) 0);
15645 }
15646 }
15647 DBUG_RETURN(0);
15648
15649error_2:
15650 for (; roop_count > 0; roop_count--)
15651 {
15652 if (tmp_table[roop_count - 1])
15653 {
15654 tmp_table[roop_count - 1]->file->ha_end_bulk_insert();
15655 spider_rm_sys_tmp_table(trx->thd, tmp_table[roop_count - 1],
15656 &result_list.upd_tmp_tbl_prms[roop_count - 1]);
15657 tmp_table[roop_count - 1] = NULL;
15658 }
15659 }
15660 roop_count = share->use_sql_dbton_count;
15661error_1:
15662 for (; roop_count > 0; roop_count--)
15663 {
15664 dbton_id = share->use_sql_dbton_ids[roop_count - 1];
15665 if (dbton_hdl->first_link_idx >= 0)
15666 {
15667 dbton_handler[dbton_id]->bulk_tmp_table_end_bulk_insert();
15668 dbton_handler[dbton_id]->rm_bulk_tmp_table();
15669 }
15670 }
15671 DBUG_RETURN(error_num);
15672}
15673
15674void ha_spider::rm_bulk_tmp_table()
15675{
15676 uint roop_count, dbton_id;
15677 TABLE **tmp_table = result_list.upd_tmp_tbls;
15678 spider_db_handler *dbton_hdl;
15679 DBUG_ENTER("ha_spider::bulk_tmp_table_rnd_end");
15680 for (roop_count = share->link_count; roop_count > 0; roop_count--)
15681 {
15682 if (tmp_table[roop_count - 1])
15683 {
15684 spider_rm_sys_tmp_table(trx->thd, tmp_table[roop_count - 1],
15685 &result_list.upd_tmp_tbl_prms[roop_count - 1]);
15686 tmp_table[roop_count - 1] = NULL;
15687 }
15688 }
15689
15690 for (roop_count = share->use_sql_dbton_count; roop_count > 0; roop_count--)
15691 {
15692 dbton_id = share->use_sql_dbton_ids[roop_count - 1];
15693 dbton_hdl = dbton_handler[dbton_id];
15694 if (dbton_hdl->first_link_idx >= 0)
15695 dbton_hdl->rm_bulk_tmp_table();
15696 }
15697 DBUG_VOID_RETURN;
15698}
15699
15700bool ha_spider::bulk_tmp_table_created()
15701{
15702 uint roop_count, dbton_id;
15703 spider_db_handler *dbton_hdl;
15704 DBUG_ENTER("ha_spider::bulk_tmp_table_created");
15705 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15706 {
15707 dbton_id = share->use_sql_dbton_ids[roop_count];
15708 dbton_hdl = dbton_handler[dbton_id];
15709 if (dbton_hdl->first_link_idx >= 0)
15710 {
15711 if (dbton_hdl->bulk_tmp_table_created())
15712 {
15713 DBUG_RETURN(TRUE);
15714 }
15715 }
15716 }
15717 DBUG_RETURN(FALSE);
15718}
15719
15720int ha_spider::print_item_type(
15721 Item *item,
15722 spider_string *str,
15723 const char *alias,
15724 uint alias_length
15725) {
15726 int error_num;
15727 uint roop_count, dbton_id;
15728 spider_db_handler *dbton_hdl;
15729 DBUG_ENTER("ha_spider::print_item_type");
15730 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15731 {
15732 dbton_id = share->use_sql_dbton_ids[roop_count];
15733 dbton_hdl = dbton_handler[dbton_id];
15734 if (
15735 dbton_hdl->first_link_idx >= 0 &&
15736 (error_num = spider_db_print_item_type(item, this, str,
15737 alias, alias_length, dbton_id, FALSE, NULL))
15738 ) {
15739 DBUG_RETURN(error_num);
15740 }
15741 }
15742 DBUG_RETURN(0);
15743}
15744
15745bool ha_spider::support_use_handler_sql(
15746 int use_handler
15747) {
15748 uint roop_count, dbton_id;
15749 spider_db_handler *dbton_hdl;
15750 DBUG_ENTER("ha_spider::support_use_handler_sql");
15751 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15752 {
15753 dbton_id = share->use_sql_dbton_ids[roop_count];
15754 dbton_hdl = dbton_handler[dbton_id];
15755 if (
15756 dbton_hdl->first_link_idx >= 0 &&
15757 !dbton_hdl->support_use_handler(use_handler)
15758 ) {
15759 DBUG_RETURN(FALSE);
15760 }
15761 }
15762 DBUG_RETURN(TRUE);
15763}
15764
15765#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
15766bool ha_spider::support_bulk_access_hs() const
15767{
15768 uint roop_count;
15769 DBUG_ENTER("ha_spider::support_bulk_access_hs");
15770 if (!share)
15771 DBUG_RETURN(FALSE);
15772 for (roop_count = 0; roop_count < share->all_link_count; roop_count++)
15773 {
15774 if (share->hs_dbton_ids[roop_count] == SPIDER_DBTON_SIZE)
15775 DBUG_RETURN(FALSE);
15776 }
15777 DBUG_RETURN(TRUE);
15778}
15779#endif
15780
15781int ha_spider::init_union_table_name_pos_sql()
15782{
15783 int error_num;
15784 uint roop_count, dbton_id;
15785 spider_db_handler *dbton_hdl;
15786 DBUG_ENTER("ha_spider::init_union_table_name_pos_sql");
15787 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15788 {
15789 dbton_id = share->use_sql_dbton_ids[roop_count];
15790 dbton_hdl = dbton_handler[dbton_id];
15791 if (
15792 dbton_hdl->first_link_idx >= 0 &&
15793 (error_num = dbton_hdl->init_union_table_name_pos())
15794 ) {
15795 DBUG_RETURN(error_num);
15796 }
15797 }
15798 DBUG_RETURN(0);
15799}
15800
15801int ha_spider::set_union_table_name_pos_sql()
15802{
15803 int error_num;
15804 uint roop_count, dbton_id;
15805 spider_db_handler *dbton_hdl;
15806 DBUG_ENTER("ha_spider::set_union_table_name_pos_sql");
15807 for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
15808 {
15809 dbton_id = share->use_sql_dbton_ids[roop_count];
15810 dbton_hdl = dbton_handler[dbton_id];
15811 if (
15812 dbton_hdl->first_link_idx >= 0 &&
15813 (error_num = dbton_hdl->set_union_table_name_pos())
15814 ) {
15815 DBUG_RETURN(error_num);
15816 }
15817 }
15818 DBUG_RETURN(0);
15819}
15820