21 #include "my_global.h"
22 #include "my_pthread.h"
42 #include "table_threads.h"
66 #include "table_users.h"
67 #include "table_accounts.h"
68 #include "table_hosts.h"
73 #include "table_session_connect_attrs.h"
74 #include "table_session_account_connect_attrs.h"
162 DBUG_EXECUTE_IF(
"tampered_perfschema_table1",
168 for (current= &all_shares[0]; (*current) != NULL; current++)
169 (*current)->check_one_table(thd);
176 virtual void report_error(uint
code,
const char *
fmt, ...);
186 void PFS_check_intact::report_error(uint
code,
const char *
fmt, ...)
189 char buff[MYSQL_ERRMSG_SIZE];
192 my_vsnprintf(buff,
sizeof(buff), fmt, args);
200 sql_print_error(
"%s", buff);
219 LEX *old_lex= thd->lex;
220 thd->lex= &dummy_lex;
229 close_thread_tables(thd);
232 sql_print_error(ER(ER_WRONG_NATIVE_TABLE_STRUCTURE),
244 for (current= &all_shares[0]; (*current) != NULL; current++)
245 thr_lock_init((*current)->m_thr_lock_ptr);
253 for (current= &all_shares[0]; (*current) != NULL; current++)
254 thr_lock_delete((*current)->m_thr_lock_ptr);
267 Field **fields)
const
269 my_bitmap_map *org_bitmap;
277 return HA_ERR_TABLE_NEEDS_UPGRADE;
282 return HA_ERR_WRONG_COMMAND;
286 org_bitmap= dbug_tmp_use_all_columns(table, table->read_set);
288 dbug_tmp_restore_column_map(table->read_set, org_bitmap);
293 static int compare_table_names(
const char *name1,
const char *name2)
309 if (lower_case_table_names)
310 return strcasecmp(name1, name2);
311 return strcmp(name1, name2);
322 DBUG_ENTER(
"PFS_engine_table::find_table_share");
326 for (current= &all_shares[0]; (*current) != NULL; current++)
328 if (compare_table_names(name, (*current)->m_name.str) == 0)
329 DBUG_RETURN(*current);
346 my_bitmap_map *org_bitmap;
348 Field **fields_reset;
356 return HA_ERR_TABLE_NEEDS_UPGRADE;
360 bool read_all= !bitmap_is_clear_all(table->write_set);
363 org_bitmap= dbug_tmp_use_all_columns(table, table->write_set);
371 for (fields_reset= fields; (f= *fields_reset) ; fields_reset++)
375 dbug_tmp_restore_column_map(table->write_set, org_bitmap);
389 const unsigned char *old_buf,
390 unsigned char *new_buf,
393 my_bitmap_map *org_bitmap;
401 return HA_ERR_TABLE_NEEDS_UPGRADE;
405 org_bitmap= dbug_tmp_use_all_columns(table, table->read_set);
407 dbug_tmp_restore_column_map(table->read_set, org_bitmap);
413 const unsigned char *
buf,
416 my_bitmap_map *org_bitmap;
424 return HA_ERR_TABLE_NEEDS_UPGRADE;
428 org_bitmap= dbug_tmp_use_all_columns(table, table->read_set);
430 dbug_tmp_restore_column_map(table->read_set, org_bitmap);
436 const unsigned char *,
439 return HA_ERR_WRONG_COMMAND;
475 DBUG_ASSERT(f->real_type() == MYSQL_TYPE_LONG);
477 f2->store(value,
true);
482 DBUG_ASSERT(f->real_type() == MYSQL_TYPE_LONGLONG);
483 Field_longlong *f2= (Field_longlong*) f;
484 f2->store(value,
true);
490 DBUG_ASSERT(f->real_type() == MYSQL_TYPE_STRING);
492 f2->store(str, len, &my_charset_utf8_bin);
498 DBUG_ASSERT(f->real_type() == MYSQL_TYPE_VARCHAR);
500 f2->store(str, len, &my_charset_utf8_bin);
506 DBUG_ASSERT(f->real_type() == MYSQL_TYPE_BLOB);
508 f2->store(str, len, &my_charset_utf8_bin);
513 DBUG_ASSERT(f->real_type() == MYSQL_TYPE_ENUM);
515 f2->store_type(value);
521 tm.tv_sec= (long)(value / 1000000);
522 tm.tv_usec= (long)(value % 1000000);
523 DBUG_ASSERT(f->real_type() == MYSQL_TYPE_TIMESTAMP2);
530 DBUG_ASSERT(f->real_type() == MYSQL_TYPE_ENUM);
532 return f2->val_int();
538 DBUG_ASSERT(f->real_type() == MYSQL_TYPE_STRING);
540 val= f2->val_str(NULL, val);
547 DBUG_ASSERT(f->real_type() == MYSQL_TYPE_VARCHAR);
549 val= f2->val_str(NULL, val);
554 const unsigned char *,
558 return HA_ERR_WRONG_COMMAND;
571 ACL_internal_access_result
check(ulong want_access,
572 ulong *save_priv)
const;
577 ACL_internal_access_result
579 ulong *save_priv)
const
581 const ulong always_forbidden= REFERENCES_ACL
582 | INDEX_ACL | ALTER_ACL | CREATE_TMP_ACL | EXECUTE_ACL
583 | CREATE_VIEW_ACL | SHOW_VIEW_ACL | CREATE_PROC_ACL | ALTER_PROC_ACL
584 | EVENT_ACL | TRIGGER_ACL ;
586 if (unlikely(want_access & always_forbidden))
587 return ACL_INTERNAL_ACCESS_DENIED;
593 return ACL_INTERNAL_ACCESS_CHECK_GRANT;
624 &pfs_internal_access);
630 ACL_internal_access_result
633 const ulong always_forbidden= INSERT_ACL | UPDATE_ACL | DELETE_ACL
634 | REFERENCES_ACL | INDEX_ACL | ALTER_ACL
635 | CREATE_VIEW_ACL | SHOW_VIEW_ACL | TRIGGER_ACL | LOCK_TABLES_ACL;
637 if (unlikely(want_access & always_forbidden))
638 return ACL_INTERNAL_ACCESS_DENIED;
640 return ACL_INTERNAL_ACCESS_CHECK_GRANT;
645 ACL_internal_access_result
648 const ulong always_forbidden= INSERT_ACL | UPDATE_ACL | DELETE_ACL
649 | REFERENCES_ACL | INDEX_ACL | ALTER_ACL
650 | CREATE_VIEW_ACL | SHOW_VIEW_ACL | TRIGGER_ACL | LOCK_TABLES_ACL;
652 if (unlikely(want_access & always_forbidden))
653 return ACL_INTERNAL_ACCESS_DENIED;
655 return ACL_INTERNAL_ACCESS_CHECK_GRANT;
660 ACL_internal_access_result
663 const ulong always_forbidden= INSERT_ACL | DELETE_ACL
664 | REFERENCES_ACL | INDEX_ACL | ALTER_ACL
665 | CREATE_VIEW_ACL | SHOW_VIEW_ACL | TRIGGER_ACL;
667 if (unlikely(want_access & always_forbidden))
668 return ACL_INTERNAL_ACCESS_DENIED;
670 return ACL_INTERNAL_ACCESS_CHECK_GRANT;
675 ACL_internal_access_result
678 const ulong always_forbidden= REFERENCES_ACL
679 | INDEX_ACL | ALTER_ACL | CREATE_VIEW_ACL | SHOW_VIEW_ACL | TRIGGER_ACL;
681 if (unlikely(want_access & always_forbidden))
682 return ACL_INTERNAL_ACCESS_DENIED;
684 return ACL_INTERNAL_ACCESS_CHECK_GRANT;
689 ACL_internal_access_result
692 const ulong always_forbidden= CREATE_ACL
693 | REFERENCES_ACL | INDEX_ACL | ALTER_ACL
694 | CREATE_VIEW_ACL | TRIGGER_ACL;
696 if (unlikely(want_access & always_forbidden))
697 return ACL_INTERNAL_ACCESS_DENIED;
709 return ACL_INTERNAL_ACCESS_CHECK_GRANT;
720 stat_print_fn *print,
enum ha_stat_type stat)
728 DBUG_ENTER(
"pfs_show_status");
737 if (stat != HA_ENGINE_STATUS)
740 size_t total_memory= 0;
746 name=
"events_waits_current.row_size";
750 name=
"events_waits_current.row_count";
754 name=
"events_waits_history.row_size";
758 name=
"events_waits_history.row_count";
762 name=
"events_waits_history.memory";
768 name=
"events_waits_history_long.row_size";
772 name=
"events_waits_history_long.row_count";
773 size= events_waits_history_long_size;
776 name=
"events_waits_history_long.memory";
781 name=
"(pfs_mutex_class).row_size";
785 name=
"(pfs_mutex_class).row_count";
789 name=
"(pfs_mutex_class).memory";
794 name=
"(pfs_rwlock_class).row_size";
798 name=
"(pfs_rwlock_class).row_count";
802 name=
"(pfs_rwlock_class).memory";
807 name=
"(pfs_cond_class).row_size";
811 name=
"(pfs_cond_class).row_count";
815 name=
"(pfs_cond_class).memory";
820 name=
"(pfs_thread_class).row_size";
824 name=
"(pfs_thread_class).row_count";
828 name=
"(pfs_thread_class).memory";
833 name=
"(pfs_file_class).row_size";
837 name=
"(pfs_file_class).row_count";
841 name=
"(pfs_file_class).memory";
846 name=
"mutex_instances.row_size";
850 name=
"mutex_instances.row_count";
854 name=
"mutex_instances.memory";
859 name=
"rwlock_instances.row_size";
863 name=
"rwlock_instances.row_count";
867 name=
"rwlock_instances.memory";
872 name=
"cond_instances.row_size";
876 name=
"cond_instances.row_count";
880 name=
"cond_instances.memory";
885 name=
"threads.row_size";
889 name=
"threads.row_count";
893 name=
"threads.memory";
898 name=
"file_instances.row_size";
902 name=
"file_instances.row_count";
906 name=
"file_instances.memory";
911 name=
"(pfs_file_handle).row_size";
915 name=
"(pfs_file_handle).row_count";
919 name=
"(pfs_file_handle).memory";
924 name=
"events_waits_summary_by_thread_by_event_name.row_size";
928 name=
"events_waits_summary_by_thread_by_event_name.row_count";
929 size= thread_max * wait_class_max;
932 name=
"events_waits_summary_by_thread_by_event_name.memory";
937 name=
"(pfs_table_share).row_size";
941 name=
"(pfs_table_share).row_count";
945 name=
"(pfs_table_share).memory";
950 name=
"(pfs_table).row_size";
954 name=
"(pfs_table).row_count";
958 name=
"(pfs_table).memory";
963 name=
"setup_actors.row_size";
967 name=
"setup_actors.row_count";
971 name=
"setup_actors.memory";
976 name=
"setup_objects.row_size";
980 name=
"setup_objects.row_count";
981 size= setup_object_max;
984 name=
"setup_objects.memory";
989 name=
"(pfs_account).row_size";
993 name=
"(pfs_account).row_count";
997 name=
"(pfs_account).memory";
1002 name=
"events_waits_summary_by_account_by_event_name.row_size";
1006 name=
"events_waits_summary_by_account_by_event_name.row_count";
1007 size= account_max * wait_class_max;
1010 name=
"events_waits_summary_by_account_by_event_name.memory";
1012 total_memory+=
size;
1015 name=
"events_waits_summary_by_user_by_event_name.row_size";
1019 name=
"events_waits_summary_by_user_by_event_name.row_count";
1020 size= user_max * wait_class_max;
1023 name=
"events_waits_summary_by_user_by_event_name.memory";
1025 total_memory+=
size;
1028 name=
"events_waits_summary_by_host_by_event_name.row_size";
1032 name=
"events_waits_summary_by_host_by_event_name.row_count";
1033 size= host_max * wait_class_max;
1036 name=
"events_waits_summary_by_host_by_event_name.memory";
1038 total_memory+=
size;
1041 name=
"(pfs_user).row_size";
1045 name=
"(pfs_user).row_count";
1049 name=
"(pfs_user).memory";
1051 total_memory+=
size;
1054 name=
"(pfs_host).row_size";
1058 name=
"(pfs_host).row_count";
1062 name=
"(pfs_host).memory";
1064 total_memory+=
size;
1067 name=
"(pfs_stage_class).row_size";
1071 name=
"(pfs_stage_class).row_count";
1075 name=
"(pfs_stage_class).memory";
1077 total_memory+=
size;
1080 name=
"events_stages_history.row_size";
1084 name=
"events_stages_history.row_count";
1088 name=
"events_stages_history.memory";
1091 total_memory+=
size;
1094 name=
"events_stages_history_long.row_size";
1098 name=
"events_stages_history_long.row_count";
1099 size= events_stages_history_long_size;
1102 name=
"events_stages_history_long.memory";
1104 total_memory+=
size;
1107 name=
"events_stages_summary_by_thread_by_event_name.row_size";
1111 name=
"events_stages_summary_by_thread_by_event_name.row_count";
1115 name=
"events_stages_summary_by_thread_by_event_name.memory";
1117 total_memory+=
size;
1120 name=
"events_stages_summary_global_by_event_name.row_size";
1124 name=
"events_stages_summary_global_by_event_name.row_count";
1128 name=
"events_stages_summary_global_by_event_name.memory";
1130 total_memory+=
size;
1133 name=
"events_stages_summary_by_account_by_event_name.row_size";
1137 name=
"events_stages_summary_by_account_by_event_name.row_count";
1141 name=
"events_stages_summary_by_account_by_event_name.memory";
1143 total_memory+=
size;
1146 name=
"events_stages_summary_by_user_by_event_name.row_size";
1150 name=
"events_stages_summary_by_user_by_event_name.row_count";
1154 name=
"events_stages_summary_by_user_by_event_name.memory";
1156 total_memory+=
size;
1159 name=
"events_stages_summary_by_host_by_event_name.row_size";
1163 name=
"events_stages_summary_by_host_by_event_name.row_count";
1167 name=
"events_stages_summary_by_host_by_event_name.memory";
1169 total_memory+=
size;
1172 name=
"(pfs_statement_class).row_size";
1176 name=
"(pfs_statement_class).row_count";
1180 name=
"(pfs_statement_class).memory";
1182 total_memory+=
size;
1185 name=
"events_statements_history.row_size";
1189 name=
"events_statements_history.row_count";
1193 name=
"events_statements_history.memory";
1196 total_memory+=
size;
1199 name=
"events_statements_history_long.row_size";
1203 name=
"events_statements_history_long.row_count";
1204 size= events_statements_history_long_size;
1207 name=
"events_statements_history_long.memory";
1209 total_memory+=
size;
1212 name=
"events_statements_summary_by_thread_by_event_name.row_size";
1216 name=
"events_statements_summary_by_thread_by_event_name.row_count";
1220 name=
"events_statements_summary_by_thread_by_event_name.memory";
1222 total_memory+=
size;
1225 name=
"events_statements_summary_global_by_event_name.row_size";
1229 name=
"events_statements_summary_global_by_event_name.row_count";
1233 name=
"events_statements_summary_global_by_event_name.memory";
1235 total_memory+=
size;
1238 name=
"events_statements_summary_by_account_by_event_name.row_size";
1242 name=
"events_statements_summary_by_account_by_event_name.row_count";
1246 name=
"events_statements_summary_by_account_by_event_name.memory";
1248 total_memory+=
size;
1251 name=
"events_statements_summary_by_user_by_event_name.row_size";
1255 name=
"events_statements_summary_by_user_by_event_name.row_count";
1259 name=
"events_statements_summary_by_user_by_event_name.memory";
1261 total_memory+=
size;
1264 name=
"events_statements_summary_by_host_by_event_name.row_size";
1268 name=
"events_statements_summary_by_host_by_event_name.row_count";
1272 name=
"events_statements_summary_by_host_by_event_name.memory";
1274 total_memory+=
size;
1277 name=
"events_statements_current.row_size";
1281 name=
"events_statements_current.row_count";
1285 name=
"events_statements_current.memory";
1287 total_memory+=
size;
1290 name=
"(pfs_socket_class).row_size";
1294 name=
"(pfs_socket_class).row_count";
1298 name=
"(pfs_socket_class).memory";
1300 total_memory+=
size;
1303 name=
"socket_instances.row_size";
1307 name=
"socket_instances.row_count";
1311 name=
"socket_instances.memory";
1313 total_memory+=
size;
1316 name=
"events_statements_summary_by_digest.row_size";
1320 name=
"events_statements_summary_by_digest.row_count";
1324 name=
"events_statements_summary_by_digest.memory";
1326 total_memory+=
size;
1329 name=
"session_connect_attrs.row_size";
1333 name=
"session_connect_attrs.row_count";
1337 name=
"session_connect_attrs.memory";
1339 total_memory+=
size;
1343 name=
"(account_hash).count";
1344 size= account_hash.count;
1347 name=
"(account_hash).size";
1348 size= account_hash.size;
1351 name=
"(digest_hash).count";
1352 size= digest_hash.count;
1355 name=
"(digest_hash).size";
1356 size= digest_hash.size;
1359 name=
"(filename_hash).count";
1363 name=
"(filename_hash).size";
1367 name=
"(host_hash).count";
1368 size= host_hash.count;
1371 name=
"(host_hash).size";
1372 size= host_hash.size;
1375 name=
"(setup_actor_hash).count";
1379 name=
"(setup_actor_hash).size";
1383 name=
"(setup_object_hash).count";
1384 size= setup_object_hash.count;
1387 name=
"(setup_object_hash).size";
1388 size= setup_object_hash.size;
1391 name=
"(table_share_hash).count";
1395 name=
"(table_share_hash).size";
1399 name=
"(user_hash).count";
1400 size= user_hash.count;
1403 name=
"(user_hash).size";
1404 size= user_hash.size;
1415 name=
"host_cache.size";
1424 name=
"performance_schema.memory";
1434 buflen= longlong10_to_str(size, buf, 10) -
buf;