1 /*
2    Copyright (c) 2000, 2011, Oracle and/or its affiliates.
3    Copyright (c) 2008, 2021, MariaDB Corporation.
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; version 2 of the License.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335  USA */
17 
18 /**
19   @file
20 
21   @brief
22   Functions to create an item. Used by sql_yac.yy
23 */
24 
25 #include "mariadb.h"
26 #include "sql_priv.h"
27 /*
28   It is necessary to include set_var.h instead of item.h because there
29   are dependencies on include order for set_var.h and item.h. This
30   will be resolved later.
31 */
32 #include "sql_class.h"                          // set_var.h: THD
33 #include "set_var.h"
34 #include "sp_head.h"
35 #include "sp.h"
36 #include "sql_time.h"
37 #include "sql_type_geom.h"
38 #include <mysql/plugin_function.h>
39 
40 
41 extern "C" uchar*
get_native_fct_hash_key(const uchar * buff,size_t * length,my_bool)42 get_native_fct_hash_key(const uchar *buff, size_t *length,
43                         my_bool /* unused */)
44 {
45   Native_func_registry *func= (Native_func_registry*) buff;
46   *length= func->name.length;
47   return (uchar*) func->name.str;
48 }
49 
50 
append_to_hash(HASH * hash) const51 bool Native_func_registry_array::append_to_hash(HASH *hash) const
52 {
53   DBUG_ENTER("Native_func_registry_array::append_to_hash");
54   for (size_t i= 0; i < count(); i++)
55   {
56     const Native_func_registry &func= element(i);
57     DBUG_ASSERT(func.builder != NULL);
58     if (my_hash_insert(hash, (uchar*) &func))
59       DBUG_RETURN(true);
60   }
61   DBUG_RETURN(false);
62 }
63 
64 
65 #ifdef HAVE_SPATIAL
66 extern Native_func_registry_array native_func_registry_array_geom;
67 #endif
68 
69 
70 /*
71 =============================================================================
72   LOCAL DECLARATIONS
73 =============================================================================
74 */
75 
76 /**
77   Function builder for Stored Functions.
78 */
79 
80 class Create_sp_func : public Create_qfunc
81 {
82 public:
83   virtual Item *create_with_db(THD *thd, LEX_CSTRING *db, LEX_CSTRING *name,
84                                bool use_explicit_name, List<Item> *item_list);
85 
86   static Create_sp_func s_singleton;
87 
88 protected:
89   /** Constructor. */
Create_sp_func()90   Create_sp_func() {}
91   /** Destructor. */
~Create_sp_func()92   virtual ~Create_sp_func() {}
93 };
94 
95 
96 /*
97   Concrete functions builders (native functions).
98   Please keep this list sorted in alphabetical order,
99   it helps to compare code between versions, and helps with merges conflicts.
100 */
101 
102 class Create_func_abs : public Create_func_arg1
103 {
104 public:
105   virtual Item *create_1_arg(THD *thd, Item *arg1);
106 
107   static Create_func_abs s_singleton;
108 
109 protected:
Create_func_abs()110   Create_func_abs() {}
~Create_func_abs()111   virtual ~Create_func_abs() {}
112 };
113 
114 
115 class Create_func_acos : public Create_func_arg1
116 {
117 public:
118   virtual Item *create_1_arg(THD *thd, Item *arg1);
119 
120   static Create_func_acos s_singleton;
121 
122 protected:
Create_func_acos()123   Create_func_acos() {}
~Create_func_acos()124   virtual ~Create_func_acos() {}
125 };
126 
127 
128 class Create_func_addtime : public Create_func_arg2
129 {
130 public:
131   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
132 
133   static Create_func_addtime s_singleton;
134 
135 protected:
Create_func_addtime()136   Create_func_addtime() {}
~Create_func_addtime()137   virtual ~Create_func_addtime() {}
138 };
139 
140 
141 class Create_func_aes_encrypt : public Create_func_arg2
142 {
143 public:
144   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
145 
146   static Create_func_aes_encrypt s_singleton;
147 
148 protected:
Create_func_aes_encrypt()149   Create_func_aes_encrypt() {}
~Create_func_aes_encrypt()150   virtual ~Create_func_aes_encrypt() {}
151 };
152 
153 
154 class Create_func_aes_decrypt : public Create_func_arg2
155 {
156 public:
157   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
158 
159   static Create_func_aes_decrypt s_singleton;
160 
161 protected:
Create_func_aes_decrypt()162   Create_func_aes_decrypt() {}
~Create_func_aes_decrypt()163   virtual ~Create_func_aes_decrypt() {}
164 };
165 
166 
167 class Create_func_asin : public Create_func_arg1
168 {
169 public:
170   virtual Item *create_1_arg(THD *thd, Item *arg1);
171 
172   static Create_func_asin s_singleton;
173 
174 protected:
Create_func_asin()175   Create_func_asin() {}
~Create_func_asin()176   virtual ~Create_func_asin() {}
177 };
178 
179 
180 class Create_func_atan : public Create_native_func
181 {
182 public:
183   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
184 
185   static Create_func_atan s_singleton;
186 
187 protected:
Create_func_atan()188   Create_func_atan() {}
~Create_func_atan()189   virtual ~Create_func_atan() {}
190 };
191 
192 
193 class Create_func_benchmark : public Create_func_arg2
194 {
195 public:
196   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
197 
198   static Create_func_benchmark s_singleton;
199 
200 protected:
Create_func_benchmark()201   Create_func_benchmark() {}
~Create_func_benchmark()202   virtual ~Create_func_benchmark() {}
203 };
204 
205 
206 class Create_func_bin : public Create_func_arg1
207 {
208 public:
209   virtual Item *create_1_arg(THD *thd, Item *arg1);
210 
211   static Create_func_bin s_singleton;
212 
213 protected:
Create_func_bin()214   Create_func_bin() {}
~Create_func_bin()215   virtual ~Create_func_bin() {}
216 };
217 
218 
219 class Create_func_binlog_gtid_pos : public Create_func_arg2
220 {
221 public:
222   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
223 
224   static Create_func_binlog_gtid_pos s_singleton;
225 
226 protected:
Create_func_binlog_gtid_pos()227   Create_func_binlog_gtid_pos() {}
~Create_func_binlog_gtid_pos()228   virtual ~Create_func_binlog_gtid_pos() {}
229 };
230 
231 
232 class Create_func_bit_count : public Create_func_arg1
233 {
234 public:
235   virtual Item *create_1_arg(THD *thd, Item *arg1);
236 
237   static Create_func_bit_count s_singleton;
238 
239 protected:
Create_func_bit_count()240   Create_func_bit_count() {}
~Create_func_bit_count()241   virtual ~Create_func_bit_count() {}
242 };
243 
244 
245 class Create_func_bit_length : public Create_func_arg1
246 {
247 public:
248   virtual Item *create_1_arg(THD *thd, Item *arg1);
249 
250   static Create_func_bit_length s_singleton;
251 
252 protected:
Create_func_bit_length()253   Create_func_bit_length() {}
~Create_func_bit_length()254   virtual ~Create_func_bit_length() {}
255 };
256 
257 
258 class Create_func_ceiling : public Create_func_arg1
259 {
260 public:
261   virtual Item *create_1_arg(THD *thd, Item *arg1);
262 
263   static Create_func_ceiling s_singleton;
264 
265 protected:
Create_func_ceiling()266   Create_func_ceiling() {}
~Create_func_ceiling()267   virtual ~Create_func_ceiling() {}
268 };
269 
270 
271 class Create_func_chr : public Create_func_arg1
272 {
273 public:
274   virtual Item *create_1_arg(THD *thd, Item *arg1);
275 
276   static Create_func_chr s_singleton;
277 
278 protected:
Create_func_chr()279   Create_func_chr() {}
~Create_func_chr()280   virtual ~Create_func_chr() {}
281 };
282 
283 
284 class Create_func_char_length : public Create_func_arg1
285 {
286 public:
287   virtual Item *create_1_arg(THD *thd, Item *arg1);
288 
289   static Create_func_char_length s_singleton;
290 
291 protected:
Create_func_char_length()292   Create_func_char_length() {}
~Create_func_char_length()293   virtual ~Create_func_char_length() {}
294 };
295 
296 
297 class Create_func_coercibility : public Create_func_arg1
298 {
299 public:
300   virtual Item *create_1_arg(THD *thd, Item *arg1);
301 
302   static Create_func_coercibility s_singleton;
303 
304 protected:
Create_func_coercibility()305   Create_func_coercibility() {}
~Create_func_coercibility()306   virtual ~Create_func_coercibility() {}
307 };
308 
309 class Create_func_dyncol_check : public Create_func_arg1
310 {
311 public:
312   virtual Item *create_1_arg(THD *thd, Item *arg1);
313 
314   static Create_func_dyncol_check s_singleton;
315 
316 protected:
Create_func_dyncol_check()317   Create_func_dyncol_check() {}
~Create_func_dyncol_check()318   virtual ~Create_func_dyncol_check() {}
319 };
320 
321 class Create_func_dyncol_exists : public Create_func_arg2
322 {
323 public:
324   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
325 
326   static Create_func_dyncol_exists s_singleton;
327 
328 protected:
Create_func_dyncol_exists()329   Create_func_dyncol_exists() {}
~Create_func_dyncol_exists()330   virtual ~Create_func_dyncol_exists() {}
331 };
332 
333 class Create_func_dyncol_list : public Create_func_arg1
334 {
335 public:
336   virtual Item *create_1_arg(THD *thd, Item *arg1);
337 
338   static Create_func_dyncol_list s_singleton;
339 
340 protected:
Create_func_dyncol_list()341   Create_func_dyncol_list() {}
~Create_func_dyncol_list()342   virtual ~Create_func_dyncol_list() {}
343 };
344 
345 class Create_func_dyncol_json : public Create_func_arg1
346 {
347 public:
348   virtual Item *create_1_arg(THD *thd, Item *arg1);
349 
350   static Create_func_dyncol_json s_singleton;
351 
352 protected:
Create_func_dyncol_json()353   Create_func_dyncol_json() {}
~Create_func_dyncol_json()354   virtual ~Create_func_dyncol_json() {}
355 };
356 
357 
358 class Create_func_compress : public Create_func_arg1
359 {
360 public:
361   virtual Item *create_1_arg(THD *thd, Item *arg1);
362 
363   static Create_func_compress s_singleton;
364 
365 protected:
Create_func_compress()366   Create_func_compress() {}
~Create_func_compress()367   virtual ~Create_func_compress() {}
368 };
369 
370 
371 class Create_func_concat : public Create_native_func
372 {
373 public:
374   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
375 
376   static Create_func_concat s_singleton;
377 
378 protected:
Create_func_concat()379   Create_func_concat() {}
~Create_func_concat()380   virtual ~Create_func_concat() {}
381 };
382 
383 
384 class Create_func_concat_operator_oracle : public Create_native_func
385 {
386 public:
387   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
388 
389   static Create_func_concat_operator_oracle s_singleton;
390 
391 protected:
Create_func_concat_operator_oracle()392   Create_func_concat_operator_oracle() {}
~Create_func_concat_operator_oracle()393   virtual ~Create_func_concat_operator_oracle() {}
394 };
395 
396 
397 class Create_func_decode_histogram : public Create_func_arg2
398 {
399 public:
400   Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
401 
402   static Create_func_decode_histogram s_singleton;
403 
404 protected:
Create_func_decode_histogram()405   Create_func_decode_histogram() {}
~Create_func_decode_histogram()406   virtual ~Create_func_decode_histogram() {}
407 };
408 
409 
410 class Create_func_decode_oracle : public Create_native_func
411 {
412 public:
413   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
414 
415   static Create_func_decode_oracle s_singleton;
416 
417 protected:
Create_func_decode_oracle()418   Create_func_decode_oracle() {}
~Create_func_decode_oracle()419   virtual ~Create_func_decode_oracle() {}
420 };
421 
422 
423 class Create_func_concat_ws : public Create_native_func
424 {
425 public:
426   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
427 
428   static Create_func_concat_ws s_singleton;
429 
430 protected:
Create_func_concat_ws()431   Create_func_concat_ws() {}
~Create_func_concat_ws()432   virtual ~Create_func_concat_ws() {}
433 };
434 
435 
436 class Create_func_connection_id : public Create_func_arg0
437 {
438 public:
439   virtual Item *create_builder(THD *thd);
440 
441   static Create_func_connection_id s_singleton;
442 
443 protected:
Create_func_connection_id()444   Create_func_connection_id() {}
~Create_func_connection_id()445   virtual ~Create_func_connection_id() {}
446 };
447 
448 
449 class Create_func_nvl2 : public Create_func_arg3
450 {
451 public:
452   virtual Item *create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3);
453 
454   static Create_func_nvl2 s_singleton;
455 
456 protected:
Create_func_nvl2()457   Create_func_nvl2() {}
~Create_func_nvl2()458   virtual ~Create_func_nvl2() {}
459 };
460 
461 
462 class Create_func_conv : public Create_func_arg3
463 {
464 public:
465   virtual Item *create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3);
466 
467   static Create_func_conv s_singleton;
468 
469 protected:
Create_func_conv()470   Create_func_conv() {}
~Create_func_conv()471   virtual ~Create_func_conv() {}
472 };
473 
474 
475 class Create_func_convert_tz : public Create_func_arg3
476 {
477 public:
478   virtual Item *create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3);
479 
480   static Create_func_convert_tz s_singleton;
481 
482 protected:
Create_func_convert_tz()483   Create_func_convert_tz() {}
~Create_func_convert_tz()484   virtual ~Create_func_convert_tz() {}
485 };
486 
487 
488 class Create_func_cos : public Create_func_arg1
489 {
490 public:
491   virtual Item *create_1_arg(THD *thd, Item *arg1);
492 
493   static Create_func_cos s_singleton;
494 
495 protected:
Create_func_cos()496   Create_func_cos() {}
~Create_func_cos()497   virtual ~Create_func_cos() {}
498 };
499 
500 
501 class Create_func_cot : public Create_func_arg1
502 {
503 public:
504   virtual Item *create_1_arg(THD *thd, Item *arg1);
505 
506   static Create_func_cot s_singleton;
507 
508 protected:
Create_func_cot()509   Create_func_cot() {}
~Create_func_cot()510   virtual ~Create_func_cot() {}
511 };
512 
513 
514 class Create_func_crc32 : public Create_func_arg1
515 {
516 public:
517   virtual Item *create_1_arg(THD *thd, Item *arg1);
518 
519   static Create_func_crc32 s_singleton;
520 
521 protected:
Create_func_crc32()522   Create_func_crc32() {}
~Create_func_crc32()523   virtual ~Create_func_crc32() {}
524 };
525 
526 
527 class Create_func_datediff : public Create_func_arg2
528 {
529 public:
530   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
531 
532   static Create_func_datediff s_singleton;
533 
534 protected:
Create_func_datediff()535   Create_func_datediff() {}
~Create_func_datediff()536   virtual ~Create_func_datediff() {}
537 };
538 
539 
540 class Create_func_dayname : public Create_func_arg1
541 {
542 public:
543   virtual Item *create_1_arg(THD *thd, Item *arg1);
544 
545   static Create_func_dayname s_singleton;
546 
547 protected:
Create_func_dayname()548   Create_func_dayname() {}
~Create_func_dayname()549   virtual ~Create_func_dayname() {}
550 };
551 
552 
553 class Create_func_dayofmonth : public Create_func_arg1
554 {
555 public:
556   virtual Item *create_1_arg(THD *thd, Item *arg1);
557 
558   static Create_func_dayofmonth s_singleton;
559 
560 protected:
Create_func_dayofmonth()561   Create_func_dayofmonth() {}
~Create_func_dayofmonth()562   virtual ~Create_func_dayofmonth() {}
563 };
564 
565 
566 class Create_func_dayofweek : public Create_func_arg1
567 {
568 public:
569   virtual Item *create_1_arg(THD *thd, Item *arg1);
570 
571   static Create_func_dayofweek s_singleton;
572 
573 protected:
Create_func_dayofweek()574   Create_func_dayofweek() {}
~Create_func_dayofweek()575   virtual ~Create_func_dayofweek() {}
576 };
577 
578 
579 class Create_func_dayofyear : public Create_func_arg1
580 {
581 public:
582   virtual Item *create_1_arg(THD *thd, Item *arg1);
583 
584   static Create_func_dayofyear s_singleton;
585 
586 protected:
Create_func_dayofyear()587   Create_func_dayofyear() {}
~Create_func_dayofyear()588   virtual ~Create_func_dayofyear() {}
589 };
590 
591 
592 class Create_func_degrees : public Create_func_arg1
593 {
594 public:
595   virtual Item *create_1_arg(THD *thd, Item *arg1);
596 
597   static Create_func_degrees s_singleton;
598 
599 protected:
Create_func_degrees()600   Create_func_degrees() {}
~Create_func_degrees()601   virtual ~Create_func_degrees() {}
602 };
603 
604 
605 class Create_func_des_decrypt : public Create_native_func
606 {
607 public:
608   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
609 
610   static Create_func_des_decrypt s_singleton;
611 
612 protected:
Create_func_des_decrypt()613   Create_func_des_decrypt() {}
~Create_func_des_decrypt()614   virtual ~Create_func_des_decrypt() {}
615 };
616 
617 
618 class Create_func_des_encrypt : public Create_native_func
619 {
620 public:
621   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
622 
623   static Create_func_des_encrypt s_singleton;
624 
625 protected:
Create_func_des_encrypt()626   Create_func_des_encrypt() {}
~Create_func_des_encrypt()627   virtual ~Create_func_des_encrypt() {}
628 };
629 
630 
631 class Create_func_elt : public Create_native_func
632 {
633 public:
634   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
635 
636   static Create_func_elt s_singleton;
637 
638 protected:
Create_func_elt()639   Create_func_elt() {}
~Create_func_elt()640   virtual ~Create_func_elt() {}
641 };
642 
643 
644 class Create_func_encode : public Create_func_arg2
645 {
646 public:
647   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
648 
649   static Create_func_encode s_singleton;
650 
651 protected:
Create_func_encode()652   Create_func_encode() {}
~Create_func_encode()653   virtual ~Create_func_encode() {}
654 };
655 
656 
657 class Create_func_encrypt : public Create_native_func
658 {
659 public:
660   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
661 
662   static Create_func_encrypt s_singleton;
663 
664 protected:
Create_func_encrypt()665   Create_func_encrypt() {}
~Create_func_encrypt()666   virtual ~Create_func_encrypt() {}
667 };
668 
669 
670 class Create_func_exp : public Create_func_arg1
671 {
672 public:
673   virtual Item *create_1_arg(THD *thd, Item *arg1);
674 
675   static Create_func_exp s_singleton;
676 
677 protected:
Create_func_exp()678   Create_func_exp() {}
~Create_func_exp()679   virtual ~Create_func_exp() {}
680 };
681 
682 
683 class Create_func_export_set : public Create_native_func
684 {
685 public:
686   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
687 
688   static Create_func_export_set s_singleton;
689 
690 protected:
Create_func_export_set()691   Create_func_export_set() {}
~Create_func_export_set()692   virtual ~Create_func_export_set() {}
693 };
694 
695 
696 class Create_func_field : public Create_native_func
697 {
698 public:
699   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
700 
701   static Create_func_field s_singleton;
702 
703 protected:
Create_func_field()704   Create_func_field() {}
~Create_func_field()705   virtual ~Create_func_field() {}
706 };
707 
708 
709 class Create_func_find_in_set : public Create_func_arg2
710 {
711 public:
712   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
713 
714   static Create_func_find_in_set s_singleton;
715 
716 protected:
Create_func_find_in_set()717   Create_func_find_in_set() {}
~Create_func_find_in_set()718   virtual ~Create_func_find_in_set() {}
719 };
720 
721 
722 class Create_func_floor : public Create_func_arg1
723 {
724 public:
725   virtual Item *create_1_arg(THD *thd, Item *arg1);
726 
727   static Create_func_floor s_singleton;
728 
729 protected:
Create_func_floor()730   Create_func_floor() {}
~Create_func_floor()731   virtual ~Create_func_floor() {}
732 };
733 
734 
735 class Create_func_format : public Create_native_func
736 {
737 public:
738   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
739 
740   static Create_func_format s_singleton;
741 
742 protected:
Create_func_format()743   Create_func_format() {}
~Create_func_format()744   virtual ~Create_func_format() {}
745 };
746 
747 
748 class Create_func_found_rows : public Create_func_arg0
749 {
750 public:
751   virtual Item *create_builder(THD *thd);
752 
753   static Create_func_found_rows s_singleton;
754 
755 protected:
Create_func_found_rows()756   Create_func_found_rows() {}
~Create_func_found_rows()757   virtual ~Create_func_found_rows() {}
758 };
759 
760 
761 class Create_func_from_base64 : public Create_func_arg1
762 {
763 public:
764   virtual Item *create_1_arg(THD *thd, Item *arg1);
765 
766   static Create_func_from_base64 s_singleton;
767 
768 protected:
Create_func_from_base64()769   Create_func_from_base64() {}
~Create_func_from_base64()770   virtual ~Create_func_from_base64() {}
771 };
772 
773 
774 class Create_func_from_days : public Create_func_arg1
775 {
776 public:
777   virtual Item *create_1_arg(THD *thd, Item *arg1);
778 
779   static Create_func_from_days s_singleton;
780 
781 protected:
Create_func_from_days()782   Create_func_from_days() {}
~Create_func_from_days()783   virtual ~Create_func_from_days() {}
784 };
785 
786 
787 class Create_func_from_unixtime : public Create_native_func
788 {
789 public:
790   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
791 
792   static Create_func_from_unixtime s_singleton;
793 
794 protected:
Create_func_from_unixtime()795   Create_func_from_unixtime() {}
~Create_func_from_unixtime()796   virtual ~Create_func_from_unixtime() {}
797 };
798 
799 
800 class Create_func_get_lock : public Create_func_arg2
801 {
802 public:
803   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
804 
805   static Create_func_get_lock s_singleton;
806 
807 protected:
Create_func_get_lock()808   Create_func_get_lock() {}
~Create_func_get_lock()809   virtual ~Create_func_get_lock() {}
810 };
811 
812 
813 class Create_func_greatest : public Create_native_func
814 {
815 public:
816   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
817 
818   static Create_func_greatest s_singleton;
819 
820 protected:
Create_func_greatest()821   Create_func_greatest() {}
~Create_func_greatest()822   virtual ~Create_func_greatest() {}
823 };
824 
825 
826 class Create_func_hex : public Create_func_arg1
827 {
828 public:
829   virtual Item *create_1_arg(THD *thd, Item *arg1);
830 
831   static Create_func_hex s_singleton;
832 
833 protected:
Create_func_hex()834   Create_func_hex() {}
~Create_func_hex()835   virtual ~Create_func_hex() {}
836 };
837 
838 
839 class Create_func_ifnull : public Create_func_arg2
840 {
841 public:
842   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
843 
844   static Create_func_ifnull s_singleton;
845 
846 protected:
Create_func_ifnull()847   Create_func_ifnull() {}
~Create_func_ifnull()848   virtual ~Create_func_ifnull() {}
849 };
850 
851 
852 class Create_func_instr : public Create_func_arg2
853 {
854 public:
855   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
856 
857   static Create_func_instr s_singleton;
858 
859 protected:
Create_func_instr()860   Create_func_instr() {}
~Create_func_instr()861   virtual ~Create_func_instr() {}
862 };
863 
864 
865 class Create_func_is_free_lock : public Create_func_arg1
866 {
867 public:
868   virtual Item *create_1_arg(THD *thd, Item *arg1);
869 
870   static Create_func_is_free_lock s_singleton;
871 
872 protected:
Create_func_is_free_lock()873   Create_func_is_free_lock() {}
~Create_func_is_free_lock()874   virtual ~Create_func_is_free_lock() {}
875 };
876 
877 
878 class Create_func_is_used_lock : public Create_func_arg1
879 {
880 public:
881   virtual Item *create_1_arg(THD *thd, Item *arg1);
882 
883   static Create_func_is_used_lock s_singleton;
884 
885 protected:
Create_func_is_used_lock()886   Create_func_is_used_lock() {}
~Create_func_is_used_lock()887   virtual ~Create_func_is_used_lock() {}
888 };
889 
890 
891 class Create_func_isnull : public Create_func_arg1
892 {
893 public:
894   virtual Item *create_1_arg(THD *thd, Item *arg1);
895 
896   static Create_func_isnull s_singleton;
897 
898 protected:
Create_func_isnull()899   Create_func_isnull() {}
~Create_func_isnull()900   virtual ~Create_func_isnull() {}
901 };
902 
903 
904 class Create_func_json_exists : public Create_func_arg2
905 {
906 public:
907   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
908 
909   static Create_func_json_exists s_singleton;
910 
911 protected:
Create_func_json_exists()912   Create_func_json_exists() {}
~Create_func_json_exists()913   virtual ~Create_func_json_exists() {}
914 };
915 
916 
917 class Create_func_json_valid : public Create_func_arg1
918 {
919 public:
920   virtual Item *create_1_arg(THD *thd, Item *arg1);
921 
922   static Create_func_json_valid s_singleton;
923 
924 protected:
Create_func_json_valid()925   Create_func_json_valid() {}
~Create_func_json_valid()926   virtual ~Create_func_json_valid() {}
927 };
928 
929 
930 class Create_func_json_compact : public Create_func_arg1
931 {
932 public:
933   virtual Item *create_1_arg(THD *thd, Item *arg1);
934 
935   static Create_func_json_compact s_singleton;
936 
937 protected:
Create_func_json_compact()938   Create_func_json_compact() {}
~Create_func_json_compact()939   virtual ~Create_func_json_compact() {}
940 };
941 
942 
943 class Create_func_json_loose : public Create_func_arg1
944 {
945 public:
946   virtual Item *create_1_arg(THD *thd, Item *arg1);
947 
948   static Create_func_json_loose s_singleton;
949 
950 protected:
Create_func_json_loose()951   Create_func_json_loose() {}
~Create_func_json_loose()952   virtual ~Create_func_json_loose() {}
953 };
954 
955 
956 class Create_func_json_detailed: public Create_native_func
957 {
958 public:
959   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
960 
961   static Create_func_json_detailed s_singleton;
962 
963 protected:
Create_func_json_detailed()964   Create_func_json_detailed() {}
~Create_func_json_detailed()965   virtual ~Create_func_json_detailed() {}
966 };
967 
968 
969 class Create_func_json_type : public Create_func_arg1
970 {
971 public:
972   virtual Item *create_1_arg(THD *thd, Item *arg1);
973 
974   static Create_func_json_type s_singleton;
975 
976 protected:
Create_func_json_type()977   Create_func_json_type() {}
~Create_func_json_type()978   virtual ~Create_func_json_type() {}
979 };
980 
981 
982 class Create_func_json_depth : public Create_func_arg1
983 {
984 public:
985   virtual Item *create_1_arg(THD *thd, Item *arg1);
986 
987   static Create_func_json_depth s_singleton;
988 
989 protected:
Create_func_json_depth()990   Create_func_json_depth() {}
~Create_func_json_depth()991   virtual ~Create_func_json_depth() {}
992 };
993 
994 
995 class Create_func_json_value : public Create_func_arg2
996 {
997 public:
998   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
999 
1000   static Create_func_json_value s_singleton;
1001 
1002 protected:
Create_func_json_value()1003   Create_func_json_value() {}
~Create_func_json_value()1004   virtual ~Create_func_json_value() {}
1005 };
1006 
1007 
1008 class Create_func_json_query : public Create_func_arg2
1009 {
1010 public:
1011   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
1012 
1013   static Create_func_json_query s_singleton;
1014 
1015 protected:
Create_func_json_query()1016   Create_func_json_query() {}
~Create_func_json_query()1017   virtual ~Create_func_json_query() {}
1018 };
1019 
1020 
1021 class Create_func_json_keys: public Create_native_func
1022 {
1023 public:
1024   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1025 
1026   static Create_func_json_keys s_singleton;
1027 
1028 protected:
Create_func_json_keys()1029   Create_func_json_keys() {}
~Create_func_json_keys()1030   virtual ~Create_func_json_keys() {}
1031 };
1032 
1033 
1034 class Create_func_json_contains: public Create_native_func
1035 {
1036 public:
1037   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1038 
1039   static Create_func_json_contains s_singleton;
1040 
1041 protected:
Create_func_json_contains()1042   Create_func_json_contains() {}
~Create_func_json_contains()1043   virtual ~Create_func_json_contains() {}
1044 };
1045 
1046 
1047 class Create_func_json_contains_path : public Create_native_func
1048 {
1049 public:
1050   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1051 
1052   static Create_func_json_contains_path s_singleton;
1053 
1054 protected:
Create_func_json_contains_path()1055   Create_func_json_contains_path() {}
~Create_func_json_contains_path()1056   virtual ~Create_func_json_contains_path() {}
1057 };
1058 
1059 
1060 class Create_func_json_extract : public Create_native_func
1061 {
1062 public:
1063   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1064 
1065   static Create_func_json_extract s_singleton;
1066 
1067 protected:
Create_func_json_extract()1068   Create_func_json_extract() {}
~Create_func_json_extract()1069   virtual ~Create_func_json_extract() {}
1070 };
1071 
1072 
1073 class Create_func_json_search : public Create_native_func
1074 {
1075 public:
1076   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1077 
1078   static Create_func_json_search s_singleton;
1079 
1080 protected:
Create_func_json_search()1081   Create_func_json_search() {}
~Create_func_json_search()1082   virtual ~Create_func_json_search() {}
1083 };
1084 
1085 
1086 class Create_func_json_array : public Create_native_func
1087 {
1088 public:
1089   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1090 
1091   static Create_func_json_array s_singleton;
1092 
1093 protected:
Create_func_json_array()1094   Create_func_json_array() {}
~Create_func_json_array()1095   virtual ~Create_func_json_array() {}
1096 };
1097 
1098 
1099 class Create_func_json_array_append : public Create_native_func
1100 {
1101 public:
1102   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1103 
1104   static Create_func_json_array_append s_singleton;
1105 
1106 protected:
Create_func_json_array_append()1107   Create_func_json_array_append() {}
~Create_func_json_array_append()1108   virtual ~Create_func_json_array_append() {}
1109 };
1110 
1111 
1112 class Create_func_json_array_insert : public Create_native_func
1113 {
1114 public:
1115   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1116 
1117   static Create_func_json_array_insert s_singleton;
1118 
1119 protected:
Create_func_json_array_insert()1120   Create_func_json_array_insert() {}
~Create_func_json_array_insert()1121   virtual ~Create_func_json_array_insert() {}
1122 };
1123 
1124 
1125 class Create_func_json_insert : public Create_native_func
1126 {
1127 public:
1128   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1129 
1130   static Create_func_json_insert s_singleton;
1131 
1132 protected:
Create_func_json_insert()1133   Create_func_json_insert() {}
~Create_func_json_insert()1134   virtual ~Create_func_json_insert() {}
1135 };
1136 
1137 
1138 class Create_func_json_set : public Create_native_func
1139 {
1140 public:
1141   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1142 
1143   static Create_func_json_set s_singleton;
1144 
1145 protected:
Create_func_json_set()1146   Create_func_json_set() {}
~Create_func_json_set()1147   virtual ~Create_func_json_set() {}
1148 };
1149 
1150 
1151 class Create_func_json_replace : public Create_native_func
1152 {
1153 public:
1154   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1155 
1156   static Create_func_json_replace s_singleton;
1157 
1158 protected:
Create_func_json_replace()1159   Create_func_json_replace() {}
~Create_func_json_replace()1160   virtual ~Create_func_json_replace() {}
1161 };
1162 
1163 
1164 class Create_func_json_remove : public Create_native_func
1165 {
1166 public:
1167   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1168 
1169   static Create_func_json_remove s_singleton;
1170 
1171 protected:
Create_func_json_remove()1172   Create_func_json_remove() {}
~Create_func_json_remove()1173   virtual ~Create_func_json_remove() {}
1174 };
1175 
1176 
1177 class Create_func_json_object : public Create_native_func
1178 {
1179 public:
1180   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1181 
1182   static Create_func_json_object s_singleton;
1183 
1184 protected:
Create_func_json_object()1185   Create_func_json_object() {}
~Create_func_json_object()1186   virtual ~Create_func_json_object() {}
1187 };
1188 
1189 
1190 class Create_func_json_length : public Create_native_func
1191 {
1192 public:
1193   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1194 
1195   static Create_func_json_length s_singleton;
1196 
1197 protected:
Create_func_json_length()1198   Create_func_json_length() {}
~Create_func_json_length()1199   virtual ~Create_func_json_length() {}
1200 };
1201 
1202 
1203 class Create_func_json_merge : public Create_native_func
1204 {
1205 public:
1206   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1207 
1208   static Create_func_json_merge s_singleton;
1209 
1210 protected:
Create_func_json_merge()1211   Create_func_json_merge() {}
~Create_func_json_merge()1212   virtual ~Create_func_json_merge() {}
1213 };
1214 
1215 
1216 class Create_func_json_merge_patch : public Create_native_func
1217 {
1218 public:
1219   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1220 
1221   static Create_func_json_merge_patch s_singleton;
1222 
1223 protected:
Create_func_json_merge_patch()1224   Create_func_json_merge_patch() {}
~Create_func_json_merge_patch()1225   virtual ~Create_func_json_merge_patch() {}
1226 };
1227 
1228 
1229 class Create_func_json_quote : public Create_func_arg1
1230 {
1231 public:
1232   virtual Item *create_1_arg(THD *thd, Item *arg1);
1233 
1234   static Create_func_json_quote s_singleton;
1235 
1236 protected:
Create_func_json_quote()1237   Create_func_json_quote() {}
~Create_func_json_quote()1238   virtual ~Create_func_json_quote() {}
1239 };
1240 
1241 
1242 class Create_func_json_unquote : public Create_func_arg1
1243 {
1244 public:
1245   virtual Item *create_1_arg(THD *thd, Item *arg1);
1246 
1247   static Create_func_json_unquote s_singleton;
1248 
1249 protected:
Create_func_json_unquote()1250   Create_func_json_unquote() {}
~Create_func_json_unquote()1251   virtual ~Create_func_json_unquote() {}
1252 };
1253 
1254 
1255 class Create_func_last_day : public Create_func_arg1
1256 {
1257 public:
1258   virtual Item *create_1_arg(THD *thd, Item *arg1);
1259 
1260   static Create_func_last_day s_singleton;
1261 
1262 protected:
Create_func_last_day()1263   Create_func_last_day() {}
~Create_func_last_day()1264   virtual ~Create_func_last_day() {}
1265 };
1266 
1267 
1268 class Create_func_last_insert_id : public Create_native_func
1269 {
1270 public:
1271   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1272 
1273   static Create_func_last_insert_id s_singleton;
1274 
1275 protected:
Create_func_last_insert_id()1276   Create_func_last_insert_id() {}
~Create_func_last_insert_id()1277   virtual ~Create_func_last_insert_id() {}
1278 };
1279 
1280 
1281 class Create_func_lcase : public Create_func_arg1
1282 {
1283 public:
1284   virtual Item *create_1_arg(THD *thd, Item *arg1);
1285 
1286   static Create_func_lcase s_singleton;
1287 
1288 protected:
Create_func_lcase()1289   Create_func_lcase() {}
~Create_func_lcase()1290   virtual ~Create_func_lcase() {}
1291 };
1292 
1293 
1294 class Create_func_least : public Create_native_func
1295 {
1296 public:
1297   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1298 
1299   static Create_func_least s_singleton;
1300 
1301 protected:
Create_func_least()1302   Create_func_least() {}
~Create_func_least()1303   virtual ~Create_func_least() {}
1304 };
1305 
1306 
1307 class Create_func_length : public Create_func_arg1
1308 {
1309 public:
1310   virtual Item *create_1_arg(THD *thd, Item *arg1);
1311 
1312   static Create_func_length s_singleton;
1313 
1314 protected:
Create_func_length()1315   Create_func_length() {}
~Create_func_length()1316   virtual ~Create_func_length() {}
1317 };
1318 
1319 class Create_func_octet_length : public Create_func_arg1
1320 {
1321 public:
1322   virtual Item *create_1_arg(THD *thd, Item *arg1);
1323 
1324   static Create_func_octet_length s_singleton;
1325 
1326 protected:
Create_func_octet_length()1327   Create_func_octet_length() {}
~Create_func_octet_length()1328   virtual ~Create_func_octet_length() {}
1329 };
1330 
1331 
1332 #ifndef DBUG_OFF
1333 class Create_func_like_range_min : public Create_func_arg2
1334 {
1335 public:
1336   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
1337 
1338   static Create_func_like_range_min s_singleton;
1339 
1340 protected:
Create_func_like_range_min()1341   Create_func_like_range_min() {}
~Create_func_like_range_min()1342   virtual ~Create_func_like_range_min() {}
1343 };
1344 
1345 
1346 class Create_func_like_range_max : public Create_func_arg2
1347 {
1348 public:
1349   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
1350 
1351   static Create_func_like_range_max s_singleton;
1352 
1353 protected:
Create_func_like_range_max()1354   Create_func_like_range_max() {}
~Create_func_like_range_max()1355   virtual ~Create_func_like_range_max() {}
1356 };
1357 #endif
1358 
1359 
1360 class Create_func_ln : public Create_func_arg1
1361 {
1362 public:
1363   virtual Item *create_1_arg(THD *thd, Item *arg1);
1364 
1365   static Create_func_ln s_singleton;
1366 
1367 protected:
Create_func_ln()1368   Create_func_ln() {}
~Create_func_ln()1369   virtual ~Create_func_ln() {}
1370 };
1371 
1372 
1373 class Create_func_load_file : public Create_func_arg1
1374 {
1375 public:
1376   virtual Item *create_1_arg(THD *thd, Item *arg1);
1377 
1378   static Create_func_load_file s_singleton;
1379 
1380 protected:
Create_func_load_file()1381   Create_func_load_file() {}
~Create_func_load_file()1382   virtual ~Create_func_load_file() {}
1383 };
1384 
1385 
1386 class Create_func_locate : public Create_native_func
1387 {
1388 public:
1389   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1390 
1391   static Create_func_locate s_singleton;
1392 
1393 protected:
Create_func_locate()1394   Create_func_locate() {}
~Create_func_locate()1395   virtual ~Create_func_locate() {}
1396 };
1397 
1398 
1399 class Create_func_log : public Create_native_func
1400 {
1401 public:
1402   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1403 
1404   static Create_func_log s_singleton;
1405 
1406 protected:
Create_func_log()1407   Create_func_log() {}
~Create_func_log()1408   virtual ~Create_func_log() {}
1409 };
1410 
1411 
1412 class Create_func_log10 : public Create_func_arg1
1413 {
1414 public:
1415   virtual Item *create_1_arg(THD *thd, Item *arg1);
1416 
1417   static Create_func_log10 s_singleton;
1418 
1419 protected:
Create_func_log10()1420   Create_func_log10() {}
~Create_func_log10()1421   virtual ~Create_func_log10() {}
1422 };
1423 
1424 
1425 class Create_func_log2 : public Create_func_arg1
1426 {
1427 public:
1428   virtual Item *create_1_arg(THD *thd, Item *arg1);
1429 
1430   static Create_func_log2 s_singleton;
1431 
1432 protected:
Create_func_log2()1433   Create_func_log2() {}
~Create_func_log2()1434   virtual ~Create_func_log2() {}
1435 };
1436 
1437 
1438 class Create_func_lpad : public Create_native_func
1439 {
1440 public:
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)1441   virtual Item *create_native(THD *thd, LEX_CSTRING *name,
1442                               List<Item> *item_list)
1443   {
1444     return thd->variables.sql_mode & MODE_ORACLE ?
1445            create_native_oracle(thd, name, item_list) :
1446            create_native_std(thd, name, item_list);
1447   }
1448   static Create_func_lpad s_singleton;
1449 
1450 protected:
Create_func_lpad()1451   Create_func_lpad() {}
~Create_func_lpad()1452   virtual ~Create_func_lpad() {}
1453   Item *create_native_std(THD *thd, LEX_CSTRING *name, List<Item> *items);
1454   Item *create_native_oracle(THD *thd, LEX_CSTRING *name, List<Item> *items);
1455 };
1456 
1457 
1458 class Create_func_lpad_oracle : public Create_func_lpad
1459 {
1460 public:
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)1461   Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list)
1462   {
1463     return create_native_oracle(thd, name, item_list);
1464   }
1465   static Create_func_lpad_oracle s_singleton;
1466 };
1467 
1468 
1469 class Create_func_ltrim : public Create_func_arg1
1470 {
1471 public:
1472   virtual Item *create_1_arg(THD *thd, Item *arg1);
1473 
1474   static Create_func_ltrim s_singleton;
1475 
1476 protected:
Create_func_ltrim()1477   Create_func_ltrim() {}
~Create_func_ltrim()1478   virtual ~Create_func_ltrim() {}
1479 };
1480 
1481 
1482 class Create_func_ltrim_oracle : public Create_func_arg1
1483 {
1484 public:
1485   virtual Item *create_1_arg(THD *thd, Item *arg1);
1486 
1487   static Create_func_ltrim_oracle s_singleton;
1488 
1489 protected:
Create_func_ltrim_oracle()1490   Create_func_ltrim_oracle() {}
~Create_func_ltrim_oracle()1491   virtual ~Create_func_ltrim_oracle() {}
1492 };
1493 
1494 
1495 class Create_func_makedate : public Create_func_arg2
1496 {
1497 public:
1498   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
1499 
1500   static Create_func_makedate s_singleton;
1501 
1502 protected:
Create_func_makedate()1503   Create_func_makedate() {}
~Create_func_makedate()1504   virtual ~Create_func_makedate() {}
1505 };
1506 
1507 
1508 class Create_func_maketime : public Create_func_arg3
1509 {
1510 public:
1511   virtual Item *create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3);
1512 
1513   static Create_func_maketime s_singleton;
1514 
1515 protected:
Create_func_maketime()1516   Create_func_maketime() {}
~Create_func_maketime()1517   virtual ~Create_func_maketime() {}
1518 };
1519 
1520 
1521 class Create_func_make_set : public Create_native_func
1522 {
1523 public:
1524   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1525 
1526   static Create_func_make_set s_singleton;
1527 
1528 protected:
Create_func_make_set()1529   Create_func_make_set() {}
~Create_func_make_set()1530   virtual ~Create_func_make_set() {}
1531 };
1532 
1533 
1534 class Create_func_master_pos_wait : public Create_native_func
1535 {
1536 public:
1537   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1538 
1539   static Create_func_master_pos_wait s_singleton;
1540 
1541 protected:
Create_func_master_pos_wait()1542   Create_func_master_pos_wait() {}
~Create_func_master_pos_wait()1543   virtual ~Create_func_master_pos_wait() {}
1544 };
1545 
1546 
1547 class Create_func_master_gtid_wait : public Create_native_func
1548 {
1549 public:
1550   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1551 
1552   static Create_func_master_gtid_wait s_singleton;
1553 
1554 protected:
Create_func_master_gtid_wait()1555   Create_func_master_gtid_wait() {}
~Create_func_master_gtid_wait()1556   virtual ~Create_func_master_gtid_wait() {}
1557 };
1558 
1559 
1560 class Create_func_md5 : public Create_func_arg1
1561 {
1562 public:
1563   virtual Item *create_1_arg(THD *thd, Item *arg1);
1564 
1565   static Create_func_md5 s_singleton;
1566 
1567 protected:
Create_func_md5()1568   Create_func_md5() {}
~Create_func_md5()1569   virtual ~Create_func_md5() {}
1570 };
1571 
1572 
1573 class Create_func_monthname : public Create_func_arg1
1574 {
1575 public:
1576   virtual Item *create_1_arg(THD *thd, Item *arg1);
1577 
1578   static Create_func_monthname s_singleton;
1579 
1580 protected:
Create_func_monthname()1581   Create_func_monthname() {}
~Create_func_monthname()1582   virtual ~Create_func_monthname() {}
1583 };
1584 
1585 
1586 class Create_func_name_const : public Create_func_arg2
1587 {
1588 public:
1589   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
1590 
1591   static Create_func_name_const s_singleton;
1592 
1593 protected:
Create_func_name_const()1594   Create_func_name_const() {}
~Create_func_name_const()1595   virtual ~Create_func_name_const() {}
1596 };
1597 
1598 
1599 class Create_func_nullif : public Create_func_arg2
1600 {
1601 public:
1602   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
1603 
1604   static Create_func_nullif s_singleton;
1605 
1606 protected:
Create_func_nullif()1607   Create_func_nullif() {}
~Create_func_nullif()1608   virtual ~Create_func_nullif() {}
1609 };
1610 
1611 
1612 class Create_func_oct : public Create_func_arg1
1613 {
1614 public:
1615   virtual Item *create_1_arg(THD *thd, Item *arg1);
1616 
1617   static Create_func_oct s_singleton;
1618 
1619 protected:
Create_func_oct()1620   Create_func_oct() {}
~Create_func_oct()1621   virtual ~Create_func_oct() {}
1622 };
1623 
1624 
1625 class Create_func_ord : public Create_func_arg1
1626 {
1627 public:
1628   virtual Item *create_1_arg(THD *thd, Item *arg1);
1629 
1630   static Create_func_ord s_singleton;
1631 
1632 protected:
Create_func_ord()1633   Create_func_ord() {}
~Create_func_ord()1634   virtual ~Create_func_ord() {}
1635 };
1636 
1637 
1638 class Create_func_period_add : public Create_func_arg2
1639 {
1640 public:
1641   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
1642 
1643   static Create_func_period_add s_singleton;
1644 
1645 protected:
Create_func_period_add()1646   Create_func_period_add() {}
~Create_func_period_add()1647   virtual ~Create_func_period_add() {}
1648 };
1649 
1650 
1651 class Create_func_period_diff : public Create_func_arg2
1652 {
1653 public:
1654   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
1655 
1656   static Create_func_period_diff s_singleton;
1657 
1658 protected:
Create_func_period_diff()1659   Create_func_period_diff() {}
~Create_func_period_diff()1660   virtual ~Create_func_period_diff() {}
1661 };
1662 
1663 
1664 class Create_func_pi : public Create_func_arg0
1665 {
1666 public:
1667   virtual Item *create_builder(THD *thd);
1668 
1669   static Create_func_pi s_singleton;
1670 
1671 protected:
Create_func_pi()1672   Create_func_pi() {}
~Create_func_pi()1673   virtual ~Create_func_pi() {}
1674 };
1675 
1676 
1677 class Create_func_pow : public Create_func_arg2
1678 {
1679 public:
1680   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
1681 
1682   static Create_func_pow s_singleton;
1683 
1684 protected:
Create_func_pow()1685   Create_func_pow() {}
~Create_func_pow()1686   virtual ~Create_func_pow() {}
1687 };
1688 
1689 
1690 class Create_func_quote : public Create_func_arg1
1691 {
1692 public:
1693   virtual Item *create_1_arg(THD *thd, Item *arg1);
1694 
1695   static Create_func_quote s_singleton;
1696 
1697 protected:
Create_func_quote()1698   Create_func_quote() {}
~Create_func_quote()1699   virtual ~Create_func_quote() {}
1700 };
1701 
1702 
1703 class Create_func_regexp_instr : public Create_func_arg2
1704 {
1705 public:
1706   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
1707 
1708   static Create_func_regexp_instr s_singleton;
1709 
1710 protected:
Create_func_regexp_instr()1711   Create_func_regexp_instr() {}
~Create_func_regexp_instr()1712   virtual ~Create_func_regexp_instr() {}
1713 };
1714 
1715 
1716 class Create_func_regexp_replace : public Create_func_arg3
1717 {
1718 public:
1719   virtual Item *create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3);
1720 
1721   static Create_func_regexp_replace s_singleton;
1722 
1723 protected:
Create_func_regexp_replace()1724   Create_func_regexp_replace() {}
~Create_func_regexp_replace()1725   virtual ~Create_func_regexp_replace() {}
1726 };
1727 
1728 
1729 class Create_func_regexp_substr : public Create_func_arg2
1730 {
1731 public:
1732   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
1733 
1734   static Create_func_regexp_substr s_singleton;
1735 
1736 protected:
Create_func_regexp_substr()1737   Create_func_regexp_substr() {}
~Create_func_regexp_substr()1738   virtual ~Create_func_regexp_substr() {}
1739 };
1740 
1741 
1742 class Create_func_radians : public Create_func_arg1
1743 {
1744 public:
1745   virtual Item *create_1_arg(THD *thd, Item *arg1);
1746 
1747   static Create_func_radians s_singleton;
1748 
1749 protected:
Create_func_radians()1750   Create_func_radians() {}
~Create_func_radians()1751   virtual ~Create_func_radians() {}
1752 };
1753 
1754 
1755 class Create_func_rand : public Create_native_func
1756 {
1757 public:
1758   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1759 
1760   static Create_func_rand s_singleton;
1761 
1762 protected:
Create_func_rand()1763   Create_func_rand() {}
~Create_func_rand()1764   virtual ~Create_func_rand() {}
1765 };
1766 
1767 
1768 class Create_func_release_all_locks : public Create_func_arg0
1769 {
1770 public:
1771   virtual Item *create_builder(THD *thd);
1772 
1773   static Create_func_release_all_locks s_singleton;
1774 };
1775 
1776 
1777 class Create_func_release_lock : public Create_func_arg1
1778 {
1779 public:
1780   virtual Item *create_1_arg(THD *thd, Item *arg1);
1781 
1782   static Create_func_release_lock s_singleton;
1783 
1784 protected:
Create_func_release_lock()1785   Create_func_release_lock() {}
~Create_func_release_lock()1786   virtual ~Create_func_release_lock() {}
1787 };
1788 
1789 
1790 class Create_func_replace_oracle : public Create_func_arg3
1791 {
1792 public:
1793   virtual Item *create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3);
1794 
1795   static Create_func_replace_oracle s_singleton;
1796 
1797 protected:
Create_func_replace_oracle()1798   Create_func_replace_oracle() {}
~Create_func_replace_oracle()1799   virtual ~Create_func_replace_oracle() {}
1800 };
1801 
1802 
1803 class Create_func_reverse : public Create_func_arg1
1804 {
1805 public:
1806   virtual Item *create_1_arg(THD *thd, Item *arg1);
1807 
1808   static Create_func_reverse s_singleton;
1809 
1810 protected:
Create_func_reverse()1811   Create_func_reverse() {}
~Create_func_reverse()1812   virtual ~Create_func_reverse() {}
1813 };
1814 
1815 
1816 class Create_func_round : public Create_native_func
1817 {
1818 public:
1819   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
1820 
1821   static Create_func_round s_singleton;
1822 
1823 protected:
Create_func_round()1824   Create_func_round() {}
~Create_func_round()1825   virtual ~Create_func_round() {}
1826 };
1827 
1828 
1829 class Create_func_rpad : public Create_native_func
1830 {
1831 public:
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)1832   virtual Item *create_native(THD *thd, LEX_CSTRING *name,
1833                               List<Item> *item_list)
1834   {
1835     return thd->variables.sql_mode & MODE_ORACLE ?
1836            create_native_oracle(thd, name, item_list) :
1837            create_native_std(thd, name, item_list);
1838   }
1839   static Create_func_rpad s_singleton;
1840 
1841 protected:
Create_func_rpad()1842   Create_func_rpad() {}
~Create_func_rpad()1843   virtual ~Create_func_rpad() {}
1844   Item *create_native_std(THD *thd, LEX_CSTRING *name, List<Item> *items);
1845   Item *create_native_oracle(THD *thd, LEX_CSTRING *name, List<Item> *items);
1846 };
1847 
1848 
1849 class Create_func_rpad_oracle : public Create_func_rpad
1850 {
1851 public:
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)1852   Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list)
1853   {
1854     return create_native_oracle(thd, name, item_list);
1855   }
1856   static Create_func_rpad_oracle s_singleton;
1857 };
1858 
1859 
1860 class Create_func_rtrim : public Create_func_arg1
1861 {
1862 public:
1863   virtual Item *create_1_arg(THD *thd, Item *arg1);
1864 
1865   static Create_func_rtrim s_singleton;
1866 
1867 protected:
Create_func_rtrim()1868   Create_func_rtrim() {}
~Create_func_rtrim()1869   virtual ~Create_func_rtrim() {}
1870 };
1871 
1872 
1873 class Create_func_rtrim_oracle : public Create_func_arg1
1874 {
1875 public:
1876   virtual Item *create_1_arg(THD *thd, Item *arg1);
1877 
1878   static Create_func_rtrim_oracle s_singleton;
1879 
1880 protected:
Create_func_rtrim_oracle()1881   Create_func_rtrim_oracle() {}
~Create_func_rtrim_oracle()1882   virtual ~Create_func_rtrim_oracle() {}
1883 };
1884 
1885 
1886 class Create_func_sec_to_time : public Create_func_arg1
1887 {
1888 public:
1889   virtual Item *create_1_arg(THD *thd, Item *arg1);
1890 
1891   static Create_func_sec_to_time s_singleton;
1892 
1893 protected:
Create_func_sec_to_time()1894   Create_func_sec_to_time() {}
~Create_func_sec_to_time()1895   virtual ~Create_func_sec_to_time() {}
1896 };
1897 
1898 
1899 class Create_func_sha : public Create_func_arg1
1900 {
1901 public:
1902   virtual Item *create_1_arg(THD *thd, Item *arg1);
1903 
1904   static Create_func_sha s_singleton;
1905 
1906 protected:
Create_func_sha()1907   Create_func_sha() {}
~Create_func_sha()1908   virtual ~Create_func_sha() {}
1909 };
1910 
1911 
1912 class Create_func_sha2 : public Create_func_arg2
1913 {
1914 public:
1915   virtual Item* create_2_arg(THD *thd, Item *arg1, Item *arg2);
1916 
1917   static Create_func_sha2 s_singleton;
1918 
1919 protected:
Create_func_sha2()1920   Create_func_sha2() {}
~Create_func_sha2()1921   virtual ~Create_func_sha2() {}
1922 };
1923 
1924 
1925 class Create_func_sign : public Create_func_arg1
1926 {
1927 public:
1928   virtual Item *create_1_arg(THD *thd, Item *arg1);
1929 
1930   static Create_func_sign s_singleton;
1931 
1932 protected:
Create_func_sign()1933   Create_func_sign() {}
~Create_func_sign()1934   virtual ~Create_func_sign() {}
1935 };
1936 
1937 
1938 class Create_func_sin : public Create_func_arg1
1939 {
1940 public:
1941   virtual Item *create_1_arg(THD *thd, Item *arg1);
1942 
1943   static Create_func_sin s_singleton;
1944 
1945 protected:
Create_func_sin()1946   Create_func_sin() {}
~Create_func_sin()1947   virtual ~Create_func_sin() {}
1948 };
1949 
1950 
1951 class Create_func_sleep : public Create_func_arg1
1952 {
1953 public:
1954   virtual Item *create_1_arg(THD *thd, Item *arg1);
1955 
1956   static Create_func_sleep s_singleton;
1957 
1958 protected:
Create_func_sleep()1959   Create_func_sleep() {}
~Create_func_sleep()1960   virtual ~Create_func_sleep() {}
1961 };
1962 
1963 
1964 class Create_func_soundex : public Create_func_arg1
1965 {
1966 public:
1967   virtual Item *create_1_arg(THD *thd, Item *arg1);
1968 
1969   static Create_func_soundex s_singleton;
1970 
1971 protected:
Create_func_soundex()1972   Create_func_soundex() {}
~Create_func_soundex()1973   virtual ~Create_func_soundex() {}
1974 };
1975 
1976 
1977 class Create_func_space : public Create_func_arg1
1978 {
1979 public:
1980   virtual Item *create_1_arg(THD *thd, Item *arg1);
1981 
1982   static Create_func_space s_singleton;
1983 
1984 protected:
Create_func_space()1985   Create_func_space() {}
~Create_func_space()1986   virtual ~Create_func_space() {}
1987 };
1988 
1989 
1990 class Create_func_sqrt : public Create_func_arg1
1991 {
1992 public:
1993   virtual Item *create_1_arg(THD *thd, Item *arg1);
1994 
1995   static Create_func_sqrt s_singleton;
1996 
1997 protected:
Create_func_sqrt()1998   Create_func_sqrt() {}
~Create_func_sqrt()1999   virtual ~Create_func_sqrt() {}
2000 };
2001 
2002 
2003 class Create_func_str_to_date : public Create_func_arg2
2004 {
2005 public:
2006   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
2007 
2008   static Create_func_str_to_date s_singleton;
2009 
2010 protected:
Create_func_str_to_date()2011   Create_func_str_to_date() {}
~Create_func_str_to_date()2012   virtual ~Create_func_str_to_date() {}
2013 };
2014 
2015 
2016 class Create_func_strcmp : public Create_func_arg2
2017 {
2018 public:
2019   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
2020 
2021   static Create_func_strcmp s_singleton;
2022 
2023 protected:
Create_func_strcmp()2024   Create_func_strcmp() {}
~Create_func_strcmp()2025   virtual ~Create_func_strcmp() {}
2026 };
2027 
2028 
2029 class Create_func_substr_index : public Create_func_arg3
2030 {
2031 public:
2032   virtual Item *create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3);
2033 
2034   static Create_func_substr_index s_singleton;
2035 
2036 protected:
Create_func_substr_index()2037   Create_func_substr_index() {}
~Create_func_substr_index()2038   virtual ~Create_func_substr_index() {}
2039 };
2040 
2041 
2042 class Create_func_substr_oracle : public Create_native_func
2043 {
2044 public:
2045   virtual Item *create_native(THD *thd, LEX_CSTRING *name,
2046                               List<Item> *item_list);
2047 
2048   static Create_func_substr_oracle s_singleton;
2049 
2050 protected:
Create_func_substr_oracle()2051   Create_func_substr_oracle() {}
~Create_func_substr_oracle()2052   virtual ~Create_func_substr_oracle() {}
2053 };
2054 
2055 
2056 class Create_func_subtime : public Create_func_arg2
2057 {
2058 public:
2059   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
2060 
2061   static Create_func_subtime s_singleton;
2062 
2063 protected:
Create_func_subtime()2064   Create_func_subtime() {}
~Create_func_subtime()2065   virtual ~Create_func_subtime() {}
2066 };
2067 
2068 
2069 class Create_func_tan : public Create_func_arg1
2070 {
2071 public:
2072   virtual Item *create_1_arg(THD *thd, Item *arg1);
2073 
2074   static Create_func_tan s_singleton;
2075 
2076 protected:
Create_func_tan()2077   Create_func_tan() {}
~Create_func_tan()2078   virtual ~Create_func_tan() {}
2079 };
2080 
2081 
2082 class Create_func_time_format : public Create_func_arg2
2083 {
2084 public:
2085   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
2086 
2087   static Create_func_time_format s_singleton;
2088 
2089 protected:
Create_func_time_format()2090   Create_func_time_format() {}
~Create_func_time_format()2091   virtual ~Create_func_time_format() {}
2092 };
2093 
2094 
2095 class Create_func_time_to_sec : public Create_func_arg1
2096 {
2097 public:
2098   virtual Item *create_1_arg(THD *thd, Item *arg1);
2099 
2100   static Create_func_time_to_sec s_singleton;
2101 
2102 protected:
Create_func_time_to_sec()2103   Create_func_time_to_sec() {}
~Create_func_time_to_sec()2104   virtual ~Create_func_time_to_sec() {}
2105 };
2106 
2107 
2108 class Create_func_timediff : public Create_func_arg2
2109 {
2110 public:
2111   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
2112 
2113   static Create_func_timediff s_singleton;
2114 
2115 protected:
Create_func_timediff()2116   Create_func_timediff() {}
~Create_func_timediff()2117   virtual ~Create_func_timediff() {}
2118 };
2119 
2120 
2121 class Create_func_to_base64 : public Create_func_arg1
2122 {
2123 public:
2124   virtual Item *create_1_arg(THD *thd, Item *arg1);
2125 
2126   static Create_func_to_base64 s_singleton;
2127 
2128 protected:
Create_func_to_base64()2129   Create_func_to_base64() {}
~Create_func_to_base64()2130   virtual ~Create_func_to_base64() {}
2131 };
2132 
2133 
2134 class Create_func_to_days : public Create_func_arg1
2135 {
2136 public:
2137   virtual Item *create_1_arg(THD *thd, Item *arg1);
2138 
2139   static Create_func_to_days s_singleton;
2140 
2141 protected:
Create_func_to_days()2142   Create_func_to_days() {}
~Create_func_to_days()2143   virtual ~Create_func_to_days() {}
2144 };
2145 
2146 class Create_func_to_seconds : public Create_func_arg1
2147 {
2148 public:
2149   virtual Item* create_1_arg(THD *thd, Item *arg1);
2150 
2151   static Create_func_to_seconds s_singleton;
2152 
2153 protected:
Create_func_to_seconds()2154   Create_func_to_seconds() {}
~Create_func_to_seconds()2155   virtual ~Create_func_to_seconds() {}
2156 };
2157 
2158 
2159 class Create_func_ucase : public Create_func_arg1
2160 {
2161 public:
2162   virtual Item *create_1_arg(THD *thd, Item *arg1);
2163 
2164   static Create_func_ucase s_singleton;
2165 
2166 protected:
Create_func_ucase()2167   Create_func_ucase() {}
~Create_func_ucase()2168   virtual ~Create_func_ucase() {}
2169 };
2170 
2171 
2172 class Create_func_uncompress : public Create_func_arg1
2173 {
2174 public:
2175   virtual Item *create_1_arg(THD *thd, Item *arg1);
2176 
2177   static Create_func_uncompress s_singleton;
2178 
2179 protected:
Create_func_uncompress()2180   Create_func_uncompress() {}
~Create_func_uncompress()2181   virtual ~Create_func_uncompress() {}
2182 };
2183 
2184 
2185 class Create_func_uncompressed_length : public Create_func_arg1
2186 {
2187 public:
2188   virtual Item *create_1_arg(THD *thd, Item *arg1);
2189 
2190   static Create_func_uncompressed_length s_singleton;
2191 
2192 protected:
Create_func_uncompressed_length()2193   Create_func_uncompressed_length() {}
~Create_func_uncompressed_length()2194   virtual ~Create_func_uncompressed_length() {}
2195 };
2196 
2197 
2198 class Create_func_unhex : public Create_func_arg1
2199 {
2200 public:
2201   virtual Item *create_1_arg(THD *thd, Item *arg1);
2202 
2203   static Create_func_unhex s_singleton;
2204 
2205 protected:
Create_func_unhex()2206   Create_func_unhex() {}
~Create_func_unhex()2207   virtual ~Create_func_unhex() {}
2208 };
2209 
2210 
2211 class Create_func_unix_timestamp : public Create_native_func
2212 {
2213 public:
2214   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
2215 
2216   static Create_func_unix_timestamp s_singleton;
2217 
2218 protected:
Create_func_unix_timestamp()2219   Create_func_unix_timestamp() {}
~Create_func_unix_timestamp()2220   virtual ~Create_func_unix_timestamp() {}
2221 };
2222 
2223 
2224 class Create_func_uuid : public Create_func_arg0
2225 {
2226 public:
2227   virtual Item *create_builder(THD *thd);
2228 
2229   static Create_func_uuid s_singleton;
2230 
2231 protected:
Create_func_uuid()2232   Create_func_uuid() {}
~Create_func_uuid()2233   virtual ~Create_func_uuid() {}
2234 };
2235 
2236 
2237 class Create_func_uuid_short : public Create_func_arg0
2238 {
2239 public:
2240   virtual Item *create_builder(THD *thd);
2241 
2242   static Create_func_uuid_short s_singleton;
2243 
2244 protected:
Create_func_uuid_short()2245   Create_func_uuid_short() {}
~Create_func_uuid_short()2246   virtual ~Create_func_uuid_short() {}
2247 };
2248 
2249 
2250 class Create_func_version : public Create_func_arg0
2251 {
2252 public:
2253   virtual Item *create_builder(THD *thd);
2254 
2255   static Create_func_version s_singleton;
2256 
2257 protected:
Create_func_version()2258   Create_func_version() {}
~Create_func_version()2259   virtual ~Create_func_version() {}
2260 };
2261 
2262 
2263 class Create_func_weekday : public Create_func_arg1
2264 {
2265 public:
2266   virtual Item *create_1_arg(THD *thd, Item *arg1);
2267 
2268   static Create_func_weekday s_singleton;
2269 
2270 protected:
Create_func_weekday()2271   Create_func_weekday() {}
~Create_func_weekday()2272   virtual ~Create_func_weekday() {}
2273 };
2274 
2275 
2276 class Create_func_weekofyear : public Create_func_arg1
2277 {
2278 public:
2279   virtual Item *create_1_arg(THD *thd, Item *arg1);
2280 
2281   static Create_func_weekofyear s_singleton;
2282 
2283 protected:
Create_func_weekofyear()2284   Create_func_weekofyear() {}
~Create_func_weekofyear()2285   virtual ~Create_func_weekofyear() {}
2286 };
2287 
2288 
2289 #ifdef WITH_WSREP
2290 class Create_func_wsrep_last_written_gtid : public Create_func_arg0
2291 {
2292 public:
2293   virtual Item *create_builder(THD *thd);
2294 
2295   static Create_func_wsrep_last_written_gtid s_singleton;
2296 
2297 protected:
Create_func_wsrep_last_written_gtid()2298   Create_func_wsrep_last_written_gtid() {}
~Create_func_wsrep_last_written_gtid()2299   virtual ~Create_func_wsrep_last_written_gtid() {}
2300 };
2301 
2302 
2303 class Create_func_wsrep_last_seen_gtid : public Create_func_arg0
2304 {
2305 public:
2306   virtual Item *create_builder(THD *thd);
2307 
2308   static Create_func_wsrep_last_seen_gtid s_singleton;
2309 
2310 protected:
Create_func_wsrep_last_seen_gtid()2311   Create_func_wsrep_last_seen_gtid() {}
~Create_func_wsrep_last_seen_gtid()2312   virtual ~Create_func_wsrep_last_seen_gtid() {}
2313 };
2314 
2315 
2316 class Create_func_wsrep_sync_wait_upto : public Create_native_func
2317 {
2318 public:
2319   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
2320 
2321   static Create_func_wsrep_sync_wait_upto s_singleton;
2322 
2323 protected:
Create_func_wsrep_sync_wait_upto()2324   Create_func_wsrep_sync_wait_upto() {}
~Create_func_wsrep_sync_wait_upto()2325   virtual ~Create_func_wsrep_sync_wait_upto() {}
2326 };
2327 #endif /* WITH_WSREP */
2328 
2329 
2330 class Create_func_xml_extractvalue : public Create_func_arg2
2331 {
2332 public:
2333   virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
2334 
2335   static Create_func_xml_extractvalue s_singleton;
2336 
2337 protected:
Create_func_xml_extractvalue()2338   Create_func_xml_extractvalue() {}
~Create_func_xml_extractvalue()2339   virtual ~Create_func_xml_extractvalue() {}
2340 };
2341 
2342 
2343 class Create_func_xml_update : public Create_func_arg3
2344 {
2345 public:
2346   virtual Item *create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3);
2347 
2348   static Create_func_xml_update s_singleton;
2349 
2350 protected:
Create_func_xml_update()2351   Create_func_xml_update() {}
~Create_func_xml_update()2352   virtual ~Create_func_xml_update() {}
2353 };
2354 
2355 
2356 class Create_func_year_week : public Create_native_func
2357 {
2358 public:
2359   virtual Item *create_native(THD *thd, LEX_CSTRING *name, List<Item> *item_list);
2360 
2361   static Create_func_year_week s_singleton;
2362 
2363 protected:
Create_func_year_week()2364   Create_func_year_week() {}
~Create_func_year_week()2365   virtual ~Create_func_year_week() {}
2366 };
2367 
2368 
2369 /*
2370 =============================================================================
2371   IMPLEMENTATION
2372 =============================================================================
2373 */
2374 
2375 /**
2376   Checks if there are named parameters in a parameter list.
2377   The syntax to name parameters in a function call is as follow:
2378   <code>foo(expr AS named, expr named, expr AS "named", expr "named")</code>
2379   @param params The parameter list, can be null
2380   @return true if one or more parameter is named
2381 */
has_named_parameters(List<Item> * params)2382 static bool has_named_parameters(List<Item> *params)
2383 {
2384   if (params)
2385   {
2386     Item *param;
2387     List_iterator<Item> it(*params);
2388     while ((param= it++))
2389     {
2390       if (! param->is_autogenerated_name())
2391         return true;
2392     }
2393   }
2394 
2395   return false;
2396 }
2397 
2398 
2399 Item*
create_func(THD * thd,LEX_CSTRING * name,List<Item> * item_list)2400 Create_qfunc::create_func(THD *thd, LEX_CSTRING *name, List<Item> *item_list)
2401 {
2402   LEX_CSTRING db;
2403 
2404   if (unlikely(! thd->db.str && ! thd->lex->sphead))
2405   {
2406     /*
2407       The proper error message should be in the lines of:
2408         Can't resolve <name>() to a function call,
2409         because this function:
2410         - is not a native function,
2411         - is not a user defined function,
2412         - can not match a qualified (read: stored) function
2413           since no database is selected.
2414       Reusing ER_SP_DOES_NOT_EXIST have a message consistent with
2415       the case when a default database exist, see Create_sp_func::create().
2416     */
2417     my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
2418              "FUNCTION", name->str);
2419     return NULL;
2420   }
2421 
2422   if (thd->lex->copy_db_to(&db))
2423     return NULL;
2424 
2425   return create_with_db(thd, &db, name, false, item_list);
2426 }
2427 
2428 
2429 #ifdef HAVE_DLOPEN
2430 Create_udf_func Create_udf_func::s_singleton;
2431 
2432 Item*
create_func(THD * thd,LEX_CSTRING * name,List<Item> * item_list)2433 Create_udf_func::create_func(THD *thd, LEX_CSTRING *name, List<Item> *item_list)
2434 {
2435   udf_func *udf= find_udf(name->str,  name->length);
2436   DBUG_ASSERT(udf);
2437   return create(thd, udf, item_list);
2438 }
2439 
2440 
2441 Item*
create(THD * thd,udf_func * udf,List<Item> * item_list)2442 Create_udf_func::create(THD *thd, udf_func *udf, List<Item> *item_list)
2443 {
2444   Item *func= NULL;
2445   int arg_count= 0;
2446 
2447   DBUG_ENTER("Create_udf_func::create");
2448   if (item_list != NULL)
2449     arg_count= item_list->elements;
2450 
2451   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_UDF);
2452 
2453   DBUG_ASSERT(   (udf->type == UDFTYPE_FUNCTION)
2454               || (udf->type == UDFTYPE_AGGREGATE));
2455 
2456   switch(udf->returns) {
2457   case STRING_RESULT:
2458   {
2459     if (udf->type == UDFTYPE_FUNCTION)
2460     {
2461       if (arg_count)
2462         func= new (thd->mem_root) Item_func_udf_str(thd, udf, *item_list);
2463       else
2464         func= new (thd->mem_root) Item_func_udf_str(thd, udf);
2465     }
2466     else
2467     {
2468       if (arg_count)
2469         func= new (thd->mem_root) Item_sum_udf_str(thd, udf, *item_list);
2470       else
2471         func= new (thd->mem_root) Item_sum_udf_str(thd, udf);
2472     }
2473     break;
2474   }
2475   case REAL_RESULT:
2476   {
2477     if (udf->type == UDFTYPE_FUNCTION)
2478     {
2479       if (arg_count)
2480         func= new (thd->mem_root) Item_func_udf_float(thd, udf, *item_list);
2481       else
2482         func= new (thd->mem_root) Item_func_udf_float(thd, udf);
2483     }
2484     else
2485     {
2486       if (arg_count)
2487         func= new (thd->mem_root) Item_sum_udf_float(thd, udf, *item_list);
2488       else
2489         func= new (thd->mem_root) Item_sum_udf_float(thd, udf);
2490     }
2491     break;
2492   }
2493   case INT_RESULT:
2494   {
2495     if (udf->type == UDFTYPE_FUNCTION)
2496     {
2497       if (arg_count)
2498         func= new (thd->mem_root) Item_func_udf_int(thd, udf, *item_list);
2499       else
2500         func= new (thd->mem_root) Item_func_udf_int(thd, udf);
2501     }
2502     else
2503     {
2504       if (arg_count)
2505         func= new (thd->mem_root) Item_sum_udf_int(thd, udf, *item_list);
2506       else
2507         func= new (thd->mem_root) Item_sum_udf_int(thd, udf);
2508     }
2509     break;
2510   }
2511   case DECIMAL_RESULT:
2512   {
2513     if (udf->type == UDFTYPE_FUNCTION)
2514     {
2515       if (arg_count)
2516         func= new (thd->mem_root) Item_func_udf_decimal(thd, udf, *item_list);
2517       else
2518         func= new (thd->mem_root) Item_func_udf_decimal(thd, udf);
2519     }
2520     else
2521     {
2522       if (arg_count)
2523         func= new (thd->mem_root) Item_sum_udf_decimal(thd, udf, *item_list);
2524       else
2525         func= new (thd->mem_root) Item_sum_udf_decimal(thd, udf);
2526     }
2527     break;
2528   }
2529   default:
2530   {
2531     my_error(ER_NOT_SUPPORTED_YET, MYF(0), "UDF return type");
2532   }
2533   }
2534   thd->lex->safe_to_cache_query= 0;
2535   DBUG_RETURN(func);
2536 }
2537 #endif
2538 
2539 
2540 Create_sp_func Create_sp_func::s_singleton;
2541 
2542 Item*
create_with_db(THD * thd,LEX_CSTRING * db,LEX_CSTRING * name,bool use_explicit_name,List<Item> * item_list)2543 Create_sp_func::create_with_db(THD *thd, LEX_CSTRING *db, LEX_CSTRING *name,
2544                                bool use_explicit_name, List<Item> *item_list)
2545 {
2546   int arg_count= 0;
2547   Item *func= NULL;
2548   LEX *lex= thd->lex;
2549   sp_name *qname;
2550   const Sp_handler *sph= &sp_handler_function;
2551   Database_qualified_name pkgname(&null_clex_str, &null_clex_str);
2552 
2553   if (unlikely(has_named_parameters(item_list)))
2554   {
2555     /*
2556       The syntax "db.foo(expr AS p1, expr AS p2, ...) is invalid,
2557       and has been rejected during syntactic parsing already,
2558       because a stored function call may not have named parameters.
2559 
2560       The syntax "foo(expr AS p1, expr AS p2, ...)" is correct,
2561       because it can refer to a User Defined Function call.
2562       For a Stored Function however, this has no semantic.
2563     */
2564     my_error(ER_WRONG_PARAMETERS_TO_STORED_FCT, MYF(0), name->str);
2565     return NULL;
2566   }
2567 
2568   if (item_list != NULL)
2569     arg_count= item_list->elements;
2570 
2571   qname= new (thd->mem_root) sp_name(db, name, use_explicit_name);
2572   if (unlikely(sph->sp_resolve_package_routine(thd, thd->lex->sphead,
2573                                                qname, &sph, &pkgname)))
2574     return NULL;
2575   sph->add_used_routine(lex, thd, qname);
2576   if (pkgname.m_name.length)
2577     sp_handler_package_body.add_used_routine(lex, thd, &pkgname);
2578   Name_resolution_context *ctx= lex->current_context();
2579   if (arg_count > 0)
2580     func= new (thd->mem_root) Item_func_sp(thd, ctx, qname, sph, *item_list);
2581   else
2582     func= new (thd->mem_root) Item_func_sp(thd, ctx, qname, sph);
2583 
2584   lex->safe_to_cache_query= 0;
2585   return func;
2586 }
2587 
2588 
2589 Item*
create_func(THD * thd,LEX_CSTRING * name,List<Item> * item_list)2590 Create_native_func::create_func(THD *thd, LEX_CSTRING *name, List<Item> *item_list)
2591 {
2592   if (unlikely(has_named_parameters(item_list)))
2593   {
2594     my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name->str);
2595     return NULL;
2596   }
2597 
2598   return create_native(thd, name, item_list);
2599 }
2600 
2601 
2602 Item*
create_func(THD * thd,LEX_CSTRING * name,List<Item> * item_list)2603 Create_func_arg0::create_func(THD *thd, LEX_CSTRING *name, List<Item> *item_list)
2604 {
2605   int arg_count= 0;
2606 
2607   if (item_list != NULL)
2608     arg_count= item_list->elements;
2609 
2610   if (unlikely(arg_count != 0))
2611   {
2612     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
2613     return NULL;
2614   }
2615 
2616   return create_builder(thd);
2617 }
2618 
2619 
2620 Item*
create_func(THD * thd,LEX_CSTRING * name,List<Item> * item_list)2621 Create_func_arg1::create_func(THD *thd, LEX_CSTRING *name, List<Item> *item_list)
2622 {
2623   int arg_count= 0;
2624 
2625   if (item_list)
2626     arg_count= item_list->elements;
2627 
2628   if (unlikely(arg_count != 1))
2629   {
2630     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
2631     return NULL;
2632   }
2633 
2634   Item *param_1= item_list->pop();
2635 
2636   if (unlikely(! param_1->is_autogenerated_name()))
2637   {
2638     my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name->str);
2639     return NULL;
2640   }
2641 
2642   return create_1_arg(thd, param_1);
2643 }
2644 
2645 
2646 Item*
create_func(THD * thd,LEX_CSTRING * name,List<Item> * item_list)2647 Create_func_arg2::create_func(THD *thd, LEX_CSTRING *name, List<Item> *item_list)
2648 {
2649   int arg_count= 0;
2650 
2651   if (item_list)
2652     arg_count= item_list->elements;
2653 
2654   if (unlikely(arg_count != 2))
2655   {
2656     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
2657     return NULL;
2658   }
2659 
2660   Item *param_1= item_list->pop();
2661   Item *param_2= item_list->pop();
2662 
2663   if (unlikely(!param_1->is_autogenerated_name() ||
2664                !param_2->is_autogenerated_name()))
2665   {
2666     my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name->str);
2667     return NULL;
2668   }
2669 
2670   return create_2_arg(thd, param_1, param_2);
2671 }
2672 
2673 
2674 Item*
create_func(THD * thd,LEX_CSTRING * name,List<Item> * item_list)2675 Create_func_arg3::create_func(THD *thd, LEX_CSTRING *name, List<Item> *item_list)
2676 {
2677   int arg_count= 0;
2678 
2679   if (item_list)
2680     arg_count= item_list->elements;
2681 
2682   if (unlikely(arg_count != 3))
2683   {
2684     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
2685     return NULL;
2686   }
2687 
2688   Item *param_1= item_list->pop();
2689   Item *param_2= item_list->pop();
2690   Item *param_3= item_list->pop();
2691 
2692   if (unlikely(!param_1->is_autogenerated_name() ||
2693                !param_2->is_autogenerated_name() ||
2694                !param_3->is_autogenerated_name()))
2695   {
2696     my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name->str);
2697     return NULL;
2698   }
2699 
2700   return create_3_arg(thd, param_1, param_2, param_3);
2701 }
2702 
2703 
2704 Create_func_abs Create_func_abs::s_singleton;
2705 
2706 Item*
create_1_arg(THD * thd,Item * arg1)2707 Create_func_abs::create_1_arg(THD *thd, Item *arg1)
2708 {
2709   return new (thd->mem_root) Item_func_abs(thd, arg1);
2710 }
2711 
2712 
2713 Create_func_acos Create_func_acos::s_singleton;
2714 
2715 Item*
create_1_arg(THD * thd,Item * arg1)2716 Create_func_acos::create_1_arg(THD *thd, Item *arg1)
2717 {
2718   return new (thd->mem_root) Item_func_acos(thd, arg1);
2719 }
2720 
2721 
2722 Create_func_addtime Create_func_addtime::s_singleton;
2723 
2724 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)2725 Create_func_addtime::create_2_arg(THD *thd, Item *arg1, Item *arg2)
2726 {
2727   return new (thd->mem_root) Item_func_add_time(thd, arg1, arg2, false);
2728 }
2729 
2730 
2731 Create_func_aes_encrypt Create_func_aes_encrypt::s_singleton;
2732 
2733 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)2734 Create_func_aes_encrypt::create_2_arg(THD *thd, Item *arg1, Item *arg2)
2735 {
2736   return new (thd->mem_root) Item_func_aes_encrypt(thd, arg1, arg2);
2737 }
2738 
2739 
2740 Create_func_aes_decrypt Create_func_aes_decrypt::s_singleton;
2741 
2742 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)2743 Create_func_aes_decrypt::create_2_arg(THD *thd, Item *arg1, Item *arg2)
2744 {
2745   return new (thd->mem_root) Item_func_aes_decrypt(thd, arg1, arg2);
2746 }
2747 
2748 
2749 Create_func_asin Create_func_asin::s_singleton;
2750 
2751 Item*
create_1_arg(THD * thd,Item * arg1)2752 Create_func_asin::create_1_arg(THD *thd, Item *arg1)
2753 {
2754   return new (thd->mem_root) Item_func_asin(thd, arg1);
2755 }
2756 
2757 
2758 Create_func_atan Create_func_atan::s_singleton;
2759 
2760 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)2761 Create_func_atan::create_native(THD *thd, LEX_CSTRING *name,
2762                                 List<Item> *item_list)
2763 {
2764   Item* func= NULL;
2765   int arg_count= 0;
2766 
2767   if (item_list != NULL)
2768     arg_count= item_list->elements;
2769 
2770   switch (arg_count) {
2771   case 1:
2772   {
2773     Item *param_1= item_list->pop();
2774     func= new (thd->mem_root) Item_func_atan(thd, param_1);
2775     break;
2776   }
2777   case 2:
2778   {
2779     Item *param_1= item_list->pop();
2780     Item *param_2= item_list->pop();
2781     func= new (thd->mem_root) Item_func_atan(thd, param_1, param_2);
2782     break;
2783   }
2784   default:
2785   {
2786     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
2787     break;
2788   }
2789   }
2790 
2791   return func;
2792 }
2793 
2794 
2795 Create_func_benchmark Create_func_benchmark::s_singleton;
2796 
2797 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)2798 Create_func_benchmark::create_2_arg(THD *thd, Item *arg1, Item *arg2)
2799 {
2800   thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
2801   return new (thd->mem_root) Item_func_benchmark(thd, arg1, arg2);
2802 }
2803 
2804 
2805 Create_func_bin Create_func_bin::s_singleton;
2806 
2807 Item*
create_1_arg(THD * thd,Item * arg1)2808 Create_func_bin::create_1_arg(THD *thd, Item *arg1)
2809 {
2810   Item *i10= new (thd->mem_root) Item_int(thd, (int32) 10,2);
2811   Item *i2= new (thd->mem_root) Item_int(thd, (int32) 2,1);
2812   return new (thd->mem_root) Item_func_conv(thd, arg1, i10, i2);
2813 }
2814 
2815 
2816 Create_func_binlog_gtid_pos Create_func_binlog_gtid_pos::s_singleton;
2817 
2818 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)2819 Create_func_binlog_gtid_pos::create_2_arg(THD *thd, Item *arg1, Item *arg2)
2820 {
2821 #ifdef HAVE_REPLICATION
2822   if (unlikely(!mysql_bin_log.is_open()))
2823 #endif
2824   {
2825     my_error(ER_NO_BINARY_LOGGING, MYF(0));
2826     return NULL;
2827   }
2828   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
2829   return new (thd->mem_root) Item_func_binlog_gtid_pos(thd, arg1, arg2);
2830 }
2831 
2832 
2833 Create_func_bit_count Create_func_bit_count::s_singleton;
2834 
2835 Item*
create_1_arg(THD * thd,Item * arg1)2836 Create_func_bit_count::create_1_arg(THD *thd, Item *arg1)
2837 {
2838   return new (thd->mem_root) Item_func_bit_count(thd, arg1);
2839 }
2840 
2841 
2842 Create_func_bit_length Create_func_bit_length::s_singleton;
2843 
2844 Item*
create_1_arg(THD * thd,Item * arg1)2845 Create_func_bit_length::create_1_arg(THD *thd, Item *arg1)
2846 {
2847   return new (thd->mem_root) Item_func_bit_length(thd, arg1);
2848 }
2849 
2850 
2851 Create_func_ceiling Create_func_ceiling::s_singleton;
2852 
2853 Item*
create_1_arg(THD * thd,Item * arg1)2854 Create_func_ceiling::create_1_arg(THD *thd, Item *arg1)
2855 {
2856   return new (thd->mem_root) Item_func_ceiling(thd, arg1);
2857 }
2858 
2859 
2860 Create_func_chr Create_func_chr::s_singleton;
2861 
2862 Item*
create_1_arg(THD * thd,Item * arg1)2863 Create_func_chr::create_1_arg(THD *thd, Item *arg1)
2864 {
2865   CHARSET_INFO *cs_db= thd->variables.collation_database;
2866   return new (thd->mem_root) Item_func_chr(thd, arg1, cs_db);
2867 }
2868 
2869 
2870 Create_func_char_length Create_func_char_length::s_singleton;
2871 
2872 Item*
create_1_arg(THD * thd,Item * arg1)2873 Create_func_char_length::create_1_arg(THD *thd, Item *arg1)
2874 {
2875   return new (thd->mem_root) Item_func_char_length(thd, arg1);
2876 }
2877 
2878 
2879 Create_func_coercibility Create_func_coercibility::s_singleton;
2880 
2881 Item*
create_1_arg(THD * thd,Item * arg1)2882 Create_func_coercibility::create_1_arg(THD *thd, Item *arg1)
2883 {
2884   return new (thd->mem_root) Item_func_coercibility(thd, arg1);
2885 }
2886 
2887 
2888 Create_func_dyncol_check Create_func_dyncol_check::s_singleton;
2889 
2890 Item*
create_1_arg(THD * thd,Item * arg1)2891 Create_func_dyncol_check::create_1_arg(THD *thd, Item *arg1)
2892 {
2893   return new (thd->mem_root) Item_func_dyncol_check(thd, arg1);
2894 }
2895 
2896 Create_func_dyncol_exists Create_func_dyncol_exists::s_singleton;
2897 
2898 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)2899 Create_func_dyncol_exists::create_2_arg(THD *thd, Item *arg1, Item *arg2)
2900 {
2901   return new (thd->mem_root) Item_func_dyncol_exists(thd, arg1, arg2);
2902 }
2903 
2904 Create_func_dyncol_list Create_func_dyncol_list::s_singleton;
2905 
2906 Item*
create_1_arg(THD * thd,Item * arg1)2907 Create_func_dyncol_list::create_1_arg(THD *thd, Item *arg1)
2908 {
2909   return new (thd->mem_root) Item_func_dyncol_list(thd, arg1);
2910 }
2911 
2912 Create_func_dyncol_json Create_func_dyncol_json::s_singleton;
2913 
2914 Item*
create_1_arg(THD * thd,Item * arg1)2915 Create_func_dyncol_json::create_1_arg(THD *thd, Item *arg1)
2916 {
2917   return new (thd->mem_root) Item_func_dyncol_json(thd, arg1);
2918 }
2919 
2920 Create_func_concat Create_func_concat::s_singleton;
2921 
2922 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)2923 Create_func_concat::create_native(THD *thd, LEX_CSTRING *name,
2924                                   List<Item> *item_list)
2925 {
2926   int arg_count= 0;
2927 
2928   if (item_list != NULL)
2929     arg_count= item_list->elements;
2930 
2931   if (unlikely(arg_count < 1))
2932   {
2933     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
2934     return NULL;
2935   }
2936 
2937   return thd->variables.sql_mode & MODE_ORACLE ?
2938     new (thd->mem_root) Item_func_concat_operator_oracle(thd, *item_list) :
2939     new (thd->mem_root) Item_func_concat(thd, *item_list);
2940 }
2941 
2942 Create_func_concat_operator_oracle
2943   Create_func_concat_operator_oracle::s_singleton;
2944 
2945 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)2946 Create_func_concat_operator_oracle::create_native(THD *thd, LEX_CSTRING *name,
2947                                                   List<Item> *item_list)
2948 {
2949   int arg_count= 0;
2950 
2951   if (item_list != NULL)
2952     arg_count= item_list->elements;
2953 
2954   if (unlikely(arg_count < 1))
2955   {
2956     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
2957     return NULL;
2958   }
2959 
2960   return new (thd->mem_root) Item_func_concat_operator_oracle(thd, *item_list);
2961 }
2962 
2963 Create_func_decode_histogram Create_func_decode_histogram::s_singleton;
2964 
2965 Item *
create_2_arg(THD * thd,Item * arg1,Item * arg2)2966 Create_func_decode_histogram::create_2_arg(THD *thd, Item *arg1, Item *arg2)
2967 {
2968   return new (thd->mem_root) Item_func_decode_histogram(thd, arg1, arg2);
2969 }
2970 
2971 Create_func_decode_oracle Create_func_decode_oracle::s_singleton;
2972 
2973 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)2974 Create_func_decode_oracle::create_native(THD *thd, LEX_CSTRING *name,
2975                                          List<Item> *item_list)
2976 {
2977   uint arg_count= item_list ? item_list->elements : 0;
2978   if (unlikely(arg_count < 3))
2979   {
2980     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
2981     return NULL;
2982   }
2983   return new (thd->mem_root) Item_func_decode_oracle(thd, *item_list);
2984 }
2985 
2986 Create_func_concat_ws Create_func_concat_ws::s_singleton;
2987 
2988 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)2989 Create_func_concat_ws::create_native(THD *thd, LEX_CSTRING *name,
2990                                      List<Item> *item_list)
2991 {
2992   int arg_count= 0;
2993 
2994   if (item_list != NULL)
2995     arg_count= item_list->elements;
2996 
2997   /* "WS" stands for "With Separator": this function takes 2+ arguments */
2998   if (unlikely(arg_count < 2))
2999   {
3000     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3001     return NULL;
3002   }
3003 
3004   return new (thd->mem_root) Item_func_concat_ws(thd, *item_list);
3005 }
3006 
3007 
3008 Create_func_compress Create_func_compress::s_singleton;
3009 
3010 Item*
create_1_arg(THD * thd,Item * arg1)3011 Create_func_compress::create_1_arg(THD *thd, Item *arg1)
3012 {
3013   return new (thd->mem_root) Item_func_compress(thd, arg1);
3014 }
3015 
3016 
3017 Create_func_connection_id Create_func_connection_id::s_singleton;
3018 
3019 Item*
create_builder(THD * thd)3020 Create_func_connection_id::create_builder(THD *thd)
3021 {
3022   thd->lex->safe_to_cache_query= 0;
3023   return new (thd->mem_root) Item_func_connection_id(thd);
3024 }
3025 
3026 
3027 Create_func_nvl2 Create_func_nvl2::s_singleton;
3028 
3029 Item*
create_3_arg(THD * thd,Item * arg1,Item * arg2,Item * arg3)3030 Create_func_nvl2::create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3)
3031 {
3032   return new (thd->mem_root) Item_func_nvl2(thd, arg1, arg2, arg3);
3033 }
3034 
3035 
3036 Create_func_conv Create_func_conv::s_singleton;
3037 
3038 Item*
create_3_arg(THD * thd,Item * arg1,Item * arg2,Item * arg3)3039 Create_func_conv::create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3)
3040 {
3041   return new (thd->mem_root) Item_func_conv(thd, arg1, arg2, arg3);
3042 }
3043 
3044 
3045 Create_func_convert_tz Create_func_convert_tz::s_singleton;
3046 
3047 Item*
create_3_arg(THD * thd,Item * arg1,Item * arg2,Item * arg3)3048 Create_func_convert_tz::create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3)
3049 {
3050   return new (thd->mem_root) Item_func_convert_tz(thd, arg1, arg2, arg3);
3051 }
3052 
3053 
3054 Create_func_cos Create_func_cos::s_singleton;
3055 
3056 Item*
create_1_arg(THD * thd,Item * arg1)3057 Create_func_cos::create_1_arg(THD *thd, Item *arg1)
3058 {
3059   return new (thd->mem_root) Item_func_cos(thd, arg1);
3060 }
3061 
3062 
3063 Create_func_cot Create_func_cot::s_singleton;
3064 
3065 Item*
create_1_arg(THD * thd,Item * arg1)3066 Create_func_cot::create_1_arg(THD *thd, Item *arg1)
3067 {
3068   return new (thd->mem_root) Item_func_cot(thd, arg1);
3069 }
3070 
3071 
3072 Create_func_crc32 Create_func_crc32::s_singleton;
3073 
3074 Item*
create_1_arg(THD * thd,Item * arg1)3075 Create_func_crc32::create_1_arg(THD *thd, Item *arg1)
3076 {
3077   return new (thd->mem_root) Item_func_crc32(thd, arg1);
3078 }
3079 
3080 Create_func_datediff Create_func_datediff::s_singleton;
3081 
3082 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)3083 Create_func_datediff::create_2_arg(THD *thd, Item *arg1, Item *arg2)
3084 {
3085   Item *i1= new (thd->mem_root) Item_func_to_days(thd, arg1);
3086   Item *i2= new (thd->mem_root) Item_func_to_days(thd, arg2);
3087 
3088   return new (thd->mem_root) Item_func_minus(thd, i1, i2);
3089 }
3090 
3091 
3092 Create_func_dayname Create_func_dayname::s_singleton;
3093 
3094 Item*
create_1_arg(THD * thd,Item * arg1)3095 Create_func_dayname::create_1_arg(THD *thd, Item *arg1)
3096 {
3097   return new (thd->mem_root) Item_func_dayname(thd, arg1);
3098 }
3099 
3100 
3101 Create_func_dayofmonth Create_func_dayofmonth::s_singleton;
3102 
3103 Item*
create_1_arg(THD * thd,Item * arg1)3104 Create_func_dayofmonth::create_1_arg(THD *thd, Item *arg1)
3105 {
3106   return new (thd->mem_root) Item_func_dayofmonth(thd, arg1);
3107 }
3108 
3109 
3110 Create_func_dayofweek Create_func_dayofweek::s_singleton;
3111 
3112 Item*
create_1_arg(THD * thd,Item * arg1)3113 Create_func_dayofweek::create_1_arg(THD *thd, Item *arg1)
3114 {
3115   return new (thd->mem_root) Item_func_weekday(thd, arg1, 1);
3116 }
3117 
3118 
3119 Create_func_dayofyear Create_func_dayofyear::s_singleton;
3120 
3121 Item*
create_1_arg(THD * thd,Item * arg1)3122 Create_func_dayofyear::create_1_arg(THD *thd, Item *arg1)
3123 {
3124   return new (thd->mem_root) Item_func_dayofyear(thd, arg1);
3125 }
3126 
3127 
3128 Create_func_degrees Create_func_degrees::s_singleton;
3129 
3130 Item*
create_1_arg(THD * thd,Item * arg1)3131 Create_func_degrees::create_1_arg(THD *thd, Item *arg1)
3132 {
3133   return new (thd->mem_root) Item_func_units(thd, (char*) "degrees", arg1,
3134                                              180/M_PI, 0.0);
3135 }
3136 
3137 
3138 Create_func_des_decrypt Create_func_des_decrypt::s_singleton;
3139 
3140 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3141 Create_func_des_decrypt::create_native(THD *thd, LEX_CSTRING *name,
3142                                        List<Item> *item_list)
3143 {
3144   Item *func= NULL;
3145   int arg_count= 0;
3146 
3147   if (item_list != NULL)
3148     arg_count= item_list->elements;
3149 
3150   switch (arg_count) {
3151   case 1:
3152   {
3153     Item *param_1= item_list->pop();
3154     func= new (thd->mem_root) Item_func_des_decrypt(thd, param_1);
3155     break;
3156   }
3157   case 2:
3158   {
3159     Item *param_1= item_list->pop();
3160     Item *param_2= item_list->pop();
3161     func= new (thd->mem_root) Item_func_des_decrypt(thd, param_1, param_2);
3162     break;
3163   }
3164   default:
3165   {
3166     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3167     break;
3168   }
3169   }
3170 
3171   return func;
3172 }
3173 
3174 
3175 Create_func_des_encrypt Create_func_des_encrypt::s_singleton;
3176 
3177 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3178 Create_func_des_encrypt::create_native(THD *thd, LEX_CSTRING *name,
3179                                        List<Item> *item_list)
3180 {
3181   Item *func= NULL;
3182   int arg_count= 0;
3183 
3184   if (item_list != NULL)
3185     arg_count= item_list->elements;
3186 
3187   switch (arg_count) {
3188   case 1:
3189   {
3190     Item *param_1= item_list->pop();
3191     func= new (thd->mem_root) Item_func_des_encrypt(thd, param_1);
3192     break;
3193   }
3194   case 2:
3195   {
3196     Item *param_1= item_list->pop();
3197     Item *param_2= item_list->pop();
3198     func= new (thd->mem_root) Item_func_des_encrypt(thd, param_1, param_2);
3199     break;
3200   }
3201   default:
3202   {
3203     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3204     break;
3205   }
3206   }
3207 
3208   return func;
3209 }
3210 
3211 
3212 Create_func_elt Create_func_elt::s_singleton;
3213 
3214 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3215 Create_func_elt::create_native(THD *thd, LEX_CSTRING *name,
3216                                List<Item> *item_list)
3217 {
3218   int arg_count= 0;
3219 
3220   if (item_list != NULL)
3221     arg_count= item_list->elements;
3222 
3223   if (unlikely(arg_count < 2))
3224   {
3225     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3226     return NULL;
3227   }
3228 
3229   return new (thd->mem_root) Item_func_elt(thd, *item_list);
3230 }
3231 
3232 
3233 Create_func_encode Create_func_encode::s_singleton;
3234 
3235 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)3236 Create_func_encode::create_2_arg(THD *thd, Item *arg1, Item *arg2)
3237 {
3238   return new (thd->mem_root) Item_func_encode(thd, arg1, arg2);
3239 }
3240 
3241 
3242 Create_func_encrypt Create_func_encrypt::s_singleton;
3243 
3244 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3245 Create_func_encrypt::create_native(THD *thd, LEX_CSTRING *name,
3246                                    List<Item> *item_list)
3247 {
3248   Item *func= NULL;
3249   int arg_count= 0;
3250 
3251   if (item_list != NULL)
3252     arg_count= item_list->elements;
3253 
3254   switch (arg_count) {
3255   case 1:
3256   {
3257     Item *param_1= item_list->pop();
3258     func= new (thd->mem_root) Item_func_encrypt(thd, param_1);
3259     thd->lex->uncacheable(UNCACHEABLE_RAND);
3260     break;
3261   }
3262   case 2:
3263   {
3264     Item *param_1= item_list->pop();
3265     Item *param_2= item_list->pop();
3266     func= new (thd->mem_root) Item_func_encrypt(thd, param_1, param_2);
3267     break;
3268   }
3269   default:
3270   {
3271     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3272     break;
3273   }
3274   }
3275 
3276   return func;
3277 }
3278 
3279 
3280 Create_func_exp Create_func_exp::s_singleton;
3281 
3282 Item*
create_1_arg(THD * thd,Item * arg1)3283 Create_func_exp::create_1_arg(THD *thd, Item *arg1)
3284 {
3285   return new (thd->mem_root) Item_func_exp(thd, arg1);
3286 }
3287 
3288 
3289 Create_func_export_set Create_func_export_set::s_singleton;
3290 
3291 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3292 Create_func_export_set::create_native(THD *thd, LEX_CSTRING *name,
3293                                       List<Item> *item_list)
3294 {
3295   Item *func= NULL;
3296   int arg_count= 0;
3297 
3298   if (item_list != NULL)
3299     arg_count= item_list->elements;
3300 
3301   switch (arg_count) {
3302   case 3:
3303   {
3304     Item *param_1= item_list->pop();
3305     Item *param_2= item_list->pop();
3306     Item *param_3= item_list->pop();
3307     func= new (thd->mem_root) Item_func_export_set(thd, param_1, param_2, param_3);
3308     break;
3309   }
3310   case 4:
3311   {
3312     Item *param_1= item_list->pop();
3313     Item *param_2= item_list->pop();
3314     Item *param_3= item_list->pop();
3315     Item *param_4= item_list->pop();
3316     func= new (thd->mem_root) Item_func_export_set(thd, param_1, param_2, param_3,
3317                                                    param_4);
3318     break;
3319   }
3320   case 5:
3321   {
3322     Item *param_1= item_list->pop();
3323     Item *param_2= item_list->pop();
3324     Item *param_3= item_list->pop();
3325     Item *param_4= item_list->pop();
3326     Item *param_5= item_list->pop();
3327     func= new (thd->mem_root) Item_func_export_set(thd, param_1, param_2, param_3,
3328                                                    param_4, param_5);
3329     break;
3330   }
3331   default:
3332   {
3333     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3334     break;
3335   }
3336   }
3337 
3338   return func;
3339 }
3340 
3341 
3342 Create_func_field Create_func_field::s_singleton;
3343 
3344 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3345 Create_func_field::create_native(THD *thd, LEX_CSTRING *name,
3346                                  List<Item> *item_list)
3347 {
3348   int arg_count= 0;
3349 
3350   if (item_list != NULL)
3351     arg_count= item_list->elements;
3352 
3353   if (unlikely(arg_count < 2))
3354   {
3355     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3356     return NULL;
3357   }
3358 
3359   return new (thd->mem_root) Item_func_field(thd, *item_list);
3360 }
3361 
3362 
3363 Create_func_find_in_set Create_func_find_in_set::s_singleton;
3364 
3365 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)3366 Create_func_find_in_set::create_2_arg(THD *thd, Item *arg1, Item *arg2)
3367 {
3368   return new (thd->mem_root) Item_func_find_in_set(thd, arg1, arg2);
3369 }
3370 
3371 
3372 Create_func_floor Create_func_floor::s_singleton;
3373 
3374 Item*
create_1_arg(THD * thd,Item * arg1)3375 Create_func_floor::create_1_arg(THD *thd, Item *arg1)
3376 {
3377   return new (thd->mem_root) Item_func_floor(thd, arg1);
3378 }
3379 
3380 
3381 Create_func_format Create_func_format::s_singleton;
3382 
3383 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3384 Create_func_format::create_native(THD *thd, LEX_CSTRING *name,
3385                                   List<Item> *item_list)
3386 {
3387   Item *func= NULL;
3388   int arg_count= item_list ? item_list->elements : 0;
3389 
3390   switch (arg_count) {
3391   case 2:
3392   {
3393     Item *param_1= item_list->pop();
3394     Item *param_2= item_list->pop();
3395     func= new (thd->mem_root) Item_func_format(thd, param_1, param_2);
3396     break;
3397   }
3398   case 3:
3399   {
3400     Item *param_1= item_list->pop();
3401     Item *param_2= item_list->pop();
3402     Item *param_3= item_list->pop();
3403     func= new (thd->mem_root) Item_func_format(thd, param_1, param_2, param_3);
3404     break;
3405   }
3406   default:
3407     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3408     break;
3409   }
3410 
3411   return func;
3412 }
3413 
3414 
3415 Create_func_from_base64 Create_func_from_base64::s_singleton;
3416 
3417 
3418 Item *
create_1_arg(THD * thd,Item * arg1)3419 Create_func_from_base64::create_1_arg(THD *thd, Item *arg1)
3420 {
3421   return new (thd->mem_root) Item_func_from_base64(thd, arg1);
3422 }
3423 
3424 
3425 Create_func_found_rows Create_func_found_rows::s_singleton;
3426 
3427 Item*
create_builder(THD * thd)3428 Create_func_found_rows::create_builder(THD *thd)
3429 {
3430   DBUG_ENTER("Create_func_found_rows::create");
3431   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
3432   thd->lex->safe_to_cache_query= 0;
3433   DBUG_RETURN(new (thd->mem_root) Item_func_found_rows(thd));
3434 }
3435 
3436 
3437 Create_func_from_days Create_func_from_days::s_singleton;
3438 
3439 Item*
create_1_arg(THD * thd,Item * arg1)3440 Create_func_from_days::create_1_arg(THD *thd, Item *arg1)
3441 {
3442   return new (thd->mem_root) Item_func_from_days(thd, arg1);
3443 }
3444 
3445 
3446 Create_func_from_unixtime Create_func_from_unixtime::s_singleton;
3447 
3448 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3449 Create_func_from_unixtime::create_native(THD *thd, LEX_CSTRING *name,
3450                                          List<Item> *item_list)
3451 {
3452   Item *func= NULL;
3453   int arg_count= 0;
3454 
3455   if (item_list != NULL)
3456     arg_count= item_list->elements;
3457 
3458   switch (arg_count) {
3459   case 1:
3460   {
3461     Item *param_1= item_list->pop();
3462     func= new (thd->mem_root) Item_func_from_unixtime(thd, param_1);
3463     break;
3464   }
3465   case 2:
3466   {
3467     Item *param_1= item_list->pop();
3468     Item *param_2= item_list->pop();
3469     Item *ut= new (thd->mem_root) Item_func_from_unixtime(thd, param_1);
3470     func= new (thd->mem_root) Item_func_date_format(thd, ut, param_2);
3471     break;
3472   }
3473   default:
3474   {
3475     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3476     break;
3477   }
3478   }
3479 
3480   return func;
3481 }
3482 
3483 
3484 
3485 Create_func_get_lock Create_func_get_lock::s_singleton;
3486 
3487 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)3488 Create_func_get_lock::create_2_arg(THD *thd, Item *arg1, Item *arg2)
3489 {
3490   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
3491   thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
3492   return new (thd->mem_root) Item_func_get_lock(thd, arg1, arg2);
3493 }
3494 
3495 
3496 Create_func_greatest Create_func_greatest::s_singleton;
3497 
3498 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3499 Create_func_greatest::create_native(THD *thd, LEX_CSTRING *name,
3500                                     List<Item> *item_list)
3501 {
3502   int arg_count= 0;
3503 
3504   if (item_list != NULL)
3505     arg_count= item_list->elements;
3506 
3507   if (unlikely(arg_count < 2))
3508   {
3509     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3510     return NULL;
3511   }
3512 
3513   return new (thd->mem_root) Item_func_max(thd, *item_list);
3514 }
3515 
3516 
3517 Create_func_hex Create_func_hex::s_singleton;
3518 
3519 Item*
create_1_arg(THD * thd,Item * arg1)3520 Create_func_hex::create_1_arg(THD *thd, Item *arg1)
3521 {
3522   return new (thd->mem_root) Item_func_hex(thd, arg1);
3523 }
3524 
3525 
3526 Create_func_ifnull Create_func_ifnull::s_singleton;
3527 
3528 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)3529 Create_func_ifnull::create_2_arg(THD *thd, Item *arg1, Item *arg2)
3530 {
3531   return new (thd->mem_root) Item_func_ifnull(thd, arg1, arg2);
3532 }
3533 
3534 
3535 Create_func_instr Create_func_instr::s_singleton;
3536 
3537 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)3538 Create_func_instr::create_2_arg(THD *thd, Item *arg1, Item *arg2)
3539 {
3540   return new (thd->mem_root) Item_func_locate(thd, arg1, arg2);
3541 }
3542 
3543 
3544 Create_func_is_free_lock Create_func_is_free_lock::s_singleton;
3545 
3546 Item*
create_1_arg(THD * thd,Item * arg1)3547 Create_func_is_free_lock::create_1_arg(THD *thd, Item *arg1)
3548 {
3549   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
3550   thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
3551   return new (thd->mem_root) Item_func_is_free_lock(thd, arg1);
3552 }
3553 
3554 
3555 Create_func_is_used_lock Create_func_is_used_lock::s_singleton;
3556 
3557 Item*
create_1_arg(THD * thd,Item * arg1)3558 Create_func_is_used_lock::create_1_arg(THD *thd, Item *arg1)
3559 {
3560   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
3561   thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
3562   return new (thd->mem_root) Item_func_is_used_lock(thd, arg1);
3563 }
3564 
3565 
3566 Create_func_isnull Create_func_isnull::s_singleton;
3567 
3568 Item*
create_1_arg(THD * thd,Item * arg1)3569 Create_func_isnull::create_1_arg(THD *thd, Item *arg1)
3570 {
3571   return new (thd->mem_root) Item_func_isnull(thd, arg1);
3572 }
3573 
3574 
3575 Create_func_json_exists Create_func_json_exists::s_singleton;
3576 
3577 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)3578 Create_func_json_exists::create_2_arg(THD *thd, Item *arg1, Item *arg2)
3579 {
3580   status_var_increment(current_thd->status_var.feature_json);
3581   return new (thd->mem_root) Item_func_json_exists(thd, arg1, arg2);
3582 }
3583 
3584 
3585 Create_func_json_detailed Create_func_json_detailed::s_singleton;
3586 
3587 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3588 Create_func_json_detailed::create_native(THD *thd, LEX_CSTRING *name,
3589                                      List<Item> *item_list)
3590 {
3591   Item *func= NULL;
3592   int arg_count= 0;
3593 
3594   if (item_list != NULL)
3595     arg_count= item_list->elements;
3596 
3597   if (unlikely(arg_count < 1 || arg_count > 2 /* json_doc, [path]...*/))
3598   {
3599     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3600   }
3601   else
3602   {
3603     func= new (thd->mem_root) Item_func_json_format(thd, *item_list);
3604   }
3605 
3606   status_var_increment(current_thd->status_var.feature_json);
3607   return func;
3608 }
3609 
3610 
3611 Create_func_json_loose Create_func_json_loose::s_singleton;
3612 
3613 Item*
create_1_arg(THD * thd,Item * arg1)3614 Create_func_json_loose::create_1_arg(THD *thd, Item *arg1)
3615 {
3616   status_var_increment(current_thd->status_var.feature_json);
3617   return new (thd->mem_root) Item_func_json_format(thd, arg1,
3618                Item_func_json_format::LOOSE);
3619 }
3620 
3621 
3622 Create_func_json_compact Create_func_json_compact::s_singleton;
3623 
3624 Item*
create_1_arg(THD * thd,Item * arg1)3625 Create_func_json_compact::create_1_arg(THD *thd, Item *arg1)
3626 {
3627   status_var_increment(current_thd->status_var.feature_json);
3628   return new (thd->mem_root) Item_func_json_format(thd, arg1,
3629                Item_func_json_format::COMPACT);
3630 }
3631 
3632 
3633 Create_func_json_valid Create_func_json_valid::s_singleton;
3634 
3635 Item*
create_1_arg(THD * thd,Item * arg1)3636 Create_func_json_valid::create_1_arg(THD *thd, Item *arg1)
3637 {
3638   status_var_increment(current_thd->status_var.feature_json);
3639   return new (thd->mem_root) Item_func_json_valid(thd, arg1);
3640 }
3641 
3642 
3643 Create_func_json_type Create_func_json_type::s_singleton;
3644 
3645 Item*
create_1_arg(THD * thd,Item * arg1)3646 Create_func_json_type::create_1_arg(THD *thd, Item *arg1)
3647 {
3648   status_var_increment(current_thd->status_var.feature_json);
3649   return new (thd->mem_root) Item_func_json_type(thd, arg1);
3650 }
3651 
3652 
3653 Create_func_json_depth Create_func_json_depth::s_singleton;
3654 
3655 Item*
create_1_arg(THD * thd,Item * arg1)3656 Create_func_json_depth::create_1_arg(THD *thd, Item *arg1)
3657 {
3658   status_var_increment(current_thd->status_var.feature_json);
3659   return new (thd->mem_root) Item_func_json_depth(thd, arg1);
3660 }
3661 
3662 
3663 Create_func_json_value Create_func_json_value::s_singleton;
3664 
3665 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)3666 Create_func_json_value::create_2_arg(THD *thd, Item *arg1, Item *arg2)
3667 {
3668   status_var_increment(current_thd->status_var.feature_json);
3669   return new (thd->mem_root) Item_func_json_value(thd, arg1, arg2);
3670 }
3671 
3672 
3673 Create_func_json_query Create_func_json_query::s_singleton;
3674 
3675 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)3676 Create_func_json_query::create_2_arg(THD *thd, Item *arg1, Item *arg2)
3677 {
3678   status_var_increment(current_thd->status_var.feature_json);
3679   return new (thd->mem_root) Item_func_json_query(thd, arg1, arg2);
3680 }
3681 
3682 
3683 Create_func_json_quote Create_func_json_quote::s_singleton;
3684 
3685 Item*
create_1_arg(THD * thd,Item * arg1)3686 Create_func_json_quote::create_1_arg(THD *thd, Item *arg1)
3687 {
3688   status_var_increment(current_thd->status_var.feature_json);
3689   return new (thd->mem_root) Item_func_json_quote(thd, arg1);
3690 }
3691 
3692 
3693 Create_func_json_unquote Create_func_json_unquote::s_singleton;
3694 
3695 Item*
create_1_arg(THD * thd,Item * arg1)3696 Create_func_json_unquote::create_1_arg(THD *thd, Item *arg1)
3697 {
3698   status_var_increment(current_thd->status_var.feature_json);
3699   return new (thd->mem_root) Item_func_json_unquote(thd, arg1);
3700 }
3701 
3702 
3703 Create_func_last_day Create_func_last_day::s_singleton;
3704 
3705 Item*
create_1_arg(THD * thd,Item * arg1)3706 Create_func_last_day::create_1_arg(THD *thd, Item *arg1)
3707 {
3708   return new (thd->mem_root) Item_func_last_day(thd, arg1);
3709 }
3710 
3711 
3712 Create_func_json_array Create_func_json_array::s_singleton;
3713 
3714 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3715 Create_func_json_array::create_native(THD *thd, LEX_CSTRING *name,
3716                                       List<Item> *item_list)
3717 {
3718   Item *func;
3719 
3720   if (item_list != NULL)
3721   {
3722     func= new (thd->mem_root) Item_func_json_array(thd, *item_list);
3723   }
3724   else
3725   {
3726     func= new (thd->mem_root) Item_func_json_array(thd);
3727   }
3728 
3729   status_var_increment(current_thd->status_var.feature_json);
3730   return func;
3731 }
3732 
3733 
3734 Create_func_json_array_append Create_func_json_array_append::s_singleton;
3735 
3736 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3737 Create_func_json_array_append::create_native(THD *thd, LEX_CSTRING *name,
3738                                                  List<Item> *item_list)
3739 {
3740   Item *func= NULL;
3741   int arg_count= 0;
3742 
3743   if (item_list != NULL)
3744     arg_count= item_list->elements;
3745 
3746   if (unlikely(arg_count < 3 || (arg_count & 1) == 0 /*is even*/))
3747   {
3748     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3749   }
3750   else
3751   {
3752     func= new (thd->mem_root) Item_func_json_array_append(thd, *item_list);
3753   }
3754 
3755   status_var_increment(current_thd->status_var.feature_json);
3756   return func;
3757 }
3758 
3759 
3760 Create_func_json_array_insert Create_func_json_array_insert::s_singleton;
3761 
3762 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3763 Create_func_json_array_insert::create_native(THD *thd, LEX_CSTRING *name,
3764                                                  List<Item> *item_list)
3765 {
3766   Item *func= NULL;
3767   int arg_count= 0;
3768 
3769   if (item_list != NULL)
3770     arg_count= item_list->elements;
3771 
3772   if (unlikely(arg_count < 3 || (arg_count & 1) == 0 /*is even*/))
3773   {
3774     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3775   }
3776   else
3777   {
3778     func= new (thd->mem_root) Item_func_json_array_insert(thd, *item_list);
3779   }
3780 
3781   status_var_increment(current_thd->status_var.feature_json);
3782   return func;
3783 }
3784 
3785 
3786 Create_func_json_insert Create_func_json_insert::s_singleton;
3787 
3788 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3789 Create_func_json_insert::create_native(THD *thd, LEX_CSTRING *name,
3790                                                  List<Item> *item_list)
3791 {
3792   Item *func= NULL;
3793   int arg_count= 0;
3794 
3795   if (item_list != NULL)
3796     arg_count= item_list->elements;
3797 
3798   if (unlikely(arg_count < 3 || (arg_count & 1) == 0 /*is even*/))
3799   {
3800     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3801   }
3802   else
3803   {
3804     func= new (thd->mem_root) Item_func_json_insert(true, false,
3805                                                     thd, *item_list);
3806   }
3807 
3808   status_var_increment(current_thd->status_var.feature_json);
3809   return func;
3810 }
3811 
3812 
3813 Create_func_json_set Create_func_json_set::s_singleton;
3814 
3815 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3816 Create_func_json_set::create_native(THD *thd, LEX_CSTRING *name,
3817                                     List<Item> *item_list)
3818 {
3819   Item *func= NULL;
3820   int arg_count= 0;
3821 
3822   if (item_list != NULL)
3823     arg_count= item_list->elements;
3824 
3825   if (unlikely(arg_count < 3 || (arg_count & 1) == 0 /*is even*/))
3826   {
3827     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3828   }
3829   else
3830   {
3831     func= new (thd->mem_root) Item_func_json_insert(true, true,
3832                                                     thd, *item_list);
3833   }
3834 
3835   status_var_increment(current_thd->status_var.feature_json);
3836   return func;
3837 }
3838 
3839 
3840 Create_func_json_replace Create_func_json_replace::s_singleton;
3841 
3842 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3843 Create_func_json_replace::create_native(THD *thd, LEX_CSTRING *name,
3844                                         List<Item> *item_list)
3845 {
3846   Item *func= NULL;
3847   int arg_count= 0;
3848 
3849   if (item_list != NULL)
3850     arg_count= item_list->elements;
3851 
3852   if (unlikely(arg_count < 3 || (arg_count & 1) == 0 /*is even*/))
3853   {
3854     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3855   }
3856   else
3857   {
3858     func= new (thd->mem_root) Item_func_json_insert(false, true,
3859                                                     thd, *item_list);
3860   }
3861 
3862   status_var_increment(current_thd->status_var.feature_json);
3863   return func;
3864 }
3865 
3866 
3867 Create_func_json_remove Create_func_json_remove::s_singleton;
3868 
3869 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3870 Create_func_json_remove::create_native(THD *thd, LEX_CSTRING *name,
3871                                        List<Item> *item_list)
3872 {
3873   Item *func= NULL;
3874   int arg_count= 0;
3875 
3876   if (item_list != NULL)
3877     arg_count= item_list->elements;
3878 
3879   if (unlikely(arg_count < 2 /*json_doc, path [,path]*/))
3880   {
3881     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3882   }
3883   else
3884   {
3885     func= new (thd->mem_root) Item_func_json_remove(thd, *item_list);
3886   }
3887 
3888   status_var_increment(current_thd->status_var.feature_json);
3889   return func;
3890 }
3891 
3892 
3893 Create_func_json_object Create_func_json_object::s_singleton;
3894 
3895 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3896 Create_func_json_object::create_native(THD *thd, LEX_CSTRING *name,
3897                                        List<Item> *item_list)
3898 {
3899   Item *func;
3900   int arg_count;
3901 
3902   if (item_list != NULL)
3903   {
3904     arg_count= item_list->elements;
3905     if (unlikely((arg_count & 1) != 0 /*is odd*/))
3906     {
3907       my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3908       func= NULL;
3909     }
3910     else
3911     {
3912       func= new (thd->mem_root) Item_func_json_object(thd, *item_list);
3913     }
3914   }
3915   else
3916   {
3917     arg_count= 0;
3918     func= new (thd->mem_root) Item_func_json_object(thd);
3919   }
3920 
3921   status_var_increment(current_thd->status_var.feature_json);
3922   return func;
3923 }
3924 
3925 
3926 Create_func_json_length Create_func_json_length::s_singleton;
3927 
3928 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3929 Create_func_json_length::create_native(THD *thd, LEX_CSTRING *name,
3930                                        List<Item> *item_list)
3931 {
3932   Item *func;
3933   int arg_count;
3934 
3935   if (unlikely(item_list == NULL ||
3936                (arg_count= item_list->elements) == 0))
3937   {
3938     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3939     func= NULL;
3940   }
3941   else
3942   {
3943     func= new (thd->mem_root) Item_func_json_length(thd, *item_list);
3944   }
3945 
3946   status_var_increment(current_thd->status_var.feature_json);
3947   return func;
3948 }
3949 
3950 
3951 Create_func_json_merge Create_func_json_merge::s_singleton;
3952 
3953 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3954 Create_func_json_merge::create_native(THD *thd, LEX_CSTRING *name,
3955                                       List<Item> *item_list)
3956 {
3957   Item *func;
3958   int arg_count;
3959 
3960   if (unlikely(item_list == NULL ||
3961                (arg_count= item_list->elements) < 2)) // json, json
3962   {
3963     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3964     func= NULL;
3965   }
3966   else
3967   {
3968     func= new (thd->mem_root) Item_func_json_merge(thd, *item_list);
3969   }
3970 
3971   status_var_increment(current_thd->status_var.feature_json);
3972   return func;
3973 }
3974 
3975 
3976 Create_func_json_merge_patch Create_func_json_merge_patch::s_singleton;
3977 
3978 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)3979 Create_func_json_merge_patch::create_native(THD *thd, LEX_CSTRING *name,
3980                                            List<Item> *item_list)
3981 {
3982   Item *func;
3983   int arg_count;
3984 
3985   if (item_list == NULL ||
3986       (arg_count= item_list->elements) < 2) // json, json
3987   {
3988     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3989     func= NULL;
3990   }
3991   else
3992   {
3993     func= new (thd->mem_root) Item_func_json_merge_patch(thd, *item_list);
3994   }
3995 
3996   return func;
3997 }
3998 
3999 
4000 Create_func_json_contains Create_func_json_contains::s_singleton;
4001 
4002 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4003 Create_func_json_contains::create_native(THD *thd, LEX_CSTRING *name,
4004                                          List<Item> *item_list)
4005 {
4006   Item *func= NULL;
4007   int arg_count= 0;
4008 
4009   if (item_list != NULL)
4010     arg_count= item_list->elements;
4011 
4012   if (unlikely(arg_count == 2 || arg_count == 3/* json_doc, val, [path] */))
4013   {
4014     func= new (thd->mem_root) Item_func_json_contains(thd, *item_list);
4015   }
4016   else
4017   {
4018     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4019   }
4020 
4021   status_var_increment(current_thd->status_var.feature_json);
4022   return func;
4023 }
4024 
4025 
4026 Create_func_json_keys Create_func_json_keys::s_singleton;
4027 
4028 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4029 Create_func_json_keys::create_native(THD *thd, LEX_CSTRING *name,
4030                                      List<Item> *item_list)
4031 {
4032   Item *func= NULL;
4033   int arg_count= 0;
4034 
4035   if (item_list != NULL)
4036     arg_count= item_list->elements;
4037 
4038   if (unlikely(arg_count < 1 || arg_count > 2 /* json_doc, [path]...*/))
4039   {
4040     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4041   }
4042   else
4043   {
4044     func= new (thd->mem_root) Item_func_json_keys(thd, *item_list);
4045   }
4046 
4047   status_var_increment(current_thd->status_var.feature_json);
4048   return func;
4049 }
4050 
4051 
4052 Create_func_json_contains_path Create_func_json_contains_path::s_singleton;
4053 
4054 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4055 Create_func_json_contains_path::create_native(THD *thd, LEX_CSTRING *name,
4056                                                  List<Item> *item_list)
4057 {
4058   Item *func= NULL;
4059   int arg_count= 0;
4060 
4061   if (item_list != NULL)
4062     arg_count= item_list->elements;
4063 
4064   if (unlikely(arg_count < 3 /* json_doc, one_or_all, path, [path]...*/))
4065   {
4066     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4067   }
4068   else
4069   {
4070     func= new (thd->mem_root) Item_func_json_contains_path(thd, *item_list);
4071   }
4072 
4073   status_var_increment(current_thd->status_var.feature_json);
4074   return func;
4075 }
4076 
4077 
4078 Create_func_json_extract Create_func_json_extract::s_singleton;
4079 
4080 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4081 Create_func_json_extract::create_native(THD *thd, LEX_CSTRING *name,
4082                                                  List<Item> *item_list)
4083 {
4084   Item *func= NULL;
4085   int arg_count= 0;
4086 
4087   if (item_list != NULL)
4088     arg_count= item_list->elements;
4089 
4090   if (unlikely(arg_count < 2 /* json_doc, path, [path]...*/))
4091   {
4092     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4093   }
4094   else
4095   {
4096     func= new (thd->mem_root) Item_func_json_extract(thd, *item_list);
4097   }
4098 
4099   status_var_increment(current_thd->status_var.feature_json);
4100   return func;
4101 }
4102 
4103 
4104 Create_func_json_search Create_func_json_search::s_singleton;
4105 
4106 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4107 Create_func_json_search::create_native(THD *thd, LEX_CSTRING *name,
4108                                        List<Item> *item_list)
4109 {
4110   Item *func= NULL;
4111   int arg_count= 0;
4112 
4113   if (item_list != NULL)
4114     arg_count= item_list->elements;
4115 
4116   if (unlikely(arg_count < 3 /* json_doc, one_or_all, search_str, [escape_char[, path]...*/))
4117   {
4118     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4119   }
4120   else
4121   {
4122     func= new (thd->mem_root) Item_func_json_search(thd, *item_list);
4123   }
4124 
4125   status_var_increment(current_thd->status_var.feature_json);
4126   return func;
4127 }
4128 
4129 
4130 Create_func_last_insert_id Create_func_last_insert_id::s_singleton;
4131 
4132 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4133 Create_func_last_insert_id::create_native(THD *thd, LEX_CSTRING *name,
4134                                           List<Item> *item_list)
4135 {
4136   Item *func= NULL;
4137   int arg_count= 0;
4138 
4139   if (item_list != NULL)
4140     arg_count= item_list->elements;
4141 
4142   switch (arg_count) {
4143   case 0:
4144   {
4145     func= new (thd->mem_root) Item_func_last_insert_id(thd);
4146     thd->lex->safe_to_cache_query= 0;
4147     break;
4148   }
4149   case 1:
4150   {
4151     Item *param_1= item_list->pop();
4152     func= new (thd->mem_root) Item_func_last_insert_id(thd, param_1);
4153     thd->lex->safe_to_cache_query= 0;
4154     break;
4155   }
4156   default:
4157   {
4158     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4159     break;
4160   }
4161   }
4162 
4163   return func;
4164 }
4165 
4166 
4167 Create_func_lcase Create_func_lcase::s_singleton;
4168 
4169 Item*
create_1_arg(THD * thd,Item * arg1)4170 Create_func_lcase::create_1_arg(THD *thd, Item *arg1)
4171 {
4172   return new (thd->mem_root) Item_func_lcase(thd, arg1);
4173 }
4174 
4175 
4176 Create_func_least Create_func_least::s_singleton;
4177 
4178 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4179 Create_func_least::create_native(THD *thd, LEX_CSTRING *name,
4180                                  List<Item> *item_list)
4181 {
4182   int arg_count= 0;
4183 
4184   if (item_list != NULL)
4185     arg_count= item_list->elements;
4186 
4187   if (unlikely(arg_count < 2))
4188   {
4189     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4190     return NULL;
4191   }
4192 
4193   return new (thd->mem_root) Item_func_min(thd, *item_list);
4194 }
4195 
4196 
4197 Create_func_length Create_func_length::s_singleton;
4198 
4199 Item*
create_1_arg(THD * thd,Item * arg1)4200 Create_func_length::create_1_arg(THD *thd, Item *arg1)
4201 {
4202   if (thd->variables.sql_mode & MODE_ORACLE)
4203     return new (thd->mem_root) Item_func_char_length(thd, arg1);
4204   else
4205     return new (thd->mem_root) Item_func_octet_length(thd, arg1);
4206 }
4207 
4208 Create_func_octet_length Create_func_octet_length::s_singleton;
4209 
4210 Item*
create_1_arg(THD * thd,Item * arg1)4211 Create_func_octet_length::create_1_arg(THD *thd, Item *arg1)
4212 {
4213   return new (thd->mem_root) Item_func_octet_length(thd, arg1);
4214 }
4215 
4216 
4217 #ifndef DBUG_OFF
4218 Create_func_like_range_min Create_func_like_range_min::s_singleton;
4219 
4220 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)4221 Create_func_like_range_min::create_2_arg(THD *thd, Item *arg1, Item *arg2)
4222 {
4223   return new (thd->mem_root) Item_func_like_range_min(thd, arg1, arg2);
4224 }
4225 
4226 
4227 Create_func_like_range_max Create_func_like_range_max::s_singleton;
4228 
4229 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)4230 Create_func_like_range_max::create_2_arg(THD *thd, Item *arg1, Item *arg2)
4231 {
4232   return new (thd->mem_root) Item_func_like_range_max(thd, arg1, arg2);
4233 }
4234 #endif
4235 
4236 
4237 Create_func_ln Create_func_ln::s_singleton;
4238 
4239 Item*
create_1_arg(THD * thd,Item * arg1)4240 Create_func_ln::create_1_arg(THD *thd, Item *arg1)
4241 {
4242   return new (thd->mem_root) Item_func_ln(thd, arg1);
4243 }
4244 
4245 
4246 Create_func_load_file Create_func_load_file::s_singleton;
4247 
4248 Item*
create_1_arg(THD * thd,Item * arg1)4249 Create_func_load_file::create_1_arg(THD *thd, Item *arg1)
4250 {
4251   DBUG_ENTER("Create_func_load_file::create");
4252   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
4253   thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
4254   DBUG_RETURN(new (thd->mem_root) Item_load_file(thd, arg1));
4255 }
4256 
4257 
4258 Create_func_locate Create_func_locate::s_singleton;
4259 
4260 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4261 Create_func_locate::create_native(THD *thd, LEX_CSTRING *name,
4262                                   List<Item> *item_list)
4263 {
4264   Item *func= NULL;
4265   int arg_count= 0;
4266 
4267   if (item_list != NULL)
4268     arg_count= item_list->elements;
4269 
4270   switch (arg_count) {
4271   case 2:
4272   {
4273     Item *param_1= item_list->pop();
4274     Item *param_2= item_list->pop();
4275     /* Yes, parameters in that order : 2, 1 */
4276     func= new (thd->mem_root) Item_func_locate(thd, param_2, param_1);
4277     break;
4278   }
4279   case 3:
4280   {
4281     Item *param_1= item_list->pop();
4282     Item *param_2= item_list->pop();
4283     Item *param_3= item_list->pop();
4284     /* Yes, parameters in that order : 2, 1, 3 */
4285     func= new (thd->mem_root) Item_func_locate(thd, param_2, param_1, param_3);
4286     break;
4287   }
4288   default:
4289   {
4290     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4291     break;
4292   }
4293   }
4294 
4295   return func;
4296 }
4297 
4298 
4299 Create_func_log Create_func_log::s_singleton;
4300 
4301 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4302 Create_func_log::create_native(THD *thd, LEX_CSTRING *name,
4303                                List<Item> *item_list)
4304 {
4305   Item *func= NULL;
4306   int arg_count= 0;
4307 
4308   if (item_list != NULL)
4309     arg_count= item_list->elements;
4310 
4311   switch (arg_count) {
4312   case 1:
4313   {
4314     Item *param_1= item_list->pop();
4315     func= new (thd->mem_root) Item_func_log(thd, param_1);
4316     break;
4317   }
4318   case 2:
4319   {
4320     Item *param_1= item_list->pop();
4321     Item *param_2= item_list->pop();
4322     func= new (thd->mem_root) Item_func_log(thd, param_1, param_2);
4323     break;
4324   }
4325   default:
4326   {
4327     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4328     break;
4329   }
4330   }
4331 
4332   return func;
4333 }
4334 
4335 
4336 Create_func_log10 Create_func_log10::s_singleton;
4337 
4338 Item*
create_1_arg(THD * thd,Item * arg1)4339 Create_func_log10::create_1_arg(THD *thd, Item *arg1)
4340 {
4341   return new (thd->mem_root) Item_func_log10(thd, arg1);
4342 }
4343 
4344 
4345 Create_func_log2 Create_func_log2::s_singleton;
4346 
4347 Item*
create_1_arg(THD * thd,Item * arg1)4348 Create_func_log2::create_1_arg(THD *thd, Item *arg1)
4349 {
4350   return new (thd->mem_root) Item_func_log2(thd, arg1);
4351 }
4352 
4353 
4354 Create_func_lpad Create_func_lpad::s_singleton;
4355 
4356 Create_func_lpad_oracle Create_func_lpad_oracle::s_singleton;
4357 
4358 Item*
create_native_std(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4359 Create_func_lpad::create_native_std(THD *thd, LEX_CSTRING *name,
4360                                     List<Item> *item_list)
4361 {
4362   Item *func= NULL;
4363   int arg_count= item_list ? item_list->elements : 0;
4364 
4365   switch (arg_count) {
4366   case 2:
4367   {
4368     Item *param_1= item_list->pop();
4369     Item *param_2= item_list->pop();
4370     func= new (thd->mem_root) Item_func_lpad(thd, param_1, param_2);
4371     break;
4372   }
4373   case 3:
4374   {
4375     Item *param_1= item_list->pop();
4376     Item *param_2= item_list->pop();
4377     Item *param_3= item_list->pop();
4378     func= new (thd->mem_root) Item_func_lpad(thd, param_1, param_2, param_3);
4379     break;
4380   }
4381   default:
4382     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4383     break;
4384   }
4385 
4386   return func;
4387 }
4388 
4389 
4390 Item*
create_native_oracle(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4391 Create_func_lpad::create_native_oracle(THD *thd, LEX_CSTRING *name,
4392                                        List<Item> *item_list)
4393 {
4394   int arg_count= item_list ? item_list->elements : 0;
4395   switch (arg_count) {
4396   case 2:
4397   {
4398     Item *param_1= item_list->pop();
4399     Item *param_2= item_list->pop();
4400     return new (thd->mem_root) Item_func_lpad_oracle(thd, param_1, param_2);
4401   }
4402   case 3:
4403   {
4404     Item *param_1= item_list->pop();
4405     Item *param_2= item_list->pop();
4406     Item *param_3= item_list->pop();
4407     return new (thd->mem_root) Item_func_lpad_oracle(thd, param_1,
4408                                                      param_2, param_3);
4409   }
4410   default:
4411     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4412     break;
4413   }
4414   return NULL;
4415 }
4416 
4417 
4418 Create_func_ltrim Create_func_ltrim::s_singleton;
4419 
4420 Item*
create_1_arg(THD * thd,Item * arg1)4421 Create_func_ltrim::create_1_arg(THD *thd, Item *arg1)
4422 {
4423   return Lex_trim(TRIM_LEADING, arg1).make_item_func_trim(thd);
4424 }
4425 
4426 
4427 Create_func_ltrim_oracle Create_func_ltrim_oracle::s_singleton;
4428 
4429 Item*
create_1_arg(THD * thd,Item * arg1)4430 Create_func_ltrim_oracle::create_1_arg(THD *thd, Item *arg1)
4431 {
4432   return new (thd->mem_root) Item_func_ltrim_oracle(thd, arg1);
4433 }
4434 
4435 
4436 Create_func_makedate Create_func_makedate::s_singleton;
4437 
4438 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)4439 Create_func_makedate::create_2_arg(THD *thd, Item *arg1, Item *arg2)
4440 {
4441   return new (thd->mem_root) Item_func_makedate(thd, arg1, arg2);
4442 }
4443 
4444 
4445 Create_func_maketime Create_func_maketime::s_singleton;
4446 
4447 Item*
create_3_arg(THD * thd,Item * arg1,Item * arg2,Item * arg3)4448 Create_func_maketime::create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3)
4449 {
4450   return new (thd->mem_root) Item_func_maketime(thd, arg1, arg2, arg3);
4451 }
4452 
4453 
4454 Create_func_make_set Create_func_make_set::s_singleton;
4455 
4456 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4457 Create_func_make_set::create_native(THD *thd, LEX_CSTRING *name,
4458                                     List<Item> *item_list)
4459 {
4460   int arg_count= 0;
4461 
4462   if (item_list != NULL)
4463     arg_count= item_list->elements;
4464 
4465   if (unlikely(arg_count < 2))
4466   {
4467     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4468     return NULL;
4469   }
4470 
4471   return new (thd->mem_root) Item_func_make_set(thd, *item_list);
4472 }
4473 
4474 
4475 Create_func_master_pos_wait Create_func_master_pos_wait::s_singleton;
4476 
4477 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4478 Create_func_master_pos_wait::create_native(THD *thd, LEX_CSTRING *name,
4479                                            List<Item> *item_list)
4480 
4481 {
4482   Item *func= NULL;
4483   int arg_count= 0;
4484 
4485   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
4486 
4487   if (item_list != NULL)
4488     arg_count= item_list->elements;
4489 
4490   if (unlikely(arg_count < 2 || arg_count > 4))
4491   {
4492     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4493     return func;
4494   }
4495 
4496   thd->lex->safe_to_cache_query= 0;
4497 
4498   Item *param_1= item_list->pop();
4499   Item *param_2= item_list->pop();
4500   switch (arg_count) {
4501   case 2:
4502   {
4503     func= new (thd->mem_root) Item_master_pos_wait(thd, param_1, param_2);
4504     break;
4505   }
4506   case 3:
4507   {
4508     Item *param_3= item_list->pop();
4509     func= new (thd->mem_root) Item_master_pos_wait(thd, param_1, param_2, param_3);
4510     break;
4511   }
4512   case 4:
4513   {
4514     Item *param_3= item_list->pop();
4515     Item *param_4= item_list->pop();
4516     func= new (thd->mem_root) Item_master_pos_wait(thd, param_1, param_2, param_3,
4517                                                    param_4);
4518     break;
4519   }
4520   }
4521 
4522   return func;
4523 }
4524 
4525 
4526 Create_func_master_gtid_wait Create_func_master_gtid_wait::s_singleton;
4527 
4528 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4529 Create_func_master_gtid_wait::create_native(THD *thd, LEX_CSTRING *name,
4530                                             List<Item> *item_list)
4531 {
4532   Item *func= NULL;
4533   int arg_count= 0;
4534 
4535   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
4536 
4537   if (item_list != NULL)
4538     arg_count= item_list->elements;
4539 
4540   if (unlikely(arg_count < 1 || arg_count > 2))
4541   {
4542     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4543     return func;
4544   }
4545 
4546   thd->lex->safe_to_cache_query= 0;
4547 
4548   Item *param_1= item_list->pop();
4549   switch (arg_count) {
4550   case 1:
4551   {
4552     func= new (thd->mem_root) Item_master_gtid_wait(thd, param_1);
4553     break;
4554   }
4555   case 2:
4556   {
4557     Item *param_2= item_list->pop();
4558     func= new (thd->mem_root) Item_master_gtid_wait(thd, param_1, param_2);
4559     break;
4560   }
4561   }
4562 
4563   return func;
4564 }
4565 
4566 
4567 Create_func_md5 Create_func_md5::s_singleton;
4568 
4569 Item*
create_1_arg(THD * thd,Item * arg1)4570 Create_func_md5::create_1_arg(THD *thd, Item *arg1)
4571 {
4572   return new (thd->mem_root) Item_func_md5(thd, arg1);
4573 }
4574 
4575 
4576 Create_func_monthname Create_func_monthname::s_singleton;
4577 
4578 Item*
create_1_arg(THD * thd,Item * arg1)4579 Create_func_monthname::create_1_arg(THD *thd, Item *arg1)
4580 {
4581   return new (thd->mem_root) Item_func_monthname(thd, arg1);
4582 }
4583 
4584 
4585 Create_func_name_const Create_func_name_const::s_singleton;
4586 
4587 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)4588 Create_func_name_const::create_2_arg(THD *thd, Item *arg1, Item *arg2)
4589 {
4590   if (!arg1->basic_const_item())
4591     goto err;
4592 
4593   if (arg2->basic_const_item())
4594     return new (thd->mem_root) Item_name_const(thd, arg1, arg2);
4595 
4596   if (arg2->type() == Item::FUNC_ITEM)
4597   {
4598     Item_func *value_func= (Item_func *) arg2;
4599     if (value_func->functype() != Item_func::COLLATE_FUNC &&
4600         value_func->functype() != Item_func::NEG_FUNC)
4601       goto err;
4602 
4603     if (!value_func->key_item()->basic_const_item())
4604       goto err;
4605     return new (thd->mem_root) Item_name_const(thd, arg1, arg2);
4606   }
4607 err:
4608   my_error(ER_WRONG_ARGUMENTS, MYF(0), "NAME_CONST");
4609   return NULL;
4610 }
4611 
4612 
4613 Create_func_nullif Create_func_nullif::s_singleton;
4614 
4615 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)4616 Create_func_nullif::create_2_arg(THD *thd, Item *arg1, Item *arg2)
4617 {
4618   return new (thd->mem_root) Item_func_nullif(thd, arg1, arg2);
4619 }
4620 
4621 
4622 Create_func_oct Create_func_oct::s_singleton;
4623 
4624 Item*
create_1_arg(THD * thd,Item * arg1)4625 Create_func_oct::create_1_arg(THD *thd, Item *arg1)
4626 {
4627   Item *i10= new (thd->mem_root) Item_int(thd, (int32) 10,2);
4628   Item *i8= new (thd->mem_root) Item_int(thd, (int32) 8,1);
4629   return new (thd->mem_root) Item_func_conv(thd, arg1, i10, i8);
4630 }
4631 
4632 
4633 Create_func_ord Create_func_ord::s_singleton;
4634 
4635 Item*
create_1_arg(THD * thd,Item * arg1)4636 Create_func_ord::create_1_arg(THD *thd, Item *arg1)
4637 {
4638   return new (thd->mem_root) Item_func_ord(thd, arg1);
4639 }
4640 
4641 
4642 Create_func_period_add Create_func_period_add::s_singleton;
4643 
4644 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)4645 Create_func_period_add::create_2_arg(THD *thd, Item *arg1, Item *arg2)
4646 {
4647   return new (thd->mem_root) Item_func_period_add(thd, arg1, arg2);
4648 }
4649 
4650 
4651 Create_func_period_diff Create_func_period_diff::s_singleton;
4652 
4653 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)4654 Create_func_period_diff::create_2_arg(THD *thd, Item *arg1, Item *arg2)
4655 {
4656   return new (thd->mem_root) Item_func_period_diff(thd, arg1, arg2);
4657 }
4658 
4659 
4660 Create_func_pi Create_func_pi::s_singleton;
4661 
4662 Item*
create_builder(THD * thd)4663 Create_func_pi::create_builder(THD *thd)
4664 {
4665   return new (thd->mem_root) Item_static_float_func(thd, "pi()", M_PI, 6, 8);
4666 }
4667 
4668 
4669 Create_func_pow Create_func_pow::s_singleton;
4670 
4671 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)4672 Create_func_pow::create_2_arg(THD *thd, Item *arg1, Item *arg2)
4673 {
4674   return new (thd->mem_root) Item_func_pow(thd, arg1, arg2);
4675 }
4676 
4677 
4678 Create_func_quote Create_func_quote::s_singleton;
4679 
4680 Item*
create_1_arg(THD * thd,Item * arg1)4681 Create_func_quote::create_1_arg(THD *thd, Item *arg1)
4682 {
4683   return new (thd->mem_root) Item_func_quote(thd, arg1);
4684 }
4685 
4686 
4687 Create_func_regexp_instr Create_func_regexp_instr::s_singleton;
4688 
4689 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)4690 Create_func_regexp_instr::create_2_arg(THD *thd, Item *arg1, Item *arg2)
4691 {
4692   return new (thd->mem_root) Item_func_regexp_instr(thd, arg1, arg2);
4693 }
4694 
4695 
4696 Create_func_regexp_replace Create_func_regexp_replace::s_singleton;
4697 
4698 Item*
create_3_arg(THD * thd,Item * arg1,Item * arg2,Item * arg3)4699 Create_func_regexp_replace::create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3)
4700 {
4701   return new (thd->mem_root) Item_func_regexp_replace(thd, arg1, arg2, arg3);
4702 }
4703 
4704 
4705 Create_func_regexp_substr Create_func_regexp_substr::s_singleton;
4706 
4707 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)4708 Create_func_regexp_substr::create_2_arg(THD *thd, Item *arg1, Item *arg2)
4709 {
4710   return new (thd->mem_root) Item_func_regexp_substr(thd, arg1, arg2);
4711 }
4712 
4713 
4714 Create_func_radians Create_func_radians::s_singleton;
4715 
4716 Item*
create_1_arg(THD * thd,Item * arg1)4717 Create_func_radians::create_1_arg(THD *thd, Item *arg1)
4718 {
4719   return new (thd->mem_root) Item_func_units(thd, (char*) "radians", arg1,
4720                                              M_PI/180, 0.0);
4721 }
4722 
4723 
4724 Create_func_rand Create_func_rand::s_singleton;
4725 
4726 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4727 Create_func_rand::create_native(THD *thd, LEX_CSTRING *name,
4728                                 List<Item> *item_list)
4729 {
4730   Item *func= NULL;
4731   int arg_count= 0;
4732 
4733   if (item_list != NULL)
4734     arg_count= item_list->elements;
4735 
4736   /*
4737     When RAND() is binlogged, the seed is binlogged too.  So the
4738     sequence of random numbers is the same on a replication slave as
4739     on the master.  However, if several RAND() values are inserted
4740     into a table, the order in which the rows are modified may differ
4741     between master and slave, because the order is undefined.  Hence,
4742     the statement is unsafe to log in statement format.
4743 
4744     For normal INSERT's this is howevever safe
4745   */
4746   if (thd->lex->sql_command != SQLCOM_INSERT)
4747     thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
4748 
4749   switch (arg_count) {
4750   case 0:
4751   {
4752     func= new (thd->mem_root) Item_func_rand(thd);
4753     thd->lex->uncacheable(UNCACHEABLE_RAND);
4754     break;
4755   }
4756   case 1:
4757   {
4758     Item *param_1= item_list->pop();
4759     func= new (thd->mem_root) Item_func_rand(thd, param_1);
4760     thd->lex->uncacheable(UNCACHEABLE_RAND);
4761     break;
4762   }
4763   default:
4764   {
4765     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4766     break;
4767   }
4768   }
4769 
4770   return func;
4771 }
4772 
4773 
4774 Create_func_release_all_locks Create_func_release_all_locks::s_singleton;
4775 
4776 Item*
create_builder(THD * thd)4777 Create_func_release_all_locks::create_builder(THD *thd)
4778 {
4779   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
4780   thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
4781   return new (thd->mem_root) Item_func_release_all_locks(thd);
4782 }
4783 
4784 
4785 Create_func_release_lock Create_func_release_lock::s_singleton;
4786 
4787 Item*
create_1_arg(THD * thd,Item * arg1)4788 Create_func_release_lock::create_1_arg(THD *thd, Item *arg1)
4789 {
4790   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
4791   thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
4792   return new (thd->mem_root) Item_func_release_lock(thd, arg1);
4793 }
4794 
4795 
4796 Create_func_replace_oracle Create_func_replace_oracle::s_singleton;
4797 
4798 Item*
create_3_arg(THD * thd,Item * arg1,Item * arg2,Item * arg3)4799 Create_func_replace_oracle::create_3_arg(THD *thd, Item *arg1, Item *arg2,
4800                                         Item *arg3)
4801 {
4802   return new (thd->mem_root) Item_func_replace_oracle(thd, arg1, arg2, arg3);
4803 }
4804 
4805 
4806 Create_func_reverse Create_func_reverse::s_singleton;
4807 
4808 Item*
create_1_arg(THD * thd,Item * arg1)4809 Create_func_reverse::create_1_arg(THD *thd, Item *arg1)
4810 {
4811   return new (thd->mem_root) Item_func_reverse(thd, arg1);
4812 }
4813 
4814 
4815 Create_func_round Create_func_round::s_singleton;
4816 
4817 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4818 Create_func_round::create_native(THD *thd, LEX_CSTRING *name,
4819                                  List<Item> *item_list)
4820 {
4821   Item *func= NULL;
4822   int arg_count= 0;
4823 
4824   if (item_list != NULL)
4825     arg_count= item_list->elements;
4826 
4827   switch (arg_count) {
4828   case 1:
4829   {
4830     Item *param_1= item_list->pop();
4831     Item *i0= new (thd->mem_root) Item_int(thd, (char*)"0", 0, 1);
4832     func= new (thd->mem_root) Item_func_round(thd, param_1, i0, 0);
4833     break;
4834   }
4835   case 2:
4836   {
4837     Item *param_1= item_list->pop();
4838     Item *param_2= item_list->pop();
4839     func= new (thd->mem_root) Item_func_round(thd, param_1, param_2, 0);
4840     break;
4841   }
4842   default:
4843   {
4844     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4845     break;
4846   }
4847   }
4848 
4849   return func;
4850 }
4851 
4852 
4853 Create_func_rpad Create_func_rpad::s_singleton;
4854 
4855 Create_func_rpad_oracle Create_func_rpad_oracle::s_singleton;
4856 
4857 Item*
create_native_std(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4858 Create_func_rpad::create_native_std(THD *thd, LEX_CSTRING *name,
4859                                     List<Item> *item_list)
4860 {
4861   Item *func= NULL;
4862   int arg_count= item_list ? item_list->elements : 0;
4863 
4864   switch (arg_count) {
4865   case 2:
4866   {
4867     Item *param_1= item_list->pop();
4868     Item *param_2= item_list->pop();
4869     func= new (thd->mem_root) Item_func_rpad(thd, param_1, param_2);
4870     break;
4871   }
4872   case 3:
4873   {
4874     Item *param_1= item_list->pop();
4875     Item *param_2= item_list->pop();
4876     Item *param_3= item_list->pop();
4877     func= new (thd->mem_root) Item_func_rpad(thd, param_1, param_2, param_3);
4878     break;
4879   }
4880   default:
4881     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4882     break;
4883   }
4884 
4885   return func;
4886 }
4887 
4888 
4889 Item*
create_native_oracle(THD * thd,LEX_CSTRING * name,List<Item> * item_list)4890 Create_func_rpad::create_native_oracle(THD *thd, LEX_CSTRING *name,
4891                                        List<Item> *item_list)
4892 {
4893   int arg_count= item_list ? item_list->elements : 0;
4894   switch (arg_count) {
4895   case 2:
4896   {
4897     Item *param_1= item_list->pop();
4898     Item *param_2= item_list->pop();
4899     return new (thd->mem_root) Item_func_rpad_oracle(thd, param_1, param_2);
4900   }
4901   case 3:
4902   {
4903     Item *param_1= item_list->pop();
4904     Item *param_2= item_list->pop();
4905     Item *param_3= item_list->pop();
4906     return new (thd->mem_root) Item_func_rpad_oracle(thd, param_1,
4907                                                      param_2, param_3);
4908   }
4909   default:
4910     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
4911     break;
4912   }
4913   return NULL;
4914 }
4915 
4916 
4917 Create_func_rtrim Create_func_rtrim::s_singleton;
4918 
4919 Item*
create_1_arg(THD * thd,Item * arg1)4920 Create_func_rtrim::create_1_arg(THD *thd, Item *arg1)
4921 {
4922   return Lex_trim(TRIM_TRAILING, arg1).make_item_func_trim(thd);
4923 }
4924 
4925 
4926 Create_func_rtrim_oracle Create_func_rtrim_oracle::s_singleton;
4927 
4928 Item*
create_1_arg(THD * thd,Item * arg1)4929 Create_func_rtrim_oracle::create_1_arg(THD *thd, Item *arg1)
4930 {
4931   return new (thd->mem_root) Item_func_rtrim_oracle(thd, arg1);
4932 }
4933 
4934 
4935 Create_func_sec_to_time Create_func_sec_to_time::s_singleton;
4936 
4937 Item*
create_1_arg(THD * thd,Item * arg1)4938 Create_func_sec_to_time::create_1_arg(THD *thd, Item *arg1)
4939 {
4940   return new (thd->mem_root) Item_func_sec_to_time(thd, arg1);
4941 }
4942 
4943 
4944 Create_func_sha Create_func_sha::s_singleton;
4945 
4946 Item*
create_1_arg(THD * thd,Item * arg1)4947 Create_func_sha::create_1_arg(THD *thd, Item *arg1)
4948 {
4949   return new (thd->mem_root) Item_func_sha(thd, arg1);
4950 }
4951 
4952 
4953 Create_func_sha2 Create_func_sha2::s_singleton;
4954 
4955 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)4956 Create_func_sha2::create_2_arg(THD *thd, Item *arg1, Item *arg2)
4957 {
4958   return new (thd->mem_root) Item_func_sha2(thd, arg1, arg2);
4959 }
4960 
4961 
4962 Create_func_sign Create_func_sign::s_singleton;
4963 
4964 Item*
create_1_arg(THD * thd,Item * arg1)4965 Create_func_sign::create_1_arg(THD *thd, Item *arg1)
4966 {
4967   return new (thd->mem_root) Item_func_sign(thd, arg1);
4968 }
4969 
4970 
4971 Create_func_sin Create_func_sin::s_singleton;
4972 
4973 Item*
create_1_arg(THD * thd,Item * arg1)4974 Create_func_sin::create_1_arg(THD *thd, Item *arg1)
4975 {
4976   return new (thd->mem_root) Item_func_sin(thd, arg1);
4977 }
4978 
4979 
4980 Create_func_sleep Create_func_sleep::s_singleton;
4981 
4982 Item*
create_1_arg(THD * thd,Item * arg1)4983 Create_func_sleep::create_1_arg(THD *thd, Item *arg1)
4984 {
4985   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
4986   thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
4987   return new (thd->mem_root) Item_func_sleep(thd, arg1);
4988 }
4989 
4990 
4991 Create_func_soundex Create_func_soundex::s_singleton;
4992 
4993 Item*
create_1_arg(THD * thd,Item * arg1)4994 Create_func_soundex::create_1_arg(THD *thd, Item *arg1)
4995 {
4996   return new (thd->mem_root) Item_func_soundex(thd, arg1);
4997 }
4998 
4999 
5000 Create_func_space Create_func_space::s_singleton;
5001 
5002 Item*
create_1_arg(THD * thd,Item * arg1)5003 Create_func_space::create_1_arg(THD *thd, Item *arg1)
5004 {
5005   return new (thd->mem_root) Item_func_space(thd, arg1);
5006 }
5007 
5008 
5009 Create_func_sqrt Create_func_sqrt::s_singleton;
5010 
5011 Item*
create_1_arg(THD * thd,Item * arg1)5012 Create_func_sqrt::create_1_arg(THD *thd, Item *arg1)
5013 {
5014   return new (thd->mem_root) Item_func_sqrt(thd, arg1);
5015 }
5016 
5017 
5018 Create_func_str_to_date Create_func_str_to_date::s_singleton;
5019 
5020 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)5021 Create_func_str_to_date::create_2_arg(THD *thd, Item *arg1, Item *arg2)
5022 {
5023   return new (thd->mem_root) Item_func_str_to_date(thd, arg1, arg2);
5024 }
5025 
5026 
5027 Create_func_strcmp Create_func_strcmp::s_singleton;
5028 
5029 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)5030 Create_func_strcmp::create_2_arg(THD *thd, Item *arg1, Item *arg2)
5031 {
5032   return new (thd->mem_root) Item_func_strcmp(thd, arg1, arg2);
5033 }
5034 
5035 
5036 Create_func_substr_index Create_func_substr_index::s_singleton;
5037 
5038 Item*
create_3_arg(THD * thd,Item * arg1,Item * arg2,Item * arg3)5039 Create_func_substr_index::create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3)
5040 {
5041   return new (thd->mem_root) Item_func_substr_index(thd, arg1, arg2, arg3);
5042 }
5043 
5044 
5045 Create_func_substr_oracle Create_func_substr_oracle::s_singleton;
5046 
5047 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)5048 Create_func_substr_oracle::create_native(THD *thd, LEX_CSTRING *name,
5049                                 List<Item> *item_list)
5050 {
5051   Item *func= NULL;
5052   int arg_count= item_list ? item_list->elements : 0;
5053 
5054   switch (arg_count) {
5055   case 2:
5056   {
5057     Item *param_1= item_list->pop();
5058     Item *param_2= item_list->pop();
5059     func= new (thd->mem_root) Item_func_substr_oracle(thd, param_1, param_2);
5060     break;
5061   }
5062   case 3:
5063   {
5064     Item *param_1= item_list->pop();
5065     Item *param_2= item_list->pop();
5066     Item *param_3= item_list->pop();
5067     func= new (thd->mem_root) Item_func_substr_oracle(thd, param_1, param_2, param_3);
5068     break;
5069   }
5070   default:
5071     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
5072     break;
5073   }
5074 
5075   return func;
5076 }
5077 
5078 
5079 Create_func_subtime Create_func_subtime::s_singleton;
5080 
5081 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)5082 Create_func_subtime::create_2_arg(THD *thd, Item *arg1, Item *arg2)
5083 {
5084   return new (thd->mem_root) Item_func_add_time(thd, arg1, arg2, true);
5085 }
5086 
5087 
5088 Create_func_tan Create_func_tan::s_singleton;
5089 
5090 Item*
create_1_arg(THD * thd,Item * arg1)5091 Create_func_tan::create_1_arg(THD *thd, Item *arg1)
5092 {
5093   return new (thd->mem_root) Item_func_tan(thd, arg1);
5094 }
5095 
5096 
5097 Create_func_time_format Create_func_time_format::s_singleton;
5098 
5099 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)5100 Create_func_time_format::create_2_arg(THD *thd, Item *arg1, Item *arg2)
5101 {
5102   return new (thd->mem_root) Item_func_time_format(thd, arg1, arg2);
5103 }
5104 
5105 
5106 Create_func_time_to_sec Create_func_time_to_sec::s_singleton;
5107 
5108 Item*
create_1_arg(THD * thd,Item * arg1)5109 Create_func_time_to_sec::create_1_arg(THD *thd, Item *arg1)
5110 {
5111   return new (thd->mem_root) Item_func_time_to_sec(thd, arg1);
5112 }
5113 
5114 
5115 Create_func_timediff Create_func_timediff::s_singleton;
5116 
5117 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)5118 Create_func_timediff::create_2_arg(THD *thd, Item *arg1, Item *arg2)
5119 {
5120   return new (thd->mem_root) Item_func_timediff(thd, arg1, arg2);
5121 }
5122 
5123 
5124 Create_func_to_base64 Create_func_to_base64::s_singleton;
5125 
5126 Item*
create_1_arg(THD * thd,Item * arg1)5127 Create_func_to_base64::create_1_arg(THD *thd, Item *arg1)
5128 {
5129   return new (thd->mem_root) Item_func_to_base64(thd, arg1);
5130 }
5131 
5132 
5133 Create_func_to_days Create_func_to_days::s_singleton;
5134 
5135 Item*
create_1_arg(THD * thd,Item * arg1)5136 Create_func_to_days::create_1_arg(THD *thd, Item *arg1)
5137 {
5138   return new (thd->mem_root) Item_func_to_days(thd, arg1);
5139 }
5140 
5141 
5142 Create_func_to_seconds Create_func_to_seconds::s_singleton;
5143 
5144 Item*
create_1_arg(THD * thd,Item * arg1)5145 Create_func_to_seconds::create_1_arg(THD *thd, Item *arg1)
5146 {
5147   return new (thd->mem_root) Item_func_to_seconds(thd, arg1);
5148 }
5149 
5150 
5151 Create_func_ucase Create_func_ucase::s_singleton;
5152 
5153 Item*
create_1_arg(THD * thd,Item * arg1)5154 Create_func_ucase::create_1_arg(THD *thd, Item *arg1)
5155 {
5156   return new (thd->mem_root) Item_func_ucase(thd, arg1);
5157 }
5158 
5159 
5160 Create_func_uncompress Create_func_uncompress::s_singleton;
5161 
5162 Item*
create_1_arg(THD * thd,Item * arg1)5163 Create_func_uncompress::create_1_arg(THD *thd, Item *arg1)
5164 {
5165   return new (thd->mem_root) Item_func_uncompress(thd, arg1);
5166 }
5167 
5168 
5169 Create_func_uncompressed_length Create_func_uncompressed_length::s_singleton;
5170 
5171 Item*
create_1_arg(THD * thd,Item * arg1)5172 Create_func_uncompressed_length::create_1_arg(THD *thd, Item *arg1)
5173 {
5174   return new (thd->mem_root) Item_func_uncompressed_length(thd, arg1);
5175 }
5176 
5177 
5178 Create_func_unhex Create_func_unhex::s_singleton;
5179 
5180 Item*
create_1_arg(THD * thd,Item * arg1)5181 Create_func_unhex::create_1_arg(THD *thd, Item *arg1)
5182 {
5183   return new (thd->mem_root) Item_func_unhex(thd, arg1);
5184 }
5185 
5186 
5187 Create_func_unix_timestamp Create_func_unix_timestamp::s_singleton;
5188 
5189 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)5190 Create_func_unix_timestamp::create_native(THD *thd, LEX_CSTRING *name,
5191                                           List<Item> *item_list)
5192 {
5193   Item *func= NULL;
5194   int arg_count= 0;
5195 
5196   if (item_list != NULL)
5197     arg_count= item_list->elements;
5198 
5199   switch (arg_count) {
5200   case 0:
5201   {
5202     func= new (thd->mem_root) Item_func_unix_timestamp(thd);
5203     thd->lex->safe_to_cache_query= 0;
5204     break;
5205   }
5206   case 1:
5207   {
5208     Item *param_1= item_list->pop();
5209     func= new (thd->mem_root) Item_func_unix_timestamp(thd, param_1);
5210     break;
5211   }
5212   default:
5213   {
5214     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
5215     break;
5216   }
5217   }
5218 
5219   return func;
5220 }
5221 
5222 
5223 Create_func_uuid Create_func_uuid::s_singleton;
5224 
5225 Item*
create_builder(THD * thd)5226 Create_func_uuid::create_builder(THD *thd)
5227 {
5228   DBUG_ENTER("Create_func_uuid::create");
5229   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
5230   thd->lex->safe_to_cache_query= 0;
5231   DBUG_RETURN(new (thd->mem_root) Item_func_uuid(thd));
5232 }
5233 
5234 
5235 Create_func_uuid_short Create_func_uuid_short::s_singleton;
5236 
5237 Item*
create_builder(THD * thd)5238 Create_func_uuid_short::create_builder(THD *thd)
5239 {
5240   DBUG_ENTER("Create_func_uuid_short::create");
5241   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
5242   thd->lex->safe_to_cache_query= 0;
5243   DBUG_RETURN(new (thd->mem_root) Item_func_uuid_short(thd));
5244 }
5245 
5246 
5247 Create_func_version Create_func_version::s_singleton;
5248 
5249 Item*
create_builder(THD * thd)5250 Create_func_version::create_builder(THD *thd)
5251 {
5252   thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
5253   static Lex_cstring name(STRING_WITH_LEN("version()"));
5254   return new (thd->mem_root) Item_static_string_func(thd, name,
5255                                                      Lex_cstring_strlen(server_version),
5256                                                      system_charset_info,
5257                                                      DERIVATION_SYSCONST);
5258 }
5259 
5260 
5261 Create_func_weekday Create_func_weekday::s_singleton;
5262 
5263 Item*
create_1_arg(THD * thd,Item * arg1)5264 Create_func_weekday::create_1_arg(THD *thd, Item *arg1)
5265 {
5266   return new (thd->mem_root) Item_func_weekday(thd, arg1, 0);
5267 }
5268 
5269 
5270 Create_func_weekofyear Create_func_weekofyear::s_singleton;
5271 
5272 Item*
create_1_arg(THD * thd,Item * arg1)5273 Create_func_weekofyear::create_1_arg(THD *thd, Item *arg1)
5274 {
5275   Item *i1= new (thd->mem_root) Item_int(thd, (char*) "3", 3, 1);
5276   return new (thd->mem_root) Item_func_week(thd, arg1, i1);
5277 }
5278 
5279 
5280 #ifdef WITH_WSREP
5281 Create_func_wsrep_last_written_gtid
5282 Create_func_wsrep_last_written_gtid::s_singleton;
5283 
5284 Item*
create_builder(THD * thd)5285 Create_func_wsrep_last_written_gtid::create_builder(THD *thd)
5286 {
5287   thd->lex->safe_to_cache_query= 0;
5288   return new (thd->mem_root) Item_func_wsrep_last_written_gtid(thd);
5289 }
5290 
5291 
5292 Create_func_wsrep_last_seen_gtid
5293 Create_func_wsrep_last_seen_gtid::s_singleton;
5294 
5295 Item*
create_builder(THD * thd)5296 Create_func_wsrep_last_seen_gtid::create_builder(THD *thd)
5297 {
5298   thd->lex->safe_to_cache_query= 0;
5299   return new (thd->mem_root) Item_func_wsrep_last_seen_gtid(thd);
5300 }
5301 
5302 
5303 Create_func_wsrep_sync_wait_upto
5304 Create_func_wsrep_sync_wait_upto::s_singleton;
5305 
5306 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)5307 Create_func_wsrep_sync_wait_upto::create_native(THD *thd,
5308                                          LEX_CSTRING *name,
5309                                          List<Item> *item_list)
5310 {
5311   Item *func= NULL;
5312   int arg_count= 0;
5313   Item *param_1, *param_2;
5314 
5315   if (item_list != NULL)
5316     arg_count= item_list->elements;
5317 
5318   switch (arg_count)
5319   {
5320   case 1:
5321     param_1= item_list->pop();
5322     func= new (thd->mem_root) Item_func_wsrep_sync_wait_upto(thd, param_1);
5323     break;
5324   case 2:
5325     param_1= item_list->pop();
5326     param_2= item_list->pop();
5327     func= new (thd->mem_root) Item_func_wsrep_sync_wait_upto(thd, param_1, param_2);
5328     break;
5329   default:
5330     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
5331     break;
5332   }
5333   thd->lex->safe_to_cache_query= 0;
5334   return func;
5335 }
5336 #endif /* WITH_WSREP */
5337 
5338 Create_func_xml_extractvalue Create_func_xml_extractvalue::s_singleton;
5339 
5340 Item*
create_2_arg(THD * thd,Item * arg1,Item * arg2)5341 Create_func_xml_extractvalue::create_2_arg(THD *thd, Item *arg1, Item *arg2)
5342 {
5343   return new (thd->mem_root) Item_func_xml_extractvalue(thd, arg1, arg2);
5344 }
5345 
5346 
5347 Create_func_xml_update Create_func_xml_update::s_singleton;
5348 
5349 Item*
create_3_arg(THD * thd,Item * arg1,Item * arg2,Item * arg3)5350 Create_func_xml_update::create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *arg3)
5351 {
5352   return new (thd->mem_root) Item_func_xml_update(thd, arg1, arg2, arg3);
5353 }
5354 
5355 
5356 Create_func_year_week Create_func_year_week::s_singleton;
5357 
5358 Item*
create_native(THD * thd,LEX_CSTRING * name,List<Item> * item_list)5359 Create_func_year_week::create_native(THD *thd, LEX_CSTRING *name,
5360                                      List<Item> *item_list)
5361 {
5362   Item *func= NULL;
5363   int arg_count= 0;
5364 
5365   if (item_list != NULL)
5366     arg_count= item_list->elements;
5367 
5368   switch (arg_count) {
5369   case 1:
5370   {
5371     Item *param_1= item_list->pop();
5372     Item *i0= new (thd->mem_root) Item_int(thd, (char*) "0", 0, 1);
5373     func= new (thd->mem_root) Item_func_yearweek(thd, param_1, i0);
5374     break;
5375   }
5376   case 2:
5377   {
5378     Item *param_1= item_list->pop();
5379     Item *param_2= item_list->pop();
5380     func= new (thd->mem_root) Item_func_yearweek(thd, param_1, param_2);
5381     break;
5382   }
5383   default:
5384   {
5385     my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
5386     break;
5387   }
5388   }
5389 
5390   return func;
5391 }
5392 
5393 #define BUILDER(F) & F::s_singleton
5394 
5395 /*
5396   MySQL native functions.
5397   MAINTAINER:
5398   - Keep sorted for human lookup. At runtime, a hash table is used.
5399   - do **NOT** conditionally (#ifdef, #ifndef) define a function *NAME*:
5400     doing so will cause user code that works against a --without-XYZ binary
5401     to fail with name collisions against a --with-XYZ binary.
5402     Use something similar to GEOM_BUILDER instead.
5403   - keep 1 line per entry, it makes grep | sort easier
5404 */
5405 
5406 Native_func_registry func_array[] =
5407 {
5408   { { STRING_WITH_LEN("ABS") }, BUILDER(Create_func_abs)},
5409   { { STRING_WITH_LEN("ACOS") }, BUILDER(Create_func_acos)},
5410   { { STRING_WITH_LEN("ADDTIME") }, BUILDER(Create_func_addtime)},
5411   { { STRING_WITH_LEN("AES_DECRYPT") }, BUILDER(Create_func_aes_decrypt)},
5412   { { STRING_WITH_LEN("AES_ENCRYPT") }, BUILDER(Create_func_aes_encrypt)},
5413   { { STRING_WITH_LEN("ASIN") }, BUILDER(Create_func_asin)},
5414   { { STRING_WITH_LEN("ATAN") }, BUILDER(Create_func_atan)},
5415   { { STRING_WITH_LEN("ATAN2") }, BUILDER(Create_func_atan)},
5416   { { STRING_WITH_LEN("BENCHMARK") }, BUILDER(Create_func_benchmark)},
5417   { { STRING_WITH_LEN("BIN") }, BUILDER(Create_func_bin)},
5418   { { STRING_WITH_LEN("BINLOG_GTID_POS") }, BUILDER(Create_func_binlog_gtid_pos)},
5419   { { STRING_WITH_LEN("BIT_COUNT") }, BUILDER(Create_func_bit_count)},
5420   { { STRING_WITH_LEN("BIT_LENGTH") }, BUILDER(Create_func_bit_length)},
5421   { { STRING_WITH_LEN("CEIL") }, BUILDER(Create_func_ceiling)},
5422   { { STRING_WITH_LEN("CEILING") }, BUILDER(Create_func_ceiling)},
5423   { { STRING_WITH_LEN("CHARACTER_LENGTH") }, BUILDER(Create_func_char_length)},
5424   { { STRING_WITH_LEN("CHAR_LENGTH") }, BUILDER(Create_func_char_length)},
5425   { { STRING_WITH_LEN("CHR") }, BUILDER(Create_func_chr)},
5426   { { STRING_WITH_LEN("COERCIBILITY") }, BUILDER(Create_func_coercibility)},
5427   { { STRING_WITH_LEN("COLUMN_CHECK") }, BUILDER(Create_func_dyncol_check)},
5428   { { STRING_WITH_LEN("COLUMN_EXISTS") }, BUILDER(Create_func_dyncol_exists)},
5429   { { STRING_WITH_LEN("COLUMN_LIST") }, BUILDER(Create_func_dyncol_list)},
5430   { { STRING_WITH_LEN("COLUMN_JSON") }, BUILDER(Create_func_dyncol_json)},
5431   { { STRING_WITH_LEN("COMPRESS") }, BUILDER(Create_func_compress)},
5432   { { STRING_WITH_LEN("CONCAT") }, BUILDER(Create_func_concat)},
5433   { { STRING_WITH_LEN("CONCAT_OPERATOR_ORACLE") }, BUILDER(Create_func_concat_operator_oracle)},
5434   { { STRING_WITH_LEN("CONCAT_WS") }, BUILDER(Create_func_concat_ws)},
5435   { { STRING_WITH_LEN("CONNECTION_ID") }, BUILDER(Create_func_connection_id)},
5436   { { STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
5437   { { STRING_WITH_LEN("CONVERT_TZ") }, BUILDER(Create_func_convert_tz)},
5438   { { STRING_WITH_LEN("COS") }, BUILDER(Create_func_cos)},
5439   { { STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
5440   { { STRING_WITH_LEN("CRC32") }, BUILDER(Create_func_crc32)},
5441   { { STRING_WITH_LEN("DATEDIFF") }, BUILDER(Create_func_datediff)},
5442   { { STRING_WITH_LEN("DAYNAME") }, BUILDER(Create_func_dayname)},
5443   { { STRING_WITH_LEN("DAYOFMONTH") }, BUILDER(Create_func_dayofmonth)},
5444   { { STRING_WITH_LEN("DAYOFWEEK") }, BUILDER(Create_func_dayofweek)},
5445   { { STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)},
5446   { { STRING_WITH_LEN("DEGREES") }, BUILDER(Create_func_degrees)},
5447   { { STRING_WITH_LEN("DECODE_HISTOGRAM") }, BUILDER(Create_func_decode_histogram)},
5448   { { STRING_WITH_LEN("DECODE_ORACLE") }, BUILDER(Create_func_decode_oracle)},
5449   { { STRING_WITH_LEN("DES_DECRYPT") }, BUILDER(Create_func_des_decrypt)},
5450   { { STRING_WITH_LEN("DES_ENCRYPT") }, BUILDER(Create_func_des_encrypt)},
5451   { { STRING_WITH_LEN("ELT") }, BUILDER(Create_func_elt)},
5452   { { STRING_WITH_LEN("ENCODE") }, BUILDER(Create_func_encode)},
5453   { { STRING_WITH_LEN("ENCRYPT") }, BUILDER(Create_func_encrypt)},
5454   { { STRING_WITH_LEN("EXP") }, BUILDER(Create_func_exp)},
5455   { { STRING_WITH_LEN("EXPORT_SET") }, BUILDER(Create_func_export_set)},
5456   { { STRING_WITH_LEN("EXTRACTVALUE") }, BUILDER(Create_func_xml_extractvalue)},
5457   { { STRING_WITH_LEN("FIELD") }, BUILDER(Create_func_field)},
5458   { { STRING_WITH_LEN("FIND_IN_SET") }, BUILDER(Create_func_find_in_set)},
5459   { { STRING_WITH_LEN("FLOOR") }, BUILDER(Create_func_floor)},
5460   { { STRING_WITH_LEN("FORMAT") }, BUILDER(Create_func_format)},
5461   { { STRING_WITH_LEN("FOUND_ROWS") }, BUILDER(Create_func_found_rows)},
5462   { { STRING_WITH_LEN("FROM_BASE64") }, BUILDER(Create_func_from_base64)},
5463   { { STRING_WITH_LEN("FROM_DAYS") }, BUILDER(Create_func_from_days)},
5464   { { STRING_WITH_LEN("FROM_UNIXTIME") }, BUILDER(Create_func_from_unixtime)},
5465   { { STRING_WITH_LEN("GET_LOCK") }, BUILDER(Create_func_get_lock)},
5466   { { STRING_WITH_LEN("GREATEST") }, BUILDER(Create_func_greatest)},
5467   { { STRING_WITH_LEN("HEX") }, BUILDER(Create_func_hex)},
5468   { { STRING_WITH_LEN("IFNULL") }, BUILDER(Create_func_ifnull)},
5469   { { STRING_WITH_LEN("INSTR") }, BUILDER(Create_func_instr)},
5470   { { STRING_WITH_LEN("ISNULL") }, BUILDER(Create_func_isnull)},
5471   { { STRING_WITH_LEN("IS_FREE_LOCK") }, BUILDER(Create_func_is_free_lock)},
5472   { { STRING_WITH_LEN("IS_USED_LOCK") }, BUILDER(Create_func_is_used_lock)},
5473   { { STRING_WITH_LEN("JSON_ARRAY") }, BUILDER(Create_func_json_array)},
5474   { { STRING_WITH_LEN("JSON_ARRAY_APPEND") }, BUILDER(Create_func_json_array_append)},
5475   { { STRING_WITH_LEN("JSON_ARRAY_INSERT") }, BUILDER(Create_func_json_array_insert)},
5476   { { STRING_WITH_LEN("JSON_COMPACT") }, BUILDER(Create_func_json_compact)},
5477   { { STRING_WITH_LEN("JSON_CONTAINS") }, BUILDER(Create_func_json_contains)},
5478   { { STRING_WITH_LEN("JSON_CONTAINS_PATH") }, BUILDER(Create_func_json_contains_path)},
5479   { { STRING_WITH_LEN("JSON_DEPTH") }, BUILDER(Create_func_json_depth)},
5480   { { STRING_WITH_LEN("JSON_DETAILED") }, BUILDER(Create_func_json_detailed)},
5481   { { STRING_WITH_LEN("JSON_EXISTS") }, BUILDER(Create_func_json_exists)},
5482   { { STRING_WITH_LEN("JSON_EXTRACT") }, BUILDER(Create_func_json_extract)},
5483   { { STRING_WITH_LEN("JSON_INSERT") }, BUILDER(Create_func_json_insert)},
5484   { { STRING_WITH_LEN("JSON_KEYS") }, BUILDER(Create_func_json_keys)},
5485   { { STRING_WITH_LEN("JSON_LENGTH") }, BUILDER(Create_func_json_length)},
5486   { { STRING_WITH_LEN("JSON_LOOSE") }, BUILDER(Create_func_json_loose)},
5487   { { STRING_WITH_LEN("JSON_MERGE") }, BUILDER(Create_func_json_merge)},
5488   { { STRING_WITH_LEN("JSON_MERGE_PATCH") }, BUILDER(Create_func_json_merge_patch)},
5489   { { STRING_WITH_LEN("JSON_MERGE_PRESERVE") }, BUILDER(Create_func_json_merge)},
5490   { { STRING_WITH_LEN("JSON_QUERY") }, BUILDER(Create_func_json_query)},
5491   { { STRING_WITH_LEN("JSON_QUOTE") }, BUILDER(Create_func_json_quote)},
5492   { { STRING_WITH_LEN("JSON_OBJECT") }, BUILDER(Create_func_json_object)},
5493   { { STRING_WITH_LEN("JSON_REMOVE") }, BUILDER(Create_func_json_remove)},
5494   { { STRING_WITH_LEN("JSON_REPLACE") }, BUILDER(Create_func_json_replace)},
5495   { { STRING_WITH_LEN("JSON_SET") }, BUILDER(Create_func_json_set)},
5496   { { STRING_WITH_LEN("JSON_SEARCH") }, BUILDER(Create_func_json_search)},
5497   { { STRING_WITH_LEN("JSON_TYPE") }, BUILDER(Create_func_json_type)},
5498   { { STRING_WITH_LEN("JSON_UNQUOTE") }, BUILDER(Create_func_json_unquote)},
5499   { { STRING_WITH_LEN("JSON_VALID") }, BUILDER(Create_func_json_valid)},
5500   { { STRING_WITH_LEN("JSON_VALUE") }, BUILDER(Create_func_json_value)},
5501   { { STRING_WITH_LEN("LAST_DAY") }, BUILDER(Create_func_last_day)},
5502   { { STRING_WITH_LEN("LAST_INSERT_ID") }, BUILDER(Create_func_last_insert_id)},
5503   { { STRING_WITH_LEN("LCASE") }, BUILDER(Create_func_lcase)},
5504   { { STRING_WITH_LEN("LEAST") }, BUILDER(Create_func_least)},
5505   { { STRING_WITH_LEN("LENGTH") }, BUILDER(Create_func_length)},
5506   { { STRING_WITH_LEN("LENGTHB") }, BUILDER(Create_func_octet_length)},
5507 #ifndef DBUG_OFF
5508   { { STRING_WITH_LEN("LIKE_RANGE_MIN") }, BUILDER(Create_func_like_range_min)},
5509   { { STRING_WITH_LEN("LIKE_RANGE_MAX") }, BUILDER(Create_func_like_range_max)},
5510 #endif
5511   { { STRING_WITH_LEN("LN") }, BUILDER(Create_func_ln)},
5512   { { STRING_WITH_LEN("LOAD_FILE") }, BUILDER(Create_func_load_file)},
5513   { { STRING_WITH_LEN("LOCATE") }, BUILDER(Create_func_locate)},
5514   { { STRING_WITH_LEN("LOG") }, BUILDER(Create_func_log)},
5515   { { STRING_WITH_LEN("LOG10") }, BUILDER(Create_func_log10)},
5516   { { STRING_WITH_LEN("LOG2") }, BUILDER(Create_func_log2)},
5517   { { STRING_WITH_LEN("LOWER") }, BUILDER(Create_func_lcase)},
5518   { { STRING_WITH_LEN("LPAD") }, BUILDER(Create_func_lpad)},
5519   { { STRING_WITH_LEN("LPAD_ORACLE") }, BUILDER(Create_func_lpad_oracle)},
5520   { { STRING_WITH_LEN("LTRIM") }, BUILDER(Create_func_ltrim)},
5521   { { STRING_WITH_LEN("LTRIM_ORACLE") }, BUILDER(Create_func_ltrim_oracle)},
5522   { { STRING_WITH_LEN("MAKEDATE") }, BUILDER(Create_func_makedate)},
5523   { { STRING_WITH_LEN("MAKETIME") }, BUILDER(Create_func_maketime)},
5524   { { STRING_WITH_LEN("MAKE_SET") }, BUILDER(Create_func_make_set)},
5525   { { STRING_WITH_LEN("MASTER_GTID_WAIT") }, BUILDER(Create_func_master_gtid_wait)},
5526   { { STRING_WITH_LEN("MASTER_POS_WAIT") }, BUILDER(Create_func_master_pos_wait)},
5527   { { STRING_WITH_LEN("MD5") }, BUILDER(Create_func_md5)},
5528   { { STRING_WITH_LEN("MONTHNAME") }, BUILDER(Create_func_monthname)},
5529   { { STRING_WITH_LEN("NAME_CONST") }, BUILDER(Create_func_name_const)},
5530   { { STRING_WITH_LEN("NVL") }, BUILDER(Create_func_ifnull)},
5531   { { STRING_WITH_LEN("NVL2") }, BUILDER(Create_func_nvl2)},
5532   { { STRING_WITH_LEN("NULLIF") }, BUILDER(Create_func_nullif)},
5533   { { STRING_WITH_LEN("OCT") }, BUILDER(Create_func_oct)},
5534   { { STRING_WITH_LEN("OCTET_LENGTH") }, BUILDER(Create_func_octet_length)},
5535   { { STRING_WITH_LEN("ORD") }, BUILDER(Create_func_ord)},
5536   { { STRING_WITH_LEN("PERIOD_ADD") }, BUILDER(Create_func_period_add)},
5537   { { STRING_WITH_LEN("PERIOD_DIFF") }, BUILDER(Create_func_period_diff)},
5538   { { STRING_WITH_LEN("PI") }, BUILDER(Create_func_pi)},
5539   { { STRING_WITH_LEN("POW") }, BUILDER(Create_func_pow)},
5540   { { STRING_WITH_LEN("POWER") }, BUILDER(Create_func_pow)},
5541   { { STRING_WITH_LEN("QUOTE") }, BUILDER(Create_func_quote)},
5542   { { STRING_WITH_LEN("REGEXP_INSTR") }, BUILDER(Create_func_regexp_instr)},
5543   { { STRING_WITH_LEN("REGEXP_REPLACE") }, BUILDER(Create_func_regexp_replace)},
5544   { { STRING_WITH_LEN("REGEXP_SUBSTR") }, BUILDER(Create_func_regexp_substr)},
5545   { { STRING_WITH_LEN("RADIANS") }, BUILDER(Create_func_radians)},
5546   { { STRING_WITH_LEN("RAND") }, BUILDER(Create_func_rand)},
5547   { { STRING_WITH_LEN("RELEASE_ALL_LOCKS") },
5548       BUILDER(Create_func_release_all_locks)},
5549   { { STRING_WITH_LEN("RELEASE_LOCK") }, BUILDER(Create_func_release_lock)},
5550   { { STRING_WITH_LEN("REPLACE_ORACLE") },
5551       BUILDER(Create_func_replace_oracle)},
5552   { { STRING_WITH_LEN("REVERSE") }, BUILDER(Create_func_reverse)},
5553   { { STRING_WITH_LEN("ROUND") }, BUILDER(Create_func_round)},
5554   { { STRING_WITH_LEN("RPAD") }, BUILDER(Create_func_rpad)},
5555   { { STRING_WITH_LEN("RPAD_ORACLE") }, BUILDER(Create_func_rpad_oracle)},
5556   { { STRING_WITH_LEN("RTRIM") }, BUILDER(Create_func_rtrim)},
5557   { { STRING_WITH_LEN("RTRIM_ORACLE") }, BUILDER(Create_func_rtrim_oracle)},
5558   { { STRING_WITH_LEN("SEC_TO_TIME") }, BUILDER(Create_func_sec_to_time)},
5559   { { STRING_WITH_LEN("SHA") }, BUILDER(Create_func_sha)},
5560   { { STRING_WITH_LEN("SHA1") }, BUILDER(Create_func_sha)},
5561   { { STRING_WITH_LEN("SHA2") }, BUILDER(Create_func_sha2)},
5562   { { STRING_WITH_LEN("SIGN") }, BUILDER(Create_func_sign)},
5563   { { STRING_WITH_LEN("SIN") }, BUILDER(Create_func_sin)},
5564   { { STRING_WITH_LEN("SLEEP") }, BUILDER(Create_func_sleep)},
5565   { { STRING_WITH_LEN("SOUNDEX") }, BUILDER(Create_func_soundex)},
5566   { { STRING_WITH_LEN("SPACE") }, BUILDER(Create_func_space)},
5567   { { STRING_WITH_LEN("SQRT") }, BUILDER(Create_func_sqrt)},
5568   { { STRING_WITH_LEN("STRCMP") }, BUILDER(Create_func_strcmp)},
5569   { { STRING_WITH_LEN("STR_TO_DATE") }, BUILDER(Create_func_str_to_date)},
5570   { { STRING_WITH_LEN("SUBSTR_ORACLE") },
5571       BUILDER(Create_func_substr_oracle)},
5572   { { STRING_WITH_LEN("SUBSTRING_INDEX") }, BUILDER(Create_func_substr_index)},
5573   { { STRING_WITH_LEN("SUBTIME") }, BUILDER(Create_func_subtime)},
5574   { { STRING_WITH_LEN("TAN") }, BUILDER(Create_func_tan)},
5575   { { STRING_WITH_LEN("TIMEDIFF") }, BUILDER(Create_func_timediff)},
5576   { { STRING_WITH_LEN("TIME_FORMAT") }, BUILDER(Create_func_time_format)},
5577   { { STRING_WITH_LEN("TIME_TO_SEC") }, BUILDER(Create_func_time_to_sec)},
5578   { { STRING_WITH_LEN("TO_BASE64") }, BUILDER(Create_func_to_base64)},
5579   { { STRING_WITH_LEN("TO_DAYS") }, BUILDER(Create_func_to_days)},
5580   { { STRING_WITH_LEN("TO_SECONDS") }, BUILDER(Create_func_to_seconds)},
5581   { { STRING_WITH_LEN("UCASE") }, BUILDER(Create_func_ucase)},
5582   { { STRING_WITH_LEN("UNCOMPRESS") }, BUILDER(Create_func_uncompress)},
5583   { { STRING_WITH_LEN("UNCOMPRESSED_LENGTH") }, BUILDER(Create_func_uncompressed_length)},
5584   { { STRING_WITH_LEN("UNHEX") }, BUILDER(Create_func_unhex)},
5585   { { STRING_WITH_LEN("UNIX_TIMESTAMP") }, BUILDER(Create_func_unix_timestamp)},
5586   { { STRING_WITH_LEN("UPDATEXML") }, BUILDER(Create_func_xml_update)},
5587   { { STRING_WITH_LEN("UPPER") }, BUILDER(Create_func_ucase)},
5588   { { STRING_WITH_LEN("UUID") }, BUILDER(Create_func_uuid)},
5589   { { STRING_WITH_LEN("UUID_SHORT") }, BUILDER(Create_func_uuid_short)},
5590   { { STRING_WITH_LEN("VERSION") }, BUILDER(Create_func_version)},
5591   { { STRING_WITH_LEN("WEEKDAY") }, BUILDER(Create_func_weekday)},
5592   { { STRING_WITH_LEN("WEEKOFYEAR") }, BUILDER(Create_func_weekofyear)},
5593 #ifdef WITH_WSREP
5594   { { STRING_WITH_LEN("WSREP_LAST_WRITTEN_GTID") }, BUILDER(Create_func_wsrep_last_written_gtid)},
5595   { { STRING_WITH_LEN("WSREP_LAST_SEEN_GTID") }, BUILDER(Create_func_wsrep_last_seen_gtid)},
5596   { { STRING_WITH_LEN("WSREP_SYNC_WAIT_UPTO_GTID") }, BUILDER(Create_func_wsrep_sync_wait_upto)},
5597 #endif /* WITH_WSREP */
5598   { { STRING_WITH_LEN("YEARWEEK") }, BUILDER(Create_func_year_week)}
5599 };
5600 
5601 Native_func_registry_array
5602   native_func_registry_array(func_array, array_elements(func_array));
5603 
5604 static HASH native_functions_hash;
5605 
5606 /*
5607   Load the hash table for native functions.
5608   Note: this code is not thread safe, and is intended to be used at server
5609   startup only (before going multi-threaded)
5610 */
5611 
item_create_init()5612 int item_create_init()
5613 {
5614   DBUG_ENTER("item_create_init");
5615   size_t count= native_func_registry_array.count();
5616 #ifdef HAVE_SPATIAL
5617   count+= native_func_registry_array_geom.count();
5618 #endif
5619   if (my_hash_init(key_memory_native_functions, & native_functions_hash,
5620                    system_charset_info, (ulong) count, 0, 0, (my_hash_get_key)
5621                    get_native_fct_hash_key, NULL, MYF(0)))
5622     DBUG_RETURN(1);
5623 
5624   if (native_func_registry_array.append_to_hash(&native_functions_hash))
5625     DBUG_RETURN(1);
5626 
5627 #ifdef HAVE_SPATIAL
5628   if (native_func_registry_array_geom.append_to_hash(&native_functions_hash))
5629     DBUG_RETURN(1);
5630 #endif
5631 
5632 #ifndef DBUG_OFF
5633   for (uint i=0 ; i < native_functions_hash.records ; i++)
5634   {
5635     Native_func_registry *func;
5636     func= (Native_func_registry*) my_hash_element(& native_functions_hash, i);
5637     DBUG_PRINT("info", ("native function: %s  length: %u",
5638                         func->name.str, (uint) func->name.length));
5639   }
5640 #endif
5641 
5642   DBUG_RETURN(0);
5643 }
5644 
5645 
5646 /*
5647   This function is used (dangerously) by plugin/versioning/versioning.cc
5648   TODO: MDEV-20842 Wrap SQL functions defined in
5649         plugin/versioning/versioning.cc into MariaDB_FUNCTION_PLUGIN
5650 */
item_create_append(Native_func_registry array[])5651 int item_create_append(Native_func_registry array[])
5652 {
5653   Native_func_registry *func;
5654 
5655   DBUG_ENTER("item_create_append");
5656 
5657   for (func= array; func->builder != NULL; func++)
5658   {
5659     if (my_hash_insert(& native_functions_hash, (uchar*) func))
5660       DBUG_RETURN(1);
5661   }
5662 
5663   DBUG_RETURN(0);
5664 }
5665 
item_create_remove(Native_func_registry array[])5666 int item_create_remove(Native_func_registry array[])
5667 {
5668   Native_func_registry *func;
5669 
5670   DBUG_ENTER("item_create_remove");
5671 
5672   for (func= array; func->builder != NULL; func++)
5673   {
5674     if (my_hash_delete(& native_functions_hash, (uchar*) func))
5675       DBUG_RETURN(1);
5676   }
5677 
5678   DBUG_RETURN(0);
5679 }
5680 
5681 /*
5682   Empty the hash table for native functions.
5683   Note: this code is not thread safe, and is intended to be used at server
5684   shutdown only (after thread requests have been executed).
5685 */
5686 
item_create_cleanup()5687 void item_create_cleanup()
5688 {
5689   DBUG_ENTER("item_create_cleanup");
5690   my_hash_free(& native_functions_hash);
5691   DBUG_VOID_RETURN;
5692 }
5693 
5694 
5695 static Create_func *
function_plugin_find_native_function_builder(THD * thd,const LEX_CSTRING & name)5696 function_plugin_find_native_function_builder(THD *thd, const LEX_CSTRING &name)
5697 {
5698   plugin_ref plugin;
5699   if ((plugin= my_plugin_lock_by_name(thd, &name, MariaDB_FUNCTION_PLUGIN)))
5700   {
5701     Create_func *builder=
5702       reinterpret_cast<Plugin_function*>(plugin_decl(plugin)->info)->
5703         create_func();
5704     // TODO: MDEV-20846 Add proper unlocking for MariaDB_FUNCTION_PLUGIN
5705     plugin_unlock(thd, plugin);
5706     return builder;
5707   }
5708   return NULL;
5709 }
5710 
5711 
5712 Create_func *
find_native_function_builder(THD * thd,const LEX_CSTRING * name)5713 find_native_function_builder(THD *thd, const LEX_CSTRING *name)
5714 {
5715   Native_func_registry *func;
5716   Create_func *builder= NULL;
5717 
5718   /* Thread safe */
5719   func= (Native_func_registry*) my_hash_search(&native_functions_hash,
5720                                                (uchar*) name->str,
5721                                                name->length);
5722 
5723   if (func && (builder= func->builder))
5724     return builder;
5725 
5726   if ((builder= function_plugin_find_native_function_builder(thd, *name)))
5727     return builder;
5728 
5729   return NULL;
5730 }
5731 
5732 Create_qfunc *
find_qualified_function_builder(THD * thd)5733 find_qualified_function_builder(THD *thd)
5734 {
5735   return & Create_sp_func::s_singleton;
5736 }
5737 
5738 
create_func_dyncol_prepare(THD * thd,DYNCALL_CREATE_DEF ** dfs,List<DYNCALL_CREATE_DEF> & list)5739 static List<Item> *create_func_dyncol_prepare(THD *thd,
5740                                               DYNCALL_CREATE_DEF **dfs,
5741                                               List<DYNCALL_CREATE_DEF> &list)
5742 {
5743   DYNCALL_CREATE_DEF *def;
5744   List_iterator_fast<DYNCALL_CREATE_DEF> li(list);
5745   List<Item> *args= new (thd->mem_root) List<Item>;
5746 
5747   *dfs= (DYNCALL_CREATE_DEF *)alloc_root(thd->mem_root,
5748                                          sizeof(DYNCALL_CREATE_DEF) *
5749                                          list.elements);
5750 
5751   if (!args || !*dfs)
5752     return NULL;
5753 
5754   for (uint i= 0; (def= li++) ;)
5755   {
5756     dfs[0][i++]= *def;
5757     args->push_back(def->key, thd->mem_root);
5758     args->push_back(def->value, thd->mem_root);
5759   }
5760   return args;
5761 }
5762 
create_func_dyncol_create(THD * thd,List<DYNCALL_CREATE_DEF> & list)5763 Item *create_func_dyncol_create(THD *thd, List<DYNCALL_CREATE_DEF> &list)
5764 {
5765   List<Item> *args;
5766   DYNCALL_CREATE_DEF *dfs;
5767   if (!(args= create_func_dyncol_prepare(thd, &dfs, list)))
5768     return NULL;
5769 
5770   return new (thd->mem_root) Item_func_dyncol_create(thd, *args, dfs);
5771 }
5772 
create_func_dyncol_add(THD * thd,Item * str,List<DYNCALL_CREATE_DEF> & list)5773 Item *create_func_dyncol_add(THD *thd, Item *str,
5774                              List<DYNCALL_CREATE_DEF> &list)
5775 {
5776   List<Item> *args;
5777   DYNCALL_CREATE_DEF *dfs;
5778 
5779   if (!(args= create_func_dyncol_prepare(thd, &dfs, list)))
5780     return NULL;
5781 
5782   args->push_back(str, thd->mem_root);
5783 
5784   return new (thd->mem_root) Item_func_dyncol_add(thd, *args, dfs);
5785 }
5786 
5787 
5788 
create_func_dyncol_delete(THD * thd,Item * str,List<Item> & nums)5789 Item *create_func_dyncol_delete(THD *thd, Item *str, List<Item> &nums)
5790 {
5791   DYNCALL_CREATE_DEF *dfs;
5792   Item *key;
5793   List_iterator_fast<Item> it(nums);
5794   List<Item> *args= new (thd->mem_root) List<Item>;
5795 
5796   dfs= (DYNCALL_CREATE_DEF *)alloc_root(thd->mem_root,
5797                                         sizeof(DYNCALL_CREATE_DEF) *
5798                                         nums.elements);
5799   if (!args || !dfs)
5800     return NULL;
5801 
5802   for (uint i= 0; (key= it++); i++)
5803   {
5804     dfs[i].key= key;
5805     dfs[i].value= new (thd->mem_root) Item_null(thd);
5806     dfs[i].type= DYN_COL_INT;
5807     args->push_back(dfs[i].key, thd->mem_root);
5808     args->push_back(dfs[i].value, thd->mem_root);
5809   }
5810 
5811   args->push_back(str, thd->mem_root);
5812 
5813   return new (thd->mem_root) Item_func_dyncol_add(thd, *args, dfs);
5814 }
5815 
5816 
create_func_dyncol_get(THD * thd,Item * str,Item * num,const Type_handler * handler,const char * c_len,const char * c_dec,CHARSET_INFO * cs)5817 Item *create_func_dyncol_get(THD *thd,  Item *str, Item *num,
5818                              const Type_handler *handler,
5819                              const char *c_len, const char *c_dec,
5820                              CHARSET_INFO *cs)
5821 {
5822   Item *res;
5823 
5824   if (likely(!(res= new (thd->mem_root) Item_dyncol_get(thd, str, num))))
5825     return res;                                 // Return NULL
5826   return handler->create_typecast_item(thd, res,
5827                                        Type_cast_attributes(c_len, c_dec, cs));
5828 }
5829