| 972 | } |
| 973 | |
| 974 | void ProfilerPlugin::createMetadata(ThrowStatusExceptionWrapper* status, RefPtr<IAttachment> attachment, |
| 975 | RefPtr<ITransaction> transaction) |
| 976 | { |
| 977 | constexpr const char* createSqlStaments[] = { |
| 978 | "create role plg$profiler", |
| 979 | |
| 980 | "grant default plg$profiler to public", |
| 981 | |
| 982 | "create sequence plg$prof_profile_id", |
| 983 | |
| 984 | "grant usage on sequence plg$prof_profile_id to plg$profiler", |
| 985 | |
| 986 | R"""( |
| 987 | create table plg$prof_sessions ( |
| 988 | profile_id bigint not null |
| 989 | constraint plg$prof_sessions_pk |
| 990 | primary key |
| 991 | using index plg$prof_sessions_profile, |
| 992 | attachment_id bigint not null, |
| 993 | user_name char(63) character set utf8 not null, |
| 994 | description varchar(255) character set utf8, |
| 995 | start_timestamp timestamp with time zone not null, |
| 996 | finish_timestamp timestamp with time zone |
| 997 | ))""", |
| 998 | |
| 999 | "grant select, update, insert, delete on table plg$prof_sessions to plg$profiler", |
| 1000 | |
| 1001 | R"""( |
| 1002 | create table plg$prof_statements ( |
| 1003 | profile_id bigint not null |
| 1004 | constraint plg$prof_statements_session_fk |
| 1005 | references plg$prof_sessions |
| 1006 | on delete cascade |
| 1007 | using index plg$prof_statements_profile, |
| 1008 | statement_id bigint not null, |
| 1009 | parent_statement_id bigint, |
| 1010 | statement_type varchar(20) character set utf8 not null, |
| 1011 | package_name char(63) character set utf8, |
| 1012 | routine_name char(63) character set utf8, |
| 1013 | sql_text blob sub_type text character set utf8, |
| 1014 | constraint plg$prof_statements_pk |
| 1015 | primary key (profile_id, statement_id) |
| 1016 | using index plg$prof_statements_profile_statement, |
| 1017 | constraint plg$prof_statements_parent_statement_fk |
| 1018 | foreign key (profile_id, parent_statement_id) references plg$prof_statements (profile_id, statement_id) |
| 1019 | on delete cascade |
| 1020 | using index plg$prof_statements_parent_statement |
| 1021 | ))""", |
| 1022 | |
| 1023 | "grant select, update, insert, delete on table plg$prof_statements to plg$profiler", |
| 1024 | |
| 1025 | R"""( |
| 1026 | create table plg$prof_cursors ( |
| 1027 | profile_id bigint not null |
| 1028 | constraint plg$prof_cursors_session_fk |
| 1029 | references plg$prof_sessions |
| 1030 | on delete cascade |
| 1031 | using index plg$prof_cursors_profile, |