CUBRID Engine  latest
show_meta.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * show_meta.c - show statement infos, including column defination, semantic check.
21  */
22 
23 #ident "$Id$"
24 
25 
26 #include "config.h"
27 
28 #include <assert.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <limits.h>
33 #include <ctype.h>
34 
35 #include "authenticate.h"
36 #include "show_meta.h"
37 #include "error_manager.h"
38 #include "parser.h"
39 #include "schema_manager.h"
40 #include "dbtype.h"
41 #include "error_code.h"
42 #include "db.h"
43 
44 enum
45 {
46  ARG_REQUIRED = false, /* argument is required */
47  ARG_OPTIONAL = true /* argument is optional */
48 };
49 
50 enum
51 {
52  ORDER_DESC = false, /* order by descending */
53  ORDER_ASC = true /* order by ascending */
54 };
55 
56 typedef enum
57 {
61 
62 static bool show_Inited = false;
64 
66 static void free_db_attribute_list (SHOWSTMT_METADATA * md);
67 
68 /* check functions */
72 
73 /* meta functions */
91 
92 static SHOWSTMT_METADATA *
94 {
95  static const SHOWSTMT_COLUMN cols[] = {
96  {"Volume_id", "int"},
97  {"Magic_symbol", "varchar(100)"},
98  {"Io_page_size", "short"},
99  {"Purpose", "varchar(24)"},
100  {"Type", "varchar(24)"},
101  {"Sector_size_in_pages", "int"},
102  {"Num_total_sectors", "int"},
103  {"Num_free_sectors", "int"},
104  {"Num_max_sectors", "int"},
105  {"Hint_alloc_sector", "int"},
106  {"Sector_alloc_table_size_in_pages", "int"},
107  {"Sector_alloc_table_first_page", "int"},
108  {"Last_system_page", "int"},
109  {"Creation_time", "datetime"},
110  {"Db_charset", "int"},
111  {"Checkpoint_lsa", "varchar(64)"},
112  {"Boot_hfid", "varchar(64)"},
113  {"Full_name", "varchar(255)"},
114  {"Next_volume_id", "int"},
115  {"Next_vol_full_name", "varchar(255)"},
116  {"Remarks", "varchar(64)"}
117  };
118 
119  static const SHOWSTMT_NAMED_ARG args[] = {
121  };
122 
123  static SHOWSTMT_METADATA md = {
124  SHOWSTMT_VOLUME_HEADER, true /* only_for_dba */ , "show volume header of ",
125  cols, DIM (cols), NULL, 0, args, DIM (args), NULL, NULL
126  };
127  return &md;
128 }
129 
130 static SHOWSTMT_METADATA *
132 {
133  static const SHOWSTMT_COLUMN cols[] = {
134  {"Volume_id", "int"},
135  {"Magic_symbol", "varchar(32)"},
136  {"Magic_symbol_location", "int"},
137  {"Creation_time", "datetime"},
138  {"Release", "varchar(32)"},
139  {"Compatibility_disk_version", "varchar(32)"},
140  {"Db_page_size", "int"},
141  {"Log_page_size", "int"},
142  {"Shutdown", "int"},
143  {"Next_trans_id", "int"},
144  {"Num_avg_trans", "int"},
145  {"Num_avg_locks", "int"},
146  {"Num_active_log_pages", "int"},
147  {"Db_charset", "int"},
148  {"First_active_log_page", "bigint"},
149  {"Current_append", "varchar(64)"},
150  {"Checkpoint", "varchar(64)"},
151  {"Next_archive_page_id", "bigint"},
152  {"Active_physical_page_id", "int"},
153  {"Next_archive_num", "int"},
154  {"Last_archive_num_for_syscrashes", "int"},
155  {"Last_deleted_archive_num", "int"},
156  {"Backup_lsa_level0", "varchar(64)"},
157  {"Backup_lsa_level1", "varchar(64)"},
158  {"Backup_lsa_level2", "varchar(64)"},
159  {"Log_prefix", "varchar(256)"},
160  {"Has_logging_been_skipped", "int"},
161  {"Perm_status", "varchar(64)"},
162  {"Backup_info_level0", "varchar(128)"},
163  {"Backup_info_level1", "varchar(128)"},
164  {"Backup_info_level2", "varchar(128)"},
165  {"Ha_server_state", "varchar(32)"},
166  {"Ha_file", "varchar(32)"},
167  {"Eof_lsa", "varchar(64)"},
168  {"Smallest_lsa_at_last_checkpoint", "varchar(64)"},
169  {"Next_mvcc_id", "bigint"},
170  {"Mvcc_op_log_lsa", "varchar(32)"},
171  {"Last_block_oldest_mvcc_id", "bigint"},
172  {"Last_block_newest_mvcc_id", "bigint"}
173  };
174 
175  static const SHOWSTMT_NAMED_ARG args[] = {
177  };
178 
179  static SHOWSTMT_METADATA md = {
180  SHOWSTMT_ACTIVE_LOG_HEADER, true /* only_for_dba */ , "show log header of ",
181  cols, DIM (cols), NULL, 0, args, DIM (args), NULL, NULL
182  };
183 
184  return &md;
185 }
186 
187 static SHOWSTMT_METADATA *
189 {
190  static const SHOWSTMT_COLUMN cols[] = {
191  {"Volume_id", "int"},
192  {"Magic_symbol", "varchar(32)"},
193  {"Magic_symbol_location", "int"},
194  {"Creation_time", "datetime"},
195  {"Next_trans_id", "bigint"},
196  {"Num_pages", "int"},
197  {"First_page_id", "bigint"},
198  {"Archive_num", "int"}
199  };
200 
201  static const SHOWSTMT_NAMED_ARG args[] = {
203  };
204 
205  static SHOWSTMT_METADATA md = {
206  SHOWSTMT_ARCHIVE_LOG_HEADER, true /* only_for_dba */ , "show archive log header of ",
207  cols, DIM (cols), NULL, 0, args, DIM (args), NULL, NULL
208  };
209 
210  return &md;
211 }
212 
213 static SHOWSTMT_METADATA *
215 {
216  static const SHOWSTMT_COLUMN cols[] = {
217  {"Volume_id", "int"},
218  {"Page_id", "int"},
219  {"Num_slots", "int"},
220  {"Num_records", "int"},
221  {"Anchor_type", "varchar(32)"},
222  {"Alignment", "varchar(8)"},
223  {"Total_free_area", "int"},
224  {"Contiguous_free_area", "int"},
225  {"Free_space_offset", "int"},
226  {"Need_update_best_hint", "int"},
227  {"Is_saving", "int"},
228  {"Flags", "int"}
229  };
230 
231  static const SHOWSTMT_NAMED_ARG args[] = {
232  {"volume", AVT_INTEGER, ARG_REQUIRED},
233  {"page", AVT_INTEGER, ARG_REQUIRED}
234  };
235 
236  static SHOWSTMT_METADATA md = {
237  SHOWSTMT_SLOTTED_PAGE_HEADER, true /* only_for_dba */ , "show slotted page header of ",
238  cols, DIM (cols), NULL, 0, args, DIM (args), NULL, NULL
239  };
240 
241  return &md;
242 }
243 
244 static SHOWSTMT_METADATA *
246 {
247  static const SHOWSTMT_COLUMN cols[] = {
248  {"Volume_id", "int"},
249  {"Page_id", "int"},
250  {"Slot_id", "int"},
251  {"Offset", "int"},
252  {"Type", "varchar(32)"},
253  {"Length", "int"},
254  {"Waste", "int"}
255  };
256 
257  static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
258  {3, ORDER_ASC}
259  };
260 
261  static const SHOWSTMT_NAMED_ARG args[] = {
262  {"volume", AVT_INTEGER, ARG_REQUIRED},
263  {"page", AVT_INTEGER, ARG_REQUIRED}
264  };
265 
266  static SHOWSTMT_METADATA md = {
267  SHOWSTMT_SLOTTED_PAGE_SLOTS, true /* only_for_dba */ , "show slotted page slots of ",
268  cols, DIM (cols), orderby, DIM (orderby), args, DIM (args), NULL, NULL
269  };
270 
271  return &md;
272 }
273 
274 static SHOWSTMT_METADATA *
276 {
277  static const SHOWSTMT_COLUMN cols[] = {
278  {"user_name", "varchar(32)"},
279  {"last_access_time", "datetime"},
280  {"last_access_host", "varchar(32)"},
281  {"program_name", "varchar(32)"}
282  };
283 
284  static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
285  {1, ORDER_ASC}
286  };
287 
288  static SHOWSTMT_METADATA md = {
289  SHOWSTMT_ACCESS_STATUS, true /* only_for_dba */ , "show access status",
290  cols, DIM (cols), orderby, DIM (orderby), NULL, 0, pt_check_access_status, NULL
291  };
292 
293  return &md;
294 }
295 
296 static SHOWSTMT_METADATA *
298 {
299  static const SHOWSTMT_COLUMN cols[] = {
300  {"Table_name", "varchar(256)"},
301  {"Class_oid", "varchar(64)"},
302  {"Volume_id", "int"},
303  {"File_id", "int"},
304  {"Header_page_id", "int"},
305  {"Overflow_vfid", "varchar(64)"},
306  {"Next_vpid", "varchar(64)"},
307  {"Unfill_space", "int"},
308  {"Estimates_num_pages", "bigint"},
309  {"Estimates_num_recs", "bigint"},
310  {"Estimates_avg_rec_len", "int"},
311  {"Estimates_num_high_best", "int"},
312  {"Estimates_num_others_high_best", "int"},
313  {"Estimates_head", "int"},
314  {"Estimates_best_list", "varchar(512)"},
315  {"Estimates_num_second_best", "int"},
316  {"Estimates_head_second_best", "int"},
317  {"Estimates_tail_second_best", "int"},
318  {"Estimates_num_substitutions", "int"},
319  {"Estimates_second_best_list", "varchar(256)"},
320  {"Estimates_last_vpid", "varchar(64)"},
321  {"Estimates_full_search_vpid", "varchar(64)"}
322  };
323 
324  static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
325  {1, ORDER_ASC}
326  };
327 
328  static const SHOWSTMT_NAMED_ARG args[] = {
330  };
331 
332  static SHOWSTMT_METADATA md_only = {
333  SHOWSTMT_HEAP_HEADER, true /* only_for_dba */ , "show heap header of ",
334  cols, DIM (cols), NULL, 0, args, DIM (args), pt_check_table_in_show_heap, NULL
335  };
336 
337  static SHOWSTMT_METADATA md_all = {
338  SHOWSTMT_ALL_HEAP_HEADER, true /* only_for_dba */ , "show all heap header of ",
339  cols, DIM (cols), orderby, DIM (orderby), args, DIM (args), pt_check_table_in_show_heap, NULL
340  };
341 
342  return (flag == SHOW_ALL) ? &md_all : &md_only;
343 }
344 
345 static SHOWSTMT_METADATA *
347 {
348  static const SHOWSTMT_COLUMN cols[] = {
349  {"Table_name", "varchar(256)"},
350  {"Class_oid", "varchar(64)"},
351  {"Volume_id", "int"},
352  {"File_id", "int"},
353  {"Header_page_id", "int"},
354  {"Num_recs", "bigint"},
355  {"Num_relocated_recs", "bigint"},
356  {"Num_overflowed_recs", "bigint"},
357  {"Num_pages", "bigint"},
358  {"Avg_rec_len", "int"},
359  {"Avg_free_space_per_page", "int"},
360  {"Avg_free_space_per_page_except_last_page", "int"},
361  {"Avg_overhead_per_page", "int"},
362  {"Repr_id", "int"},
363  {"Num_total_attrs", "int"},
364  {"Num_fixed_width_attrs", "int"},
365  {"Num_variable_width_attrs", "int"},
366  {"Num_shared_attrs", "int"},
367  {"Num_class_attrs", "int"},
368  {"Total_size_fixed_width_attrs", "int"}
369  };
370 
371  static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
372  {1, ORDER_ASC}
373  };
374 
375  static const SHOWSTMT_NAMED_ARG args[] = {
377  };
378 
379  static SHOWSTMT_METADATA md_only = {
380  SHOWSTMT_HEAP_CAPACITY, true /* only_for_dba */ , "show heap capacity of ",
381  cols, DIM (cols), orderby, DIM (orderby), args, DIM (args), pt_check_table_in_show_heap, NULL
382  };
383 
384  static SHOWSTMT_METADATA md_all = {
385  SHOWSTMT_ALL_HEAP_CAPACITY, true /* only_for_dba */ , "show all heap capacity of ",
386  cols, DIM (cols), orderby, DIM (orderby), args, DIM (args), pt_check_table_in_show_heap, NULL
387  };
388 
389  return (flag == SHOW_ALL) ? &md_all : &md_only;
390 }
391 
392 /* for show index header */
393 static SHOWSTMT_METADATA *
395 {
396  static const SHOWSTMT_COLUMN cols[] = {
397  {"Table_name", "varchar(256)"},
398  {"Index_name", "varchar(256)"},
399  {"Btid", "varchar(64)"},
400  {"Node_level", "int"},
401  {"Max_key_len", "int"},
402  {"Num_oids", "int"},
403  {"Num_nulls", "int"},
404  {"Num_keys", "int"},
405  {"Topclass_oid", "varchar(64)"},
406  {"Unique", "int"},
407  {"Overflow_vfid", "varchar(32)"},
408  {"Key_type", "varchar(256)"},
409  {"Columns", "varchar(256)"}
410  };
411 
412  static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
413  {1, ORDER_ASC},
414  {2, ORDER_ASC}
415  };
416 
417  static const SHOWSTMT_NAMED_ARG args1[] = {
419  };
420  static const SHOWSTMT_NAMED_ARG args2[] = {
421  {NULL, AVT_IDENTIFIER, ARG_REQUIRED},
422  {NULL, AVT_IDENTIFIER, ARG_REQUIRED}
423  };
424 
425  static SHOWSTMT_METADATA md_all = {
426  SHOWSTMT_ALL_INDEXES_HEADER, true /* only_for_dba */ , "show all indexes header of ",
427  cols, DIM (cols), orderby, DIM (orderby), args1, DIM (args1), pt_check_show_index, NULL
428  };
429 
430  static SHOWSTMT_METADATA md_only = {
431  SHOWSTMT_INDEX_HEADER, true /* only_for_dba */ , "show index header of ",
432  cols, DIM (cols), NULL, 0, args2, DIM (args2), pt_check_show_index, NULL
433  };
434 
435  return (flag == SHOW_ALL) ? &md_all : &md_only;
436 }
437 
438 /* for show index capacity */
439 static SHOWSTMT_METADATA *
441 {
442  static const SHOWSTMT_COLUMN cols[] = {
443  {"Table_name", "varchar(256)"},
444  {"Index_name", "varchar(256)"},
445  {"Btid", "varchar(64)"},
446  {"Num_distinct_key", "int"},
447  {"Total_value", "int"},
448  {"Avg_num_value_per_key", "int"},
449  {"Num_leaf_page", "int"},
450  {"Num_non_leaf_page", "int"},
451  {"Num_total_page", "int"},
452  {"Height", "int"},
453  {"Avg_key_len", "int"},
454  {"Avg_rec_len", "int"},
455  {"Total_space", "varchar(64)"},
456  {"Total_used_space", "varchar(64)"},
457  {"Total_free_space", "varchar(64)"},
458  {"Avg_num_page_key", "int"},
459  {"Avg_page_free_space", "varchar(64)"}
460  };
461 
462  static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
463  {1, ORDER_ASC},
464  {2, ORDER_ASC}
465  };
466 
467  static const SHOWSTMT_NAMED_ARG args1[] = {
469  };
470  static const SHOWSTMT_NAMED_ARG args2[] = {
471  {NULL, AVT_IDENTIFIER, ARG_REQUIRED},
472  {NULL, AVT_IDENTIFIER, ARG_REQUIRED}
473  };
474 
475  static SHOWSTMT_METADATA md_all = {
476  SHOWSTMT_ALL_INDEXES_CAPACITY, true /* only_for_dba */ , "show all indexes capacity of ",
477  cols, DIM (cols), orderby, DIM (orderby), args1, DIM (args1), pt_check_show_index, NULL
478  };
479 
480  static SHOWSTMT_METADATA md_only = {
481  SHOWSTMT_INDEX_CAPACITY, true /* only_for_dba */ , "show index capacity of ",
482  cols, DIM (cols), NULL, 0, args2, DIM (args2), pt_check_show_index, NULL
483  };
484 
485  return (flag == SHOW_ALL) ? &md_all : &md_only;
486 }
487 
488 /* for show critical sections */
489 static SHOWSTMT_METADATA *
491 {
492  static const SHOWSTMT_COLUMN cols[] = {
493  {"Index", "int"},
494  {"Name", "varchar(32)"},
495  {"Num_holders", "varchar(16)"},
496  {"Num_waiting_readers", "int"},
497  {"Num_waiting_writers", "int"},
498  {"Owner_thread_index", "int"},
499  {"Owner_tran_index", "int"},
500  {"Total_enter_count", "bigint"},
501  {"Total_waiter_count", "bigint"},
502  {"Waiting_promoter_thread_index", "int"},
503  {"Max_waiting_msecs", "numeric(10,3)"},
504  {"Total_waiting_msecs", "numeric(10,3)"}
505  };
506 
507  static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
508  {1, ORDER_ASC}
509  };
510 
511  static SHOWSTMT_METADATA md = {
512  SHOWSTMT_GLOBAL_CRITICAL_SECTIONS, true /* only_for_dba */ , "show critical sections",
513  cols, DIM (cols), orderby, DIM (orderby), NULL, 0, NULL, NULL
514  };
515 
516  return &md;
517 }
518 
519 static SHOWSTMT_METADATA *
521 {
522  static const SHOWSTMT_COLUMN cols[] = {
523  {"Jobq_index", "int"},
524  {"Num_total_workers", "int"},
525  {"Num_busy_workers", "int"},
526  {"Num_connection_workers", "int"}
527  };
528 
529  static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
530  {1, ORDER_ASC}
531  };
532 
533  static SHOWSTMT_METADATA md = {
534  SHOWSTMT_JOB_QUEUES, true /* only_for_dba */ , "show job queue",
535  cols, DIM (cols), orderby, DIM (orderby), NULL, 0, NULL, NULL
536  };
537 
538  return &md;
539 }
540 
541 /* for show timezones */
542 static SHOWSTMT_METADATA *
544 {
545  static const SHOWSTMT_COLUMN cols[] = {
546  {"timezone_region", "varchar(32)"}
547  };
548 
549  static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
550  {1, ORDER_ASC}
551  };
552 
553  static SHOWSTMT_METADATA md = {
554  SHOWSTMT_TIMEZONES, false /* only_for_dba */ , "show timezones",
555  cols, DIM (cols), orderby, DIM (orderby), NULL, 0, NULL, NULL
556  };
557 
558  return &md;
559 }
560 
561 /* for show full timezones */
562 static SHOWSTMT_METADATA *
564 {
565  static const SHOWSTMT_COLUMN cols[] = {
566  {"timezone_region", "varchar(32)"},
567  {"region_offset", "varchar(32)"},
568  {"dst_offset", "varchar(32)"},
569  {"dst_abbreviation", "varchar(32)"}
570  };
571 
572  static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
573  {1, ORDER_ASC}
574  };
575 
576  static SHOWSTMT_METADATA md = {
577  SHOWSTMT_FULL_TIMEZONES, false /* only_for_dba */ , "show full timezones",
578  cols, DIM (cols), orderby, DIM (orderby), NULL, 0, NULL, NULL
579  };
580 
581  return &md;
582 }
583 
584 /* for show transaction descriptors */
585 static SHOWSTMT_METADATA *
587 {
588  static const SHOWSTMT_COLUMN cols[] = {
589  {"Tran_index", "int"},
590  {"Tran_id", "int"},
591  {"Is_loose_end", "int"},
592  {"State", "varchar(64)"},
593  {"Isolation", "varchar(64)"},
594  {"Wait_msecs", "int"},
595  {"Head_lsa", "varchar(64)"},
596  {"Tail_lsa", "varchar(64)"},
597  {"Undo_next_lsa", "varchar(64)"},
598  {"Postpone_next_lsa", "varchar(64)"},
599  {"Savepoint_lsa", "varchar(64)"},
600  {"Topop_lsa", "varchar(64)"},
601  {"Tail_top_result_lsa", "varchar(64)"},
602  {"Client_id", "int"},
603  {"Client_type", "varchar(40)"},
604  {"Client_info", "varchar(256)"},
605  {"Client_db_user", "varchar(40)"},
606  {"Client_program", "varchar(256)"},
607  {"Client_login_user", "varchar(16)"},
608  {"Client_host", "varchar(64)"},
609  {"Client_pid", "int"},
610  {"Topop_depth", "int"},
611  {"Num_unique_btrees", "int"},
612  {"Max_unique_btrees", "int"},
613  {"Interrupt", "int"},
614  {"Num_transient_classnames", "int"},
615  {"Repl_max_records", "int"},
616  {"Repl_records", "varchar(20)"},
617  {"Repl_current_index", "int"},
618  {"Repl_append_index", "int"},
619  {"Repl_flush_marked_index", "int"},
620  {"Repl_insert_lsa", "varchar(64)"},
621  {"Repl_update_lsa", "varchar(64)"},
622  {"First_save_entry", "varchar(20)"},
623  {"Tran_unique_stats", "varchar(20)"},
624  {"Modified_class_list", "varchar(20)"},
625  {"Num_temp_files", "int"},
626  {"Waiting_for_res", "varchar(20)"},
627  {"Has_deadlock_priority", "int"},
628  {"Suppress_replication", "int"},
629  {"Query_timeout", "datetime"},
630  {"Query_start_time", "datetime"},
631  {"Tran_start_time", "datetime"},
632  {"Xasl_id", "varchar(64)"},
633  {"Disable_modifications", "int"},
634  {"Abort_reason", "varchar(40)"}
635  };
636 
637  static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
638  {1, ORDER_ASC}
639  };
640 
641  static SHOWSTMT_METADATA md = {
642  SHOWSTMT_TRAN_TABLES, true /* only_for_dba */ , "show transaction tables",
643  cols, DIM (cols), orderby, DIM (orderby), NULL, 0, NULL, NULL
644  };
645 
646  return &md;
647 }
648 
649 static SHOWSTMT_METADATA *
651 {
652  static const SHOWSTMT_COLUMN cols[] = {
653  {"Index", "int"},
654  {"Jobq_index", "int"},
655  {"Thread_id", "bigint"},
656  {"Tran_index", "int"},
657  {"Type", "varchar(8)"},
658  {"Status", "varchar(8)"},
659  {"Resume_status", "varchar(32)"},
660  {"Net_request", "varchar(64)"},
661  {"Conn_client_id", "int"},
662  {"Conn_request_id", "int"},
663  {"Conn_index", "int"},
664  {"Last_error_code", "int"},
665  {"Last_error_msg", "varchar(256)"},
666  {"Private_heap_id", "varchar(20)"},
667  {"Query_entry", "varchar(20)"},
668  {"Interrupted", "int"},
669  {"Shutdown", "int"},
670  {"Check_interrupt", "int"},
671  {"Wait_for_latch_promote", "int"},
672  {"Lockwait_blocked_mode", "varchar(24)"},
673  {"Lockwait_start_time", "datetime"},
674  {"Lockwait_msecs", "int"},
675  {"Lockwait_state", "varchar(24)"},
676  {"Next_wait_thread_index", "int"},
677  {"Next_tran_wait_thread_index", "int"},
678  {"Next_worker_thread_index", "int"}
679  };
680 
681  static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
682  {1, ORDER_ASC}
683  };
684 
685  static SHOWSTMT_METADATA md = {
686  SHOWSTMT_THREADS, true /* only_for_dba */ , "show threads",
687  cols, DIM (cols), orderby, DIM (orderby), NULL, 0, NULL, NULL
688  };
689  return &md;
690 }
691 
692 static SHOWSTMT_METADATA *
694 {
695  static const SHOWSTMT_COLUMN cols[] = {
696  {"Hit_rate", "numeric(13,10)"},
697  {"Num_hit", "bigint"},
698  {"Num_page_request", "bigint"},
699  {"Pool_size", "int"},
700  {"Page_size", "int"},
701  {"Free_pages", "int"},
702  {"Victim_candidate_pages", "int"},
703  {"Clean_pages", "int"},
704  {"Dirty_pages", "int"},
705  {"Num_index_pages", "int"},
706  {"Num_data_pages", "int"},
707  {"Num_system_pages", "int"},
708  {"Num_temp_pages", "int"},
709  {"Num_pages_created", "bigint"},
710  {"Num_pages_written", "bigint"},
711  {"Pages_written_rate", "numeric(20,10)"},
712  {"Num_pages_read", "bigint"},
713  {"Pages_read_rate", "numeric(20,10)"},
714  {"Num_flusher_waiting_threads", "int"}
715  };
716 
717  static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
718  {1, ORDER_ASC}
719  };
720 
721  static SHOWSTMT_METADATA md = {
722  SHOWSTMT_PAGE_BUFFER_STATUS, true /* only_for_dba */ , "show page buffer status",
723  cols, DIM (cols), orderby, DIM (orderby), NULL, 0, NULL, NULL
724  };
725  return &md;
726 }
727 
728 /*
729  * showstmt_get_metadata() - return show statement column infos
730  * return:-
731  * show_type(in): SHOW statement type
732  */
733 const SHOWSTMT_METADATA *
735 {
736  const SHOWSTMT_METADATA *show_meta = NULL;
737 
738  assert_release (SHOWSTMT_START < show_type);
739  assert_release (show_type < SHOWSTMT_END);
740 
741  show_meta = show_Metas[show_type];
742  assert_release (show_meta != NULL);
743  assert_release (show_meta->show_type == show_type);
744  return show_meta;
745 }
746 
747 /*
748  * showstmt_get_attributes () - return all DB_ATTRIBUTE
749  * return:-
750  * show_type(in): SHOW statement type
751  */
752 DB_ATTRIBUTE *
754 {
755  const SHOWSTMT_METADATA *show_meta = NULL;
756 
757  show_meta = showstmt_get_metadata (show_type);
758 
759  return show_meta->showstmt_attrs;
760 }
761 
762 /*
763  * pt_check_show_heap () - check table exists or not
764  * return: PT_NODE pointer
765  *
766  * parser(in):
767  * node(in):
768  */
769 static PT_NODE *
771 {
772  int error = NO_ERROR;
773  PT_NODE *show_args_node = NULL, *spec, *derived_table;
774  PT_NODE *partition_node = NULL;
775  SHOWSTMT_TYPE show_type;
776  int partition_type = DB_NOT_PARTITIONED_CLASS;
777  const char *table_name = NULL;
778  MOP cls;
780  int save;
781 
782  if (node->node_type != PT_SELECT)
783  {
784  return node;
785  }
786 
787  spec = node->info.query.q.select.from;
788  assert (spec != NULL);
789 
790  derived_table = spec->info.spec.derived_table;
791  assert (derived_table != NULL);
792 
793  show_type = derived_table->info.showstmt.show_type;
794  assert (show_type == SHOWSTMT_HEAP_HEADER || show_type == SHOWSTMT_ALL_HEAP_HEADER
795  || show_type == SHOWSTMT_HEAP_CAPACITY || show_type == SHOWSTMT_ALL_HEAP_CAPACITY);
796 
797  show_args_node = derived_table->info.showstmt.show_args;
798  assert (show_args_node != NULL);
799 
800  assert (show_args_node->node_type == PT_VALUE);
801  assert (show_args_node->type_enum == PT_TYPE_CHAR);
802 
803  table_name = (const char *) show_args_node->info.value.data_value.str->bytes;
804 
805  cls = sm_find_class (table_name);
806  if (cls == NULL)
807  {
808  PT_ERRORmf (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_LC_UNKNOWN_CLASSNAME), table_name);
809  return node;
810  }
811 
812  AU_DISABLE (save);
813  error = au_fetch_class_force (cls, &sm_class, AU_FETCH_READ);
814  AU_ENABLE (save);
815  if (error == NO_ERROR)
816  {
817  if (sm_get_class_type (sm_class) != SM_CLASS_CT)
818  {
819  PT_ERRORm (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_OBJ_NOT_A_CLASS));
820  return node;
821  }
822  }
823 
824  error = sm_partitioned_class_type (cls, &partition_type, NULL, NULL);
825  if (error != NO_ERROR)
826  {
827  PT_ERRORc (parser, show_args_node, er_msg ());
828  return node;
829  }
830 
831  partition_node = pt_make_integer_value (parser, partition_type);
832  if (partition_node == NULL)
833  {
834  PT_INTERNAL_ERROR (parser, "allocate new node");
835  return node;
836  }
837 
838  parser_append_node (partition_node, show_args_node);
839 
840  return node;
841 }
842 
843 /*
844  * init_db_attribute_list () : init DB_ATTRIBUTE list for each show statement
845  * return: error code
846  * md(in/out):
847  */
848 static int
850 {
851  int i;
852  DB_DOMAIN *domain;
853  DB_ATTRIBUTE *attrs = NULL, *att;
854 
855  if (md == NULL)
856  {
857  return NO_ERROR;
858  }
859 
860  for (i = md->num_cols - 1; i >= 0; i--)
861  {
862  domain = pt_string_to_db_domain (md->cols[i].type, NULL);
863  if (domain == NULL)
864  {
865  goto on_error;
866  }
867  domain = tp_domain_cache (domain);
868 
869  att = classobj_make_attribute (md->cols[i].name, domain->type, ID_ATTRIBUTE);
870  if (att == NULL)
871  {
872  goto on_error;
873  }
874  att->domain = domain;
875  att->auto_increment = NULL;
876 
877  if (attrs == NULL)
878  {
879  attrs = att;
880  }
881  else
882  {
883  att->order_link = attrs;
884  attrs = att;
885  }
886  }
887 
888  md->showstmt_attrs = attrs;
889  return NO_ERROR;
890 
891 on_error:
892  while (attrs != NULL)
893  {
894  att = attrs;
895  attrs = (DB_ATTRIBUTE *) att->order_link;
896  att->order_link = NULL;
897 
899  }
900 
901  assert (er_errid () != NO_ERROR);
902  return er_errid ();
903 }
904 
905 /*
906  * free_db_attribute_list () : free DB_ATTRIBUTE list for each show statement
907  * return:
908  * md(in/out):
909  */
910 static void
912 {
913  DB_ATTRIBUTE *attrs = NULL, *att;
914 
915  if (md == NULL)
916  {
917  return;
918  }
919 
920  attrs = md->showstmt_attrs;
921  md->showstmt_attrs = NULL;
922  while (attrs != NULL)
923  {
924  att = attrs;
925  attrs = (DB_ATTRIBUTE *) att->order_link;
926  att->order_link = NULL;
927 
929  }
930 }
931 
932 /*
933  * showstmt_metadata_init() -- initialize the metadata of show statements
934  * return error code>
935  */
936 int
938 {
939  int error;
940  unsigned int i;
941 
942  if (show_Inited)
943  {
944  return NO_ERROR;
945  }
946 
947  memset (show_Metas, 0, sizeof (show_Metas));
948 
965  show_Metas[SHOWSTMT_TIMEZONES] = metadata_of_timezones ();
968  show_Metas[SHOWSTMT_THREADS] = metadata_of_threads ();
970 
971  for (i = 0; i < DIM (show_Metas); i++)
972  {
973  error = init_db_attribute_list (show_Metas[i]);
974  if (error != NO_ERROR)
975  {
976  goto on_error;
977  }
978  }
979  show_Inited = true;
980  return NO_ERROR;
981 
982 on_error:
983  for (i = 0; i < DIM (show_Metas); i++)
984  {
985  free_db_attribute_list (show_Metas[i]);
986  }
987  return error;
988 }
989 
990 /*
991  * showstmt_metadata_final() -- free the metadata of show statements
992  */
993 void
995 {
996  unsigned int i;
997 
998  if (!show_Inited)
999  {
1000  return;
1001  }
1002 
1003  for (i = 0; i < DIM (show_Metas); i++)
1004  {
1005  free_db_attribute_list (show_Metas[i]);
1006  }
1007  show_Inited = false;
1008 }
1009 
1010 static PT_NODE *
1012 {
1013  DB_VALUE oid_val;
1014  MOP classop;
1015  PT_NODE *entity = NULL;
1016  PT_NODE *derived_table = NULL;
1017  PT_NODE *arg = NULL;
1018 
1020  {
1021  PT_ERRORmf (parser, NULL, MSGCAT_SET_ERROR, -(ER_AU_DBA_ONLY), "show access status");
1022  return node;
1023  }
1024 
1025  entity = node->info.query.q.select.from;
1026  assert (entity != NULL);
1027 
1028  derived_table = entity->info.spec.derived_table;
1029  assert (derived_table != NULL);
1030 
1031  classop = sm_find_class ("db_user");
1032  if (classop == NULL)
1033  {
1034  assert (er_errid () != NO_ERROR);
1035  PT_ERRORc (parser, node, er_msg ());
1036  return node;
1037  }
1038 
1039  db_make_oid (&oid_val, &classop->oid_info.oid);
1040  arg = pt_dbval_to_value (parser, &oid_val);
1041 
1042  derived_table->info.showstmt.show_args = parser_append_node (arg, derived_table->info.showstmt.show_args);
1043 
1044  return node;
1045 }
1046 
1047 /*
1048  * pt_check_show_index () - semantic check for show index.
1049  * return:
1050  * parser(in):
1051  * node(in):
1052  */
1053 static PT_NODE *
1055 {
1056  PT_NODE *show_args_node = NULL;
1057  MOP cls;
1058  const char *table_name = NULL;
1059  const char *index_name = NULL;
1060  SM_CLASS *sm_class = NULL;
1061  SM_CLASS_CONSTRAINT *sm_all_constraints = NULL;
1063  PT_NODE *entity = NULL;
1064  PT_NODE *derived_table = NULL;
1065  SHOWSTMT_TYPE show_type;
1066  int error = NO_ERROR;
1067  int save;
1068  int partition_type = DB_NOT_PARTITIONED_CLASS;
1069  PT_NODE *partition_node = NULL;
1070 
1071  if (node->node_type != PT_SELECT)
1072  {
1073  return node;
1074  }
1075 
1076  entity = node->info.query.q.select.from;
1077  assert (entity != NULL);
1078 
1079  derived_table = entity->info.spec.derived_table;
1080  assert (derived_table != NULL);
1081 
1082  show_type = derived_table->info.showstmt.show_type;
1083  assert (show_type == SHOWSTMT_INDEX_HEADER || show_type == SHOWSTMT_INDEX_CAPACITY
1084  || show_type == SHOWSTMT_ALL_INDEXES_HEADER || show_type == SHOWSTMT_ALL_INDEXES_CAPACITY);
1085 
1086  show_args_node = derived_table->info.showstmt.show_args;
1087  assert (show_args_node != NULL);
1088 
1089  assert (show_args_node->node_type == PT_VALUE);
1090  assert (show_args_node->type_enum == PT_TYPE_CHAR);
1092 
1093  /* check table name */
1094  table_name = (const char *) show_args_node->info.value.data_value.str->bytes;
1095  cls = sm_find_class (table_name);
1096  if (cls == NULL)
1097  {
1098  PT_ERRORmf (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_LC_UNKNOWN_CLASSNAME), table_name);
1099  return node;
1100  }
1101 
1102  AU_DISABLE (save);
1103  error = au_fetch_class_force (cls, &sm_class, AU_FETCH_READ);
1104  AU_ENABLE (save);
1105  if (error == NO_ERROR)
1106  {
1107  if (sm_get_class_type (sm_class) != SM_CLASS_CT)
1108  {
1109  PT_ERRORm (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_OBJ_NOT_A_CLASS));
1110  return node;
1111  }
1112  }
1113 
1114  /* check index name */
1115  if (show_type == SHOWSTMT_INDEX_HEADER || show_type == SHOWSTMT_INDEX_CAPACITY)
1116  {
1117  show_args_node = show_args_node->next;
1118  assert (show_args_node != NULL);
1119  assert (show_args_node->node_type == PT_VALUE);
1120  assert (show_args_node->type_enum == PT_TYPE_CHAR);
1122 
1123  index_name = (const char *) show_args_node->info.value.data_value.str->bytes;
1124  sm_all_constraints = sm_class_constraints (cls);
1125  sm_constraint = classobj_find_constraint_by_name (sm_all_constraints, index_name);
1126  if (sm_all_constraints == NULL || sm_constraint == NULL)
1127  {
1128  PT_ERRORmf (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_SM_NO_INDEX), index_name);
1129  return node;
1130  }
1131  }
1132 
1133  /* get partition type and pass it by args */
1134  error = sm_partitioned_class_type (cls, &partition_type, NULL, NULL);
1135  if (error != NO_ERROR)
1136  {
1137  PT_ERRORc (parser, show_args_node, er_msg ());
1138  return node;
1139  }
1140 
1141  partition_node = pt_make_integer_value (parser, partition_type);
1142  if (partition_node == NULL)
1143  {
1144  PT_INTERNAL_ERROR (parser, "allocate new node");
1145  return node;
1146  }
1147  parser_append_node (partition_node, show_args_node);
1148 
1149  return node;
1150 }
const SHOWSTMT_METADATA * showstmt_get_metadata(SHOWSTMT_TYPE show_type)
Definition: show_meta.c:734
PT_NODE * next
Definition: parse_tree.h:3447
static int init_db_attribute_list(SHOWSTMT_METADATA *md)
Definition: show_meta.c:849
#define NO_ERROR
Definition: error_code.h:46
#define AU_DISABLE(save)
Definition: authenticate.h:106
static SHOWSTMT_METADATA * metadata_of_active_log_header(void)
Definition: show_meta.c:131
PT_STATEMENT_INFO info
Definition: parse_tree.h:3487
#define PT_ERRORm(parser, node, setNo, msgNo)
Definition: parse_tree.h:63
PT_NODE * show_args
Definition: parse_tree.h:2816
static SHOWSTMT_METADATA * metadata_of_threads(void)
Definition: show_meta.c:650
static SHOWSTMT_METADATA * metadata_of_index_capacity(SHOW_ONLY_ALL flag)
Definition: show_meta.c:440
int showstmt_metadata_init(void)
Definition: show_meta.c:937
static SHOWSTMT_METADATA * metadata_of_global_critical_sections(void)
Definition: show_meta.c:490
PT_SPEC_INFO spec
Definition: parse_tree.h:3346
static SHOWSTMT_METADATA * metadata_of_heap_capacity(SHOW_ONLY_ALL flag)
Definition: show_meta.c:346
const char * type
Definition: show_meta.h:38
SHOWSTMT_TYPE show_type
Definition: show_meta.h:68
#define assert_release(e)
Definition: error_manager.h:96
static PT_NODE * pt_check_table_in_show_heap(PARSER_CONTEXT *parser, PT_NODE *node)
Definition: show_meta.c:770
static SHOWSTMT_METADATA * metadata_of_page_buffer_status(void)
Definition: show_meta.c:693
SM_CLASS_TYPE sm_get_class_type(SM_CLASS *class_)
bool au_is_dba_group_member(MOP user)
static SHOWSTMT_METADATA * metadata_of_tran_tables(void)
Definition: show_meta.c:586
SM_CLASS_CONSTRAINT * classobj_find_constraint_by_name(SM_CLASS_CONSTRAINT *cons_list, const char *name)
union pt_query_info::@124 q
int er_errid(void)
SHOWSTMT_TYPE show_type
Definition: parse_tree.h:2815
static SHOWSTMT_METADATA * metadata_of_full_timezones(void)
Definition: show_meta.c:563
SHOWSTMT_TYPE
static SHOWSTMT_METADATA * show_Metas[SHOWSTMT_END]
Definition: show_meta.c:63
DB_ATTRIBUTE * showstmt_get_attributes(SHOWSTMT_TYPE show_type)
Definition: show_meta.c:753
SM_CLASS_CONSTRAINT * sm_class_constraints(MOP classop)
PT_TYPE_ENUM type_enum
Definition: parse_tree.h:3457
static PT_NODE * pt_check_access_status(PARSER_CONTEXT *parser, PT_NODE *node)
Definition: show_meta.c:1011
unsigned char bytes[1]
Definition: parse_tree.h:3431
DB_ATTRIBUTE * showstmt_attrs
Definition: show_meta.h:78
static PT_NODE * pt_check_show_index(PARSER_CONTEXT *parser, PT_NODE *node)
Definition: show_meta.c:1054
#define assert(x)
#define ER_SM_NO_INDEX
Definition: error_code.h:345
#define ER_LC_UNKNOWN_CLASSNAME
Definition: error_code.h:121
PT_DATA_VALUE data_value
Definition: parse_tree.h:3058
#define DB_MAX_IDENTIFIER_LENGTH
Definition: dbtype_def.h:495
PT_NODE_TYPE node_type
Definition: parse_tree.h:3439
static SHOWSTMT_METADATA * metadata_of_timezones(void)
Definition: show_meta.c:543
PT_SHOWSTMT_INFO showstmt
Definition: parse_tree.h:3342
PT_NODE * from
Definition: parse_tree.h:2686
VID_OID oid_info
Definition: work_space.h:120
void classobj_free_attribute(SM_ATTRIBUTE *att)
PARSER_VARCHAR * str
Definition: parse_tree.h:3036
SP_PARSER_CTX * parser
#define NULL
Definition: freelistheap.h:34
OID oid
Definition: work_space.h:65
const char * name
Definition: show_meta.h:37
const char * er_msg(void)
struct pr_type * type
Definition: object_domain.h:76
static SHOWSTMT_METADATA * metadata_of_heap_header(SHOW_ONLY_ALL flag)
Definition: show_meta.c:297
TP_DOMAIN * tp_domain_cache(TP_DOMAIN *transient)
#define PT_ERRORc(parser, node, msg)
Definition: parse_tree.h:55
SM_ATTRIBUTE * classobj_make_attribute(const char *name, struct pr_type *type, SM_NAME_SPACE name_space)
PT_QUERY_INFO query
Definition: parse_tree.h:3325
static SHOWSTMT_METADATA * metadata_of_volume_header(void)
Definition: show_meta.c:93
DB_DOMAIN * pt_string_to_db_domain(const char *s, const char *class_name)
Definition: parse_dbi.c:1332
static SHOWSTMT_METADATA * metadata_of_archive_log_header(void)
Definition: show_meta.c:188
static SHOWSTMT_METADATA * metadata_of_slotted_page_header(void)
Definition: show_meta.c:214
PT_NODE * pt_make_integer_value(PARSER_CONTEXT *parser, const int value_int)
PT_NODE * parser_append_node(PT_NODE *node, PT_NODE *list)
MOP Au_user
Definition: authenticate.c:343
static void error(const char *msg)
Definition: gencat.c:331
void showstmt_metadata_final(void)
Definition: show_meta.c:994
static void free_db_attribute_list(SHOWSTMT_METADATA *md)
Definition: show_meta.c:911
static SHOWSTMT_METADATA * metadata_of_job_queues(void)
Definition: show_meta.c:520
#define MSGCAT_SET_ERROR
#define ER_AU_DBA_ONLY
Definition: error_code.h:204
int sm_partitioned_class_type(DB_OBJECT *classop, int *partition_type, char *keyattr, MOP **partitions)
static SHOWSTMT_METADATA * metadata_of_slotted_page_slots(void)
Definition: show_meta.c:245
#define AU_ENABLE(save)
Definition: authenticate.h:113
static SHOWSTMT_METADATA * metadata_of_index_header(SHOW_ONLY_ALL flag)
Definition: show_meta.c:394
static bool show_Inited
Definition: show_meta.c:62
int i
Definition: dynamic_load.c:954
PT_VALUE_INFO value
Definition: parse_tree.h:3358
static WHEN_DESC on_error
static SHOWSTMT_METADATA * metadata_of_access_status(void)
Definition: show_meta.c:275
struct sm_attribute * order_link
Definition: class_object.h:461
SHOW_ONLY_ALL
Definition: show_meta.c:56
#define PT_INTERNAL_ERROR(parser, what)
Definition: parse_tree.h:112
int db_make_oid(DB_VALUE *value, const OID *oid)
MOP sm_find_class(const char *name)
PT_NODE * pt_dbval_to_value(PARSER_CONTEXT *parser, const DB_VALUE *val)
Definition: parse_dbi.c:574
PT_SELECT_INFO select
Definition: parse_tree.h:2781
const SHOWSTMT_COLUMN * cols
Definition: show_meta.h:71
#define ER_OBJ_NOT_A_CLASS
Definition: error_code.h:288
int au_fetch_class_force(MOP op, SM_CLASS **class_, AU_FETCHMODE fetchmode)
#define PT_ERRORmf(parser, node, setNo, msgNo, arg1)
Definition: parse_tree.h:64
PT_NODE * derived_table
Definition: parse_tree.h:2134