1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
|
/* Copyright (C) 2008-2019 Kentoku Shiba
Copyright (C) 2019-2022 MariaDB corp
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
/*
Structure used to manage Spider parameter string parsing. Types of
parameters include:
- connection strings
- UDF parameters
A parameter string consists of one or more parameter definitions using
the following syntax:
<parameter title> <parameter value>
A comma is the separator character between multiple parameter definitions.
Parameter titles must not be quoted. Parameter values must be quoted with
single or double quotes.
*/
typedef struct st_spider_param_string_parse
{
char *start_ptr; /* Pointer to the start of the parameter string */
char *end_ptr; /* Pointer to the end of the parameter string */
char *start_title_ptr; /* Pointer to the start of the current parameter
title */
char *end_title_ptr; /* Pointer to the end of the current parameter
title */
char *start_value_ptr; /* Pointer to the start of the current parameter
value */
char *end_value_ptr; /* Pointer to the end of the current parameter
value */
int error_num; /* Error code of the error message to print when
an error is detected */
uint delim_title_len; /* Length of the paramater title's delimiter */
uint delim_value_len; /* Length of the paramater value's delimiter */
char delim_title; /* Current parameter title's delimiter character */
char delim_value; /* Current parameter value's delimiter character */
/**
Initialize the parameter string parse information.
@param param_string Pointer to the parameter string being parsed.
@param error_code Error code of the error message to print when
an error is detected.
*/
inline void init(char *param_string, int error_code)
{
start_ptr = param_string;
end_ptr = start_ptr + strlen(start_ptr);
init_param_title();
init_param_value();
error_num = error_code;
}
/**
Initialize the current parameter title.
*/
inline void init_param_title()
{
start_title_ptr = end_title_ptr = NULL;
delim_title_len = 0;
delim_title = '\0';
}
/**
Save pointers to the start and end positions of the current parameter
title in the parameter string. Also save the parameter title's
delimiter character.
@param start_value Pointer to the start position of the current
parameter title.
@param end_value Pointer to the end position of the current
parameter title.
*/
inline void set_param_title(char *start_title, char *end_title)
{
start_title_ptr = start_title;
end_title_ptr = end_title;
if (*start_title == '"' ||
*start_title == '\'')
{
delim_title = *start_title;
if (start_title >= start_ptr && *--start_title == '\\')
delim_title_len = 2;
else
delim_title_len = 1;
}
}
/**
Initialize the current parameter value.
*/
inline void init_param_value()
{
start_value_ptr = end_value_ptr = NULL;
delim_value_len = 0;
delim_value = '\0';
}
/**
Save pointers to the start and end positions of the current parameter
value in the parameter string. Also save the parameter value's
delimiter character.
@param start_value Pointer to the start position of the current
parameter value.
@param end_value Pointer to the end position of the current
parameter value.
*/
inline void set_param_value(char *start_value, char *end_value)
{
start_value_ptr = start_value--;
end_value_ptr = end_value;
if (*start_value == '"' ||
*start_value == '\'')
{
delim_value = *start_value;
if (*--start_value == '\\')
delim_value_len = 2;
else
delim_value_len = 1;
}
}
/**
Determine whether the current parameter in the parameter string has
extra parameter values.
@return 0 Current parameter value in the parameter string
does not have extra parameter values.
<> 0 Error code indicating that the current parameter
value in the parameter string has extra
parameter values.
*/
inline int has_extra_parameter_values()
{
int error_num = 0;
DBUG_ENTER("has_extra_parameter_values");
if (end_value_ptr)
{
/* There is a current parameter value */
char *end_param_ptr = end_value_ptr;
while (end_param_ptr < end_ptr &&
(*end_param_ptr == ' ' || *end_param_ptr == '\r' ||
*end_param_ptr == '\n' || *end_param_ptr == '\t'))
end_param_ptr++;
if (end_param_ptr < end_ptr && *end_param_ptr != '\0')
{
/* Extra values in parameter definition */
error_num = print_param_error();
}
}
DBUG_RETURN(error_num);
}
inline int get_next_parameter_head(char *st, char **nx)
{
DBUG_ENTER("get_next_parameter_head");
char *sq = strchr(st, '\'');
char *dq = strchr(st, '"');
if (!sq && !dq)
{
DBUG_RETURN(print_param_error());
}
if (dq && (!sq || sq > dq))
{
while (1)
{
++dq;
if (*dq == '\\')
{
++dq;
}
else if (*dq == '"')
{
break;
}
else if (*dq == '\0')
{
DBUG_RETURN(print_param_error());
}
}
while (1)
{
++dq;
if (*dq == '\0')
{
*nx = dq;
break;
}
else if (*dq == ',')
{
*dq = '\0';
*nx = dq + 1;
break;
}
else if (*dq != ' ' && *dq != '\r' && *dq != '\n' && *dq != '\t')
{
DBUG_RETURN(print_param_error());
}
}
}
else /* sq && (!dq || sq <= dq) */
{
while (1)
{
++sq;
if (*sq == '\\')
{
++sq;
}
else if (*sq == '\'')
{
break;
}
else if (*sq == '\0')
{
DBUG_RETURN(print_param_error());
}
}
while (1)
{
++sq;
if (*sq == '\0')
{
*nx = sq;
break;
}
else if (*sq == ',')
{
*sq = '\0';
*nx = sq + 1;
break;
}
else if (*sq != ' ' && *sq != '\r' && *sq != '\n' && *sq != '\t')
{
DBUG_RETURN(print_param_error());
}
}
}
DBUG_RETURN(0);
}
/**
Restore the current parameter's input delimiter characters in the
parameter string. They were NULLed during parameter parsing.
*/
inline void restore_delims()
{
char *end = end_title_ptr - 1;
switch (delim_title_len)
{
case 2:
*end++ = '\\';
/* Fall through */
case 1:
*end = delim_title;
}
end = end_value_ptr - 1;
switch (delim_value_len)
{
case 2:
*end++ = '\\';
/* Fall through */
case 1:
*end = delim_value;
}
}
/**
Print a parameter string error message.
@return Error code.
*/
int print_param_error();
} SPIDER_PARAM_STRING_PARSE;
uchar *spider_tbl_get_key(
SPIDER_SHARE *share,
size_t *length,
my_bool not_used __attribute__ ((unused))
);
uchar *spider_wide_share_get_key(
SPIDER_WIDE_SHARE *share,
size_t *length,
my_bool not_used __attribute__ ((unused))
);
uchar *spider_link_get_key(
SPIDER_LINK_FOR_HASH *link_for_hash,
size_t *length,
my_bool not_used __attribute__ ((unused))
);
uchar *spider_ha_get_key(
ha_spider *spider,
size_t *length,
my_bool not_used __attribute__ ((unused))
);
int spider_get_server(
SPIDER_SHARE *share,
int link_idx
);
int spider_free_share_alloc(
SPIDER_SHARE *share
);
void spider_free_tmp_share_alloc(
SPIDER_SHARE *share
);
char *spider_get_string_between_quote(
char *ptr,
bool alloc,
SPIDER_PARAM_STRING_PARSE *param_string_parse = NULL
);
int spider_create_string_list(
char ***string_list,
uint **string_length_list,
uint *list_length,
char *str,
uint length,
SPIDER_PARAM_STRING_PARSE *param_string_parse
);
int spider_create_long_list(
long **long_list,
uint *list_length,
char *str,
uint length,
long min_val,
long max_val,
SPIDER_PARAM_STRING_PARSE *param_string_parse
);
int spider_create_longlong_list(
longlong **longlong_list,
uint *list_length,
char *str,
uint length,
longlong min_val,
longlong max_val,
SPIDER_PARAM_STRING_PARSE *param_string_parse
);
int spider_increase_string_list(
char ***string_list,
uint **string_length_list,
uint *list_length,
uint *list_charlen,
uint link_count
);
int spider_increase_long_list(
long **long_list,
uint *list_length,
uint link_count
);
int spider_increase_longlong_list(
longlong **longlong_list,
uint *list_length,
uint link_count
);
int spider_parse_connect_info(
SPIDER_SHARE *share,
TABLE_SHARE *table_share,
#ifdef WITH_PARTITION_STORAGE_ENGINE
partition_info *part_info,
#endif
uint create_table
);
int spider_set_connect_info_default(
SPIDER_SHARE *share,
#ifdef WITH_PARTITION_STORAGE_ENGINE
partition_element *part_elem,
partition_element *sub_elem,
#endif
TABLE_SHARE *table_share
);
int spider_set_connect_info_default_db_table(
SPIDER_SHARE *share,
const char *db_name,
uint db_name_length,
const char *table_name,
uint table_name_length
);
int spider_set_connect_info_default_dbtable(
SPIDER_SHARE *share,
const char *dbtable_name,
int dbtable_name_length
);
#ifndef DBUG_OFF
void spider_print_keys(
const char *key,
uint length
);
#endif
int spider_create_conn_keys(
SPIDER_SHARE *share
);
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share(
const char *table_name,
uint table_name_length,
my_hash_value_type hash_value,
bool locked,
bool need_to_create,
int *error_num
);
#else
SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share(
const char *table_name,
uint table_name_length,
bool locked,
bool need_to_create,
int *error_num
);
#endif
void spider_free_lgtm_tblhnd_share_alloc(
SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share,
bool locked
);
SPIDER_SHARE *spider_create_share(
const char *table_name,
TABLE_SHARE *table_share,
#ifdef WITH_PARTITION_STORAGE_ENGINE
partition_info *part_info,
#endif
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type hash_value,
#endif
int *error_num
);
SPIDER_SHARE *spider_get_share(
const char *table_name,
TABLE *table,
THD *thd,
ha_spider *spider,
int *error_num
);
void spider_free_share_resource_only(
SPIDER_SHARE *share
);
int spider_free_share(
SPIDER_SHARE *share
);
void spider_update_link_status_for_share(
const char *table_name,
uint table_name_length,
int link_idx,
long link_status
);
SPIDER_WIDE_SHARE *spider_get_wide_share(
SPIDER_SHARE *share,
TABLE_SHARE *table_share,
int *error_num
);
int spider_free_wide_share(
SPIDER_WIDE_SHARE *wide_share
);
void spider_copy_sts_to_wide_share(
SPIDER_WIDE_SHARE *wide_share,
SPIDER_SHARE *share
);
void spider_copy_sts_to_share(
SPIDER_SHARE *share,
SPIDER_WIDE_SHARE *wide_share
);
void spider_copy_crd_to_wide_share(
SPIDER_WIDE_SHARE *wide_share,
SPIDER_SHARE *share,
int fields
);
void spider_copy_crd_to_share(
SPIDER_SHARE *share,
SPIDER_WIDE_SHARE *wide_share,
int fields
);
int spider_open_all_tables(
SPIDER_TRX *trx,
bool lock
);
bool spider_flush_logs(
handlerton *hton
);
handler* spider_create_handler(
handlerton *hton,
TABLE_SHARE *table,
MEM_ROOT *mem_root
);
int spider_close_connection(
handlerton* hton,
THD* thd
);
void spider_drop_database(
handlerton *hton,
char* path
);
bool spider_show_status(
handlerton *hton,
THD *thd,
stat_print_fn *stat_print,
enum ha_stat_type stat_type
);
int spider_db_done(
void *p
);
int spider_panic(
handlerton *hton,
ha_panic_function type
);
int spider_db_init(
void *p
);
char *spider_create_table_name_string(
const char *table_name,
const char *part_name,
const char *sub_name
);
#ifdef WITH_PARTITION_STORAGE_ENGINE
void spider_get_partition_info(
const char *table_name,
uint table_name_length,
const TABLE_SHARE *table_share,
partition_info *part_info,
partition_element **part_elem,
partition_element **sub_elem
);
#endif
int spider_get_sts(
SPIDER_SHARE *share,
int link_idx,
time_t tmp_time,
ha_spider *spider,
double sts_interval,
int sts_mode,
#ifdef WITH_PARTITION_STORAGE_ENGINE
int sts_sync,
#endif
int sts_sync_level,
uint flag
);
int spider_get_crd(
SPIDER_SHARE *share,
int link_idx,
time_t tmp_time,
ha_spider *spider,
TABLE *table,
double crd_interval,
int crd_mode,
#ifdef WITH_PARTITION_STORAGE_ENGINE
int crd_sync,
#endif
int crd_sync_level
);
void spider_set_result_list_param(
ha_spider *spider
);
SPIDER_INIT_ERROR_TABLE *spider_get_init_error_table(
SPIDER_TRX *trx,
SPIDER_SHARE *share,
bool create
);
void spider_delete_init_error_table(
const char *name
);
bool spider_check_pk_update(
TABLE *table
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
bool spider_check_hs_pk_update(
ha_spider *spider,
key_range *key
);
#endif
#endif
void spider_set_tmp_share_pointer(
SPIDER_SHARE *tmp_share,
char **tmp_connect_info,
uint *tmp_connect_info_length,
long *tmp_long,
longlong *tmp_longlong
);
int spider_create_tmp_dbton_share(
SPIDER_SHARE *tmp_share
);
void spider_free_tmp_dbton_share(
SPIDER_SHARE *tmp_share
);
int spider_create_tmp_dbton_handler(
ha_spider *tmp_spider
);
void spider_free_tmp_dbton_handler(
ha_spider *tmp_spider
);
TABLE_LIST *spider_get_parent_table_list(
ha_spider *spider
);
List<Index_hint> *spider_get_index_hints(
ha_spider *spider
);
st_select_lex *spider_get_select_lex(
ha_spider *spider
);
void spider_get_select_limit_from_select_lex(
st_select_lex *select_lex,
longlong *select_limit,
longlong *offset_limit
);
void spider_get_select_limit(
ha_spider *spider,
st_select_lex **select_lex,
longlong *select_limit,
longlong *offset_limit
);
longlong spider_split_read_param(
ha_spider *spider
);
longlong spider_bg_split_read_param(
ha_spider *spider
);
void spider_first_split_read_param(
ha_spider *spider
);
void spider_next_split_read_param(
ha_spider *spider
);
bool spider_check_direct_order_limit(
ha_spider *spider
);
#ifdef HANDLER_HAS_DIRECT_AGGREGATE
bool spider_all_part_in_order(
ORDER *order,
TABLE *table
);
Field *spider_field_exchange(
handler *handler,
Field *field
);
#endif
int spider_set_direct_limit_offset(
ha_spider *spider
);
bool spider_check_index_merge(
TABLE *table,
st_select_lex *select_lex
);
int spider_compare_for_sort(
SPIDER_SORT *a,
SPIDER_SORT *b
);
ulong spider_calc_for_sort(
uint count,
...
);
double spider_rand(
uint32 rand_source
);
#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE
int spider_discover_table_structure_internal(
SPIDER_TRX *trx,
SPIDER_SHARE *spider_share,
spider_string *str
);
int spider_discover_table_structure(
handlerton *hton,
THD* thd,
TABLE_SHARE *share,
HA_CREATE_INFO *info
);
#endif
#ifndef WITHOUT_SPIDER_BG_SEARCH
int spider_create_spider_object_for_share(
SPIDER_TRX *trx,
SPIDER_SHARE *share,
ha_spider **spider
);
void spider_free_spider_object_for_share(
ha_spider **spider
);
int spider_create_sts_threads(
SPIDER_THREAD *spider_thread
);
void spider_free_sts_threads(
SPIDER_THREAD *spider_thread
);
int spider_create_crd_threads(
SPIDER_THREAD *spider_thread
);
void spider_free_crd_threads(
SPIDER_THREAD *spider_thread
);
void *spider_table_bg_sts_action(
void *arg
);
void *spider_table_bg_crd_action(
void *arg
);
void spider_table_add_share_to_sts_thread(
SPIDER_SHARE *share
);
void spider_table_add_share_to_crd_thread(
SPIDER_SHARE *share
);
void spider_table_remove_share_from_sts_thread(
SPIDER_SHARE *share
);
void spider_table_remove_share_from_crd_thread(
SPIDER_SHARE *share
);
#endif
uchar *spider_duplicate_char(
uchar *dst,
uchar esc,
uchar *src,
uint src_lgt
);
|