1 /* Copyright (c) 2013, 2021, Oracle and/or its affiliates.
2 
3   This program is free software; you can redistribute it and/or modify
4   it under the terms of the GNU General Public License, version 2.0,
5   as published by the Free Software Foundation.
6 
7   This program is also distributed with certain software (including
8   but not limited to OpenSSL) that is licensed under separate terms,
9   as designated in a particular file or component or in included license
10   documentation.  The authors of MySQL hereby grant you an additional
11   permission to link the program and your derivative works with the
12   separately licensed software that they have included with MySQL.
13 
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License, version 2.0, for more details.
18 
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software Foundation,
21   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef PFS_PROGRAM_H
24 #define PFS_PROGRAM_H
25 
26 /**
27   @file storage/perfschema/pfs_program.h
28   Stored Program data structures (declarations).
29 */
30 
31 #include "pfs_column_types.h"
32 #include "pfs_stat.h"
33 
34 #define PROGRAM_HASH_KEY_LENGTH sizeof(enum_object_type) + COL_OBJECT_NAME_SIZE + 1 + COL_OBJECT_SCHEMA_SIZE + 1
35 
36 extern LF_HASH program_hash;
37 
38 /**
39   Hash key for a program.
40 */
41 struct PFS_program_key
42 {
43   /**
44     Hash search key.
45     This has to be a string for LF_HASH,
46     the format is "<object_type><0x00><object_name><0x00><schema_name><0x00>"
47   */
48   char m_hash_key[PROGRAM_HASH_KEY_LENGTH];
49   uint m_key_length;
50 };
51 
52 struct PFS_ALIGNED PFS_program : public PFS_instr
53 {
54   /** Object type. */
55   enum_object_type m_type;
56 
57   /** Object name. */
58   const char *m_object_name;
59   int m_object_name_length;
60 
61   /** Object Schema name. */
62   const char *m_schema_name;
63   int m_schema_name_length;
64 
65   /** Hash key */
66   PFS_program_key m_key;
67 
68   /** Sub statement stat. */
69   PFS_statement_stat m_stmt_stat;
70 
71   /** Stored program stat. */
72   PFS_sp_stat m_sp_stat;
73 
74   /** Referesh setup object flags. */
75   void refresh_setup_object_flags(PFS_thread* thread);
76 
77   /** Reset data for this record. */
78   void reset_data();
79 };
80 
81 int init_program(const PFS_global_param *param);
82 void cleanup_program(void);
83 int init_program_hash(const PFS_global_param *param);
84 void cleanup_program_hash(void);
85 
86 void reset_esms_by_program();
87 
88 PFS_program*
89 find_or_create_program(PFS_thread *thread,
90                       enum_object_type object_type,
91                       const char *object_name,
92                       uint object_name_length,
93                       const char *schema,
94                       uint schema_length);
95 
96 void
97 drop_program(PFS_thread *thread,
98              enum_object_type object_type,
99              const char *object_name,
100              uint object_name_length,
101              const char *schema_name,
102              uint schema_name_length);
103 #endif
104