You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This patch adds a new and optional configuration option, database_type,
to the set of options available in the scheduler's config. Valid values
are "mysql" and "postgresql", and if the option is omitted, "mysql" as
treated as the default.
Note that this patch does not yet introduce PostgreSQL support, but
provides the initial restructuring of the scheduler.
Abstract usage of an SQL connection into a new module, sql_connection,
and a new enum representing a connection, SQLConnection, which
represents either a MySQL or a PostgreSQL connection. Also replace all
uses of mysql::Conn with the new SQLConnection enum, which acts as a
thin wrapper.
"SELECT digest FROM mysql_query_rules WHERE comment LIKE '{MIRROR_QUERY_TOKEN}%' OR comment LIKE '{DESTINATION_QUERY_TOKEN}%'"
143
167
))
144
168
.expect("Failed to find queries routed to Readyset");
@@ -155,7 +179,10 @@ impl ProxySQL {
155
179
let datetime_now:DateTime<Local> = Local::now();
156
180
let tz = datetime_now.format("%z").to_string();
157
181
let date_formatted = datetime_now.format("%Y-%m-%d %H:%M:%S");
158
-
let rows:Vec<(u16,String)> = self.conn.query(format!("SELECT rule_id, comment FROM mysql_query_rules WHERE comment LIKE '{MIRROR_QUERY_TOKEN}: ____-__-__ __:__:__';")).expect("Failed to select mirror rules");
182
+
ifself.database_type == DatabaseType::PostgreSQL{
183
+
todo!("PostgreSQL ProxySQL query rule updating");
184
+
}
185
+
let rows:Vec<(u16,String)> = self.conn.query(&format!("SELECT rule_id, comment FROM mysql_query_rules WHERE comment LIKE '{MIRROR_QUERY_TOKEN}: ____-__-__ __:__:__';")).expect("Failed to select mirror rules");
159
186
for(rule_id, comment)in rows {
160
187
let datetime_mirror_str = comment
161
188
.split(&format!("{MIRROR_QUERY_TOKEN}:"))
@@ -173,7 +200,7 @@ impl ProxySQL {
173
200
.num_seconds();
174
201
if elapsed > self.warmup_time_sasi64{
175
202
let comment = format!("{comment}\n {DESTINATION_QUERY_TOKEN}: {date_formatted}");
176
-
self.conn.query_drop(format!("UPDATE mysql_query_rules SET mirror_hostgroup = NULL, destination_hostgroup = {}, comment = '{}' WHERE rule_id = {}",self.readyset_hostgroup, comment, rule_id)).expect("Failed to update rule");
203
+
self.conn.query_drop(&format!("UPDATE mysql_query_rules SET mirror_hostgroup = NULL, destination_hostgroup = {}, comment = '{}' WHERE rule_id = {}",self.readyset_hostgroup, comment, rule_id)).expect("Failed to update rule");
177
204
messages::print_note(
178
205
format!("Updated rule ID {} from warmup to destination", rule_id).as_str(),
179
206
);
@@ -286,7 +313,7 @@ impl ProxySQL {
286
313
}
287
314
288
315
/// Returns a reference to the current connection to ProxySQL.
Copy file name to clipboardExpand all lines: src/queries.rs
+23-10Lines changed: 23 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,8 @@
1
1
usecrate::{
2
-
config::{Config,QueryDiscoveryMode},
2
+
config::{Config,DatabaseType,QueryDiscoveryMode},
3
3
messages,
4
4
proxysql::ProxySQL,
5
5
};
6
-
use mysql::prelude::Queryable;
7
6
8
7
pubstructQuery{
9
8
digest_text:String,
@@ -72,6 +71,7 @@ impl Query {
72
71
}
73
72
74
73
pubstructQueryDiscovery{
74
+
database_type:DatabaseType,
75
75
query_discovery_mode:QueryDiscoveryMode,
76
76
query_discovery_min_execution:u64,
77
77
query_discovery_min_rows_sent:u64,
@@ -81,9 +81,13 @@ pub struct QueryDiscovery {
81
81
offset:u16,
82
82
}
83
83
84
-
/// Query Discovery is a feature responsible for discovering queries that are hurting the database performance.
85
-
/// The queries are discovered by analyzing the stats_mysql_query_digest table and finding queries that are not cached in Readyset and are not in the mysql_query_rules table.
86
-
/// The query discover is also responsible for promoting the queries from mirror(warmup) to destination.
84
+
/// Query Discovery is a feature responsible for discovering queries that are hurting the database
85
+
/// performance.
86
+
///
87
+
/// For MySQL, the queries are discovered by analyzing the stats_mysql_query_digest table and
88
+
/// finding queries that are not cached in Readyset and are not in the mysql_query_rules table.
89
+
/// The query discover is also responsible for promoting the queries from mirror(warmup) to
90
+
/// destination.
87
91
implQueryDiscovery{
88
92
/// This function is used to create a new QueryDiscovery struct.
/// This function is used to generate the query responsible for finding queries that are not cached in Readyset and are not in the mysql_query_rules table.
114
+
/// This function is used to generate the query responsible for finding queries that are not
115
+
/// cached in Readyset and are not in the ProxySQL's query rules table.
116
+
///
110
117
/// Queries have to return 3 fields: digest_text, digest, and schema name.
111
118
///
112
119
/// # Returns
113
120
///
114
-
/// A string containing the query responsible for finding queries that are not cached in Readyset and are not in the mysql_query_rules table.
121
+
/// A string containing the query responsible for finding queries that are not cached in
122
+
/// Readyset and are not in the ProxySQL query stats table.
0 commit comments