mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-12-04 08:25:29 +00:00
fix!: drop unused MySQL/PG runtime_size and fix PG Describe column names (#10859)
* chore!: remove unused mysql and postgres runtime_size options `mysql.runtime_size` and `postgres.runtime_size` have not been read since #4436. Remove them from the option structs, example configs and generated config docs. BREAKING CHANGE: `mysql.runtime_size` and `postgres.runtime_size` are no longer part of the frontend/standalone configuration. Existing config files that still set them load unchanged, since the option structs do not deny unknown fields; the keys are ignored as before. The serialized config (e.g. the `/config` HTTP API) no longer lists them. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(servers)!: describe SHOW statements with their execution schema The PostgreSQL extended-protocol Describe hand-wrote result columns for several SHOW statements, and the names did not match what execution returns. pgwire does not resend RowDescription on Execute, so clients reading columns by name saw the wrong names: - SHOW CREATE TABLE/DATABASE/VIEW/FLOW were described as `name` and `create_statement`; execution returns e.g. `Table` and `Create Table`. - SHOW TRIGGERS was described as `name`; execution returns `Triggers`. - SHOW VARIABLES for a query option was described upper-cased; execution keeps the option's spelling. Describe SHOW CREATE from the static schemas execution uses, route SHOW TRIGGERS through the same dataframe path as SHOW FLOWS, and share the SHOW VARIABLES column-name rule with execution. BREAKING CHANGE: extended-protocol PostgreSQL clients now see the same column names for these statements as MySQL and simple-protocol clients. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
This commit is contained in:
@@ -55,7 +55,6 @@
|
||||
| `mysql` | -- | -- | MySQL server options. |
|
||||
| `mysql.enable` | Bool | `true` | Whether to enable. |
|
||||
| `mysql.addr` | String | `127.0.0.1:4002` | The addr to bind the MySQL server. |
|
||||
| `mysql.runtime_size` | Integer | `2` | The number of server worker threads. |
|
||||
| `mysql.keep_alive` | String | `0s` | Server-side keep-alive time.<br/>Set to 0 (default) to disable. |
|
||||
| `mysql.prepared_stmt_cache_size` | Integer | `10000` | Maximum entries in the MySQL prepared statement cache; default is 10,000. |
|
||||
| `mysql.tls` | -- | -- | -- |
|
||||
@@ -66,7 +65,6 @@
|
||||
| `postgres` | -- | -- | PostgresSQL server options. |
|
||||
| `postgres.enable` | Bool | `true` | Whether to enable |
|
||||
| `postgres.addr` | String | `127.0.0.1:4003` | The addr to bind the PostgresSQL server. |
|
||||
| `postgres.runtime_size` | Integer | `2` | The number of server worker threads. |
|
||||
| `postgres.keep_alive` | String | `0s` | Server-side keep-alive time.<br/>Set to 0 (default) to disable. |
|
||||
| `postgres.max_copy_in_payload` | String | `64MB` | Maximum size of a table-less `COPY ... FROM STDIN` payload: the influxdb line protocol, OTLP and Prometheus Remote Write formats, which buffer the whole payload until the copy completes, like an HTTP request body.<br/>Table-bound formats (csv, jsonl, arrow) stream and are not bound by it.<br/>The following units are supported: `B`, `KB`, `KiB`, `MB`, `MiB`, `GB`, `GiB`, `TB`, `TiB`, `PB`, `PiB`.<br/>Set to 0 to disable the limit; nonzero sizes must be at least one byte. |
|
||||
| `postgres.tls` | -- | -- | PostgresSQL server TLS options, see `mysql.tls` section. |
|
||||
@@ -346,7 +344,6 @@
|
||||
| `mysql` | -- | -- | MySQL server options. |
|
||||
| `mysql.enable` | Bool | `true` | Whether to enable. |
|
||||
| `mysql.addr` | String | `127.0.0.1:4002` | The addr to bind the MySQL server. |
|
||||
| `mysql.runtime_size` | Integer | `2` | The number of server worker threads. |
|
||||
| `mysql.keep_alive` | String | `0s` | Server-side keep-alive time.<br/>Set to 0 (default) to disable. |
|
||||
| `mysql.prepared_stmt_cache_size` | Integer | `10000` | Maximum entries in the MySQL prepared statement cache; default is 10,000. |
|
||||
| `mysql.tls` | -- | -- | -- |
|
||||
@@ -357,7 +354,6 @@
|
||||
| `postgres` | -- | -- | PostgresSQL server options. |
|
||||
| `postgres.enable` | Bool | `true` | Whether to enable |
|
||||
| `postgres.addr` | String | `127.0.0.1:4003` | The addr to bind the PostgresSQL server. |
|
||||
| `postgres.runtime_size` | Integer | `2` | The number of server worker threads. |
|
||||
| `postgres.keep_alive` | String | `0s` | Server-side keep-alive time.<br/>Set to 0 (default) to disable. |
|
||||
| `postgres.max_copy_in_payload` | String | `64MB` | Maximum size of a table-less `COPY ... FROM STDIN` payload: the influxdb line protocol, OTLP and Prometheus Remote Write formats, which buffer the whole payload until the copy completes, like an HTTP request body.<br/>Table-bound formats (csv, jsonl, arrow) stream and are not bound by it.<br/>The following units are supported: `B`, `KB`, `KiB`, `MB`, `MiB`, `GB`, `GiB`, `TB`, `TiB`, `PB`, `PiB`.<br/>Set to 0 to disable the limit; nonzero sizes must be at least one byte. |
|
||||
| `postgres.tls` | -- | -- | PostgresSQL server TLS options, see `mysql.tls` section. |
|
||||
|
||||
@@ -180,8 +180,6 @@ watch = false
|
||||
enable = true
|
||||
## The addr to bind the MySQL server.
|
||||
addr = "127.0.0.1:4002"
|
||||
## The number of server worker threads.
|
||||
runtime_size = 2
|
||||
## Server-side keep-alive time.
|
||||
## Set to 0 (default) to disable.
|
||||
keep_alive = "0s"
|
||||
@@ -216,8 +214,6 @@ watch = false
|
||||
enable = true
|
||||
## The addr to bind the PostgresSQL server.
|
||||
addr = "127.0.0.1:4003"
|
||||
## The number of server worker threads.
|
||||
runtime_size = 2
|
||||
## Server-side keep-alive time.
|
||||
## Set to 0 (default) to disable.
|
||||
keep_alive = "0s"
|
||||
|
||||
@@ -161,8 +161,6 @@ watch = false
|
||||
enable = true
|
||||
## The addr to bind the MySQL server.
|
||||
addr = "127.0.0.1:4002"
|
||||
## The number of server worker threads.
|
||||
runtime_size = 2
|
||||
## Server-side keep-alive time.
|
||||
## Set to 0 (default) to disable.
|
||||
keep_alive = "0s"
|
||||
@@ -196,8 +194,6 @@ watch = false
|
||||
enable = true
|
||||
## The addr to bind the PostgresSQL server.
|
||||
addr = "127.0.0.1:4003"
|
||||
## The number of server worker threads.
|
||||
runtime_size = 2
|
||||
## Server-side keep-alive time.
|
||||
## Set to 0 (default) to disable.
|
||||
keep_alive = "0s"
|
||||
|
||||
@@ -787,12 +787,7 @@ mod tests {
|
||||
|
||||
assert_eq!(opts.grpc.bind_addr, default_opts.grpc.bind_addr);
|
||||
assert!(opts.mysql.enable);
|
||||
assert_eq!(opts.mysql.runtime_size, default_opts.mysql.runtime_size);
|
||||
assert!(opts.postgres.enable);
|
||||
assert_eq!(
|
||||
opts.postgres.runtime_size,
|
||||
default_opts.postgres.runtime_size
|
||||
);
|
||||
assert!(opts.opentsdb.enable);
|
||||
|
||||
assert!(!opts.influxdb.enable);
|
||||
@@ -926,11 +921,11 @@ mod tests {
|
||||
Some("127.0.0.1:14002"),
|
||||
),
|
||||
(
|
||||
// mysql.runtime_size = 11
|
||||
// mysql.prepared_stmt_cache_size = 11
|
||||
[
|
||||
env_prefix.to_string(),
|
||||
"mysql".to_uppercase(),
|
||||
"runtime_size".to_uppercase(),
|
||||
"prepared_stmt_cache_size".to_uppercase(),
|
||||
]
|
||||
.join(ENV_VAR_SEP),
|
||||
Some("11"),
|
||||
@@ -967,7 +962,7 @@ mod tests {
|
||||
let fe_opts = command.load_options(&Default::default()).unwrap().component;
|
||||
|
||||
// Should be read from env, env > default values.
|
||||
assert_eq!(fe_opts.mysql.runtime_size, 11);
|
||||
assert_eq!(fe_opts.mysql.prepared_stmt_cache_size, 11);
|
||||
assert_eq!(
|
||||
fe_opts.meta_client.unwrap().metasrv_addrs,
|
||||
vec![
|
||||
|
||||
@@ -1441,7 +1441,6 @@ mod tests {
|
||||
assert_eq!("127.0.0.1:4001".to_string(), fe_opts.grpc.bind_addr);
|
||||
assert!(fe_opts.mysql.enable);
|
||||
assert_eq!("127.0.0.1:4002", fe_opts.mysql.addr);
|
||||
assert_eq!(2, fe_opts.mysql.runtime_size);
|
||||
assert_eq!(None, fe_opts.mysql.reject_no_database);
|
||||
assert!(fe_opts.influxdb.enable);
|
||||
assert!(fe_opts.opentsdb.enable);
|
||||
|
||||
@@ -1147,6 +1147,10 @@ impl Instance {
|
||||
Statement::ShowProcesslist(show) => {
|
||||
query::sql::show_processlist_dataframe(show, engine, catalog_manager, ctx).await
|
||||
}
|
||||
#[cfg(feature = "enterprise")]
|
||||
Statement::ShowTriggers(show) => {
|
||||
query::sql::show_triggers_dataframe(show, engine, catalog_manager, ctx).await
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
Some(dataframe)
|
||||
|
||||
@@ -19,7 +19,6 @@ use servers::tls::TlsOption;
|
||||
pub struct MysqlOptions {
|
||||
pub enable: bool,
|
||||
pub addr: String,
|
||||
pub runtime_size: usize,
|
||||
#[serde(default = "Default::default")]
|
||||
pub tls: TlsOption,
|
||||
pub reject_no_database: Option<bool>,
|
||||
@@ -37,7 +36,6 @@ impl Default for MysqlOptions {
|
||||
Self {
|
||||
enable: true,
|
||||
addr: "127.0.0.1:4002".to_string(),
|
||||
runtime_size: 2,
|
||||
tls: TlsOption::default(),
|
||||
reject_no_database: None,
|
||||
keep_alive: std::time::Duration::from_secs(0),
|
||||
|
||||
@@ -57,7 +57,6 @@ fn deserialize_max_copy_in_payload<'de, D: Deserializer<'de>>(
|
||||
pub struct PostgresOptions {
|
||||
pub enable: bool,
|
||||
pub addr: String,
|
||||
pub runtime_size: usize,
|
||||
#[serde(default = "Default::default")]
|
||||
pub tls: TlsOption,
|
||||
/// Server-side keep-alive time.
|
||||
@@ -85,7 +84,6 @@ impl Default for PostgresOptions {
|
||||
Self {
|
||||
enable: true,
|
||||
addr: "127.0.0.1:4003".to_string(),
|
||||
runtime_size: 2,
|
||||
tls: Default::default(),
|
||||
keep_alive: std::time::Duration::from_secs(0),
|
||||
max_copy_in_payload: default_max_copy_in_payload(),
|
||||
@@ -101,7 +99,7 @@ mod tests {
|
||||
fn test_max_copy_in_payload() {
|
||||
let parse = |value: &str| {
|
||||
toml::from_str::<PostgresOptions>(&format!(
|
||||
"enable = true\naddr = '127.0.0.1:4003'\nruntime_size = 2\nmax_copy_in_payload = {value}"
|
||||
"enable = true\naddr = '127.0.0.1:4003'\nmax_copy_in_payload = {value}"
|
||||
))
|
||||
};
|
||||
for value in ["-1", "'-1MiB'", "'0.5B'", "'1e-999B'"] {
|
||||
|
||||
+31
-6
@@ -144,7 +144,7 @@ pub static DESCRIBE_TABLE_OUTPUT_SCHEMA: Lazy<Arc<Schema>> = Lazy::new(|| {
|
||||
]))
|
||||
});
|
||||
|
||||
static SHOW_CREATE_DATABASE_OUTPUT_SCHEMA: Lazy<Arc<Schema>> = Lazy::new(|| {
|
||||
pub static SHOW_CREATE_DATABASE_OUTPUT_SCHEMA: Lazy<Arc<Schema>> = Lazy::new(|| {
|
||||
Arc::new(Schema::new(vec![
|
||||
ColumnSchema::new("Database", ConcreteDataType::string_datatype(), false),
|
||||
ColumnSchema::new(
|
||||
@@ -155,21 +155,21 @@ static SHOW_CREATE_DATABASE_OUTPUT_SCHEMA: Lazy<Arc<Schema>> = Lazy::new(|| {
|
||||
]))
|
||||
});
|
||||
|
||||
static SHOW_CREATE_TABLE_OUTPUT_SCHEMA: Lazy<Arc<Schema>> = Lazy::new(|| {
|
||||
pub static SHOW_CREATE_TABLE_OUTPUT_SCHEMA: Lazy<Arc<Schema>> = Lazy::new(|| {
|
||||
Arc::new(Schema::new(vec![
|
||||
ColumnSchema::new("Table", ConcreteDataType::string_datatype(), false),
|
||||
ColumnSchema::new("Create Table", ConcreteDataType::string_datatype(), false),
|
||||
]))
|
||||
});
|
||||
|
||||
static SHOW_CREATE_FLOW_OUTPUT_SCHEMA: Lazy<Arc<Schema>> = Lazy::new(|| {
|
||||
pub static SHOW_CREATE_FLOW_OUTPUT_SCHEMA: Lazy<Arc<Schema>> = Lazy::new(|| {
|
||||
Arc::new(Schema::new(vec![
|
||||
ColumnSchema::new("Flow", ConcreteDataType::string_datatype(), false),
|
||||
ColumnSchema::new("Create Flow", ConcreteDataType::string_datatype(), false),
|
||||
]))
|
||||
});
|
||||
|
||||
static SHOW_CREATE_VIEW_OUTPUT_SCHEMA: Lazy<Arc<Schema>> = Lazy::new(|| {
|
||||
pub static SHOW_CREATE_VIEW_OUTPUT_SCHEMA: Lazy<Arc<Schema>> = Lazy::new(|| {
|
||||
Arc::new(Schema::new(vec![
|
||||
ColumnSchema::new("View", ConcreteDataType::string_datatype(), false),
|
||||
ColumnSchema::new("Create View", ConcreteDataType::string_datatype(), false),
|
||||
@@ -946,6 +946,18 @@ pub fn show_query_option(
|
||||
Ok(Some(Output::new_with_record_batches(records)))
|
||||
}
|
||||
|
||||
/// Returns the column name of a `SHOW VARIABLES` result: supported query
|
||||
/// options keep their spelling (see [`show_query_option`]), other variables
|
||||
/// are upper-cased (see [`show_variable`]).
|
||||
pub fn show_variable_column_name(variable: &ObjectName) -> String {
|
||||
let name = sql::ast::object_name_to_string_unquoted(variable);
|
||||
if session::query_options::canonical_query_option_name(&name).is_some() {
|
||||
name
|
||||
} else {
|
||||
variable.to_string().to_uppercase()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show_variable(stmt: ShowVariables, query_ctx: QueryContextRef) -> Result<Output> {
|
||||
let variable = stmt.variable.to_string().to_uppercase();
|
||||
let value = match variable.as_str() {
|
||||
@@ -1272,6 +1284,19 @@ pub async fn show_triggers(
|
||||
catalog_manager: &CatalogManagerRef,
|
||||
query_ctx: QueryContextRef,
|
||||
) -> Result<Output> {
|
||||
let dataframe =
|
||||
show_triggers_dataframe(&stmt, query_engine, catalog_manager, query_ctx).await?;
|
||||
dataframe_to_output(dataframe).await
|
||||
}
|
||||
|
||||
/// Builds the [`DataFrame`] for `SHOW TRIGGERS` without executing it.
|
||||
#[cfg(feature = "enterprise")]
|
||||
pub async fn show_triggers_dataframe(
|
||||
stmt: &sql::statements::show::trigger::ShowTriggers,
|
||||
query_engine: &QueryEngineRef,
|
||||
catalog_manager: &CatalogManagerRef,
|
||||
query_ctx: QueryContextRef,
|
||||
) -> Result<DataFrame> {
|
||||
const TRIGGER_NAME: &str = "trigger_name";
|
||||
const TRIGGERS_COLUMN: &str = "Triggers";
|
||||
|
||||
@@ -1279,7 +1304,7 @@ pub async fn show_triggers(
|
||||
let like_field = Some(TRIGGER_NAME);
|
||||
let sort = vec![col(TRIGGER_NAME).sort(true, true)];
|
||||
|
||||
query_from_information_schema_table(
|
||||
query_from_information_schema_dataframe(
|
||||
query_engine,
|
||||
catalog_manager,
|
||||
query_ctx,
|
||||
@@ -1289,7 +1314,7 @@ pub async fn show_triggers(
|
||||
vec![],
|
||||
like_field,
|
||||
sort,
|
||||
stmt.kind,
|
||||
&stmt.kind,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@@ -44,7 +44,11 @@ use pgwire::messages::data::DataRow;
|
||||
use query::dist_analyze_output_schema;
|
||||
use query::planner::DfLogicalPlanner;
|
||||
use query::query_engine::DescribeResult;
|
||||
use query::sql::DESCRIBE_TABLE_OUTPUT_SCHEMA;
|
||||
use query::sql::{
|
||||
DESCRIBE_TABLE_OUTPUT_SCHEMA, SHOW_CREATE_DATABASE_OUTPUT_SCHEMA,
|
||||
SHOW_CREATE_FLOW_OUTPUT_SCHEMA, SHOW_CREATE_TABLE_OUTPUT_SCHEMA,
|
||||
SHOW_CREATE_VIEW_OUTPUT_SCHEMA, show_variable_column_name,
|
||||
};
|
||||
use session::Session;
|
||||
use session::context::QueryContextRef;
|
||||
use snafu::ResultExt;
|
||||
@@ -706,30 +710,18 @@ fn describe_fields(
|
||||
let schema: Schema = plan.schema().clone().try_into().map_err(convert_err)?;
|
||||
schema_to_pg(&schema, format, None).map_err(convert_err)
|
||||
}
|
||||
// We can cover only part of show statements
|
||||
// these show create statements will return 2 columns
|
||||
SqlPlan::Statement(
|
||||
Statement::ShowCreateDatabase(_)
|
||||
| Statement::ShowCreateTable(_)
|
||||
| Statement::ShowCreateFlow(_)
|
||||
| Statement::ShowCreateView(_),
|
||||
_,
|
||||
) => Ok(vec![
|
||||
FieldInfo::new(
|
||||
"name".to_string(),
|
||||
None,
|
||||
None,
|
||||
Type::TEXT,
|
||||
format.format_for(0),
|
||||
),
|
||||
FieldInfo::new(
|
||||
"create_statement".to_string(),
|
||||
None,
|
||||
None,
|
||||
Type::TEXT,
|
||||
format.format_for(1),
|
||||
),
|
||||
]),
|
||||
SqlPlan::Statement(Statement::ShowCreateDatabase(_), _) => {
|
||||
schema_to_pg(&SHOW_CREATE_DATABASE_OUTPUT_SCHEMA, format, None).map_err(convert_err)
|
||||
}
|
||||
SqlPlan::Statement(Statement::ShowCreateTable(_), _) => {
|
||||
schema_to_pg(&SHOW_CREATE_TABLE_OUTPUT_SCHEMA, format, None).map_err(convert_err)
|
||||
}
|
||||
SqlPlan::Statement(Statement::ShowCreateFlow(_), _) => {
|
||||
schema_to_pg(&SHOW_CREATE_FLOW_OUTPUT_SCHEMA, format, None).map_err(convert_err)
|
||||
}
|
||||
SqlPlan::Statement(Statement::ShowCreateView(_), _) => {
|
||||
schema_to_pg(&SHOW_CREATE_VIEW_OUTPUT_SCHEMA, format, None).map_err(convert_err)
|
||||
}
|
||||
#[cfg(feature = "enterprise")]
|
||||
SqlPlan::Statement(Statement::ShowCreateTrigger(_), _) => Ok(vec![
|
||||
FieldInfo::new(
|
||||
@@ -793,15 +785,6 @@ fn describe_fields(
|
||||
format.format_for(5),
|
||||
),
|
||||
]),
|
||||
|
||||
#[cfg(feature = "enterprise")]
|
||||
SqlPlan::Statement(Statement::ShowTriggers(_), _) => Ok(vec![FieldInfo::new(
|
||||
"name".to_string(),
|
||||
None,
|
||||
None,
|
||||
Type::TEXT,
|
||||
format.format_for(0),
|
||||
)]),
|
||||
// we will not support other show statements for extended query protocol at least for now.
|
||||
// because the return columns is not predictable at this stage
|
||||
SqlPlan::Shortcut(query) => {
|
||||
@@ -815,9 +798,8 @@ fn describe_fields(
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
// Single column named after the variable (see `query::sql::show_variable`).
|
||||
SqlPlan::Statement(Statement::ShowVariables(show), _) => Ok(vec![FieldInfo::new(
|
||||
show.variable.to_string().to_uppercase(),
|
||||
show_variable_column_name(&show.variable),
|
||||
None,
|
||||
None,
|
||||
Type::TEXT,
|
||||
|
||||
@@ -4989,7 +4989,6 @@ watch = false
|
||||
[mysql]
|
||||
enable = true
|
||||
addr = "127.0.0.1:4002"
|
||||
runtime_size = 2
|
||||
keep_alive = "0s"
|
||||
prepared_stmt_cache_size = 10000
|
||||
|
||||
@@ -5003,7 +5002,6 @@ watch = false
|
||||
[postgres]
|
||||
enable = true
|
||||
addr = "127.0.0.1:4003"
|
||||
runtime_size = 2
|
||||
keep_alive = "0s"
|
||||
max_copy_in_payload = "64MiB"
|
||||
|
||||
|
||||
@@ -2068,6 +2068,19 @@ pub async fn test_postgres_extended_query_row_returning_statements(store_type: S
|
||||
assert_eq!(1, rows[0].columns().len());
|
||||
assert_eq!("TIMEZONE", rows[0].columns()[0].name());
|
||||
let _ = rows[0].get::<_, String>(0);
|
||||
let rows = client
|
||||
.query("SHOW VARIABLES \"query.parallelism\"", &[])
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!("query.parallelism", rows[0].columns()[0].name());
|
||||
|
||||
// ---- SHOW CREATE TABLE: `Table` + `Create Table` columns ----
|
||||
let rows = client
|
||||
.query("SHOW CREATE TABLE demo_metrics", &[])
|
||||
.await
|
||||
.unwrap();
|
||||
let names: Vec<&str> = rows[0].columns().iter().map(|c| c.name()).collect();
|
||||
assert_eq!(vec!["Table", "Create Table"], names);
|
||||
|
||||
// ---- DESCRIBE TABLE: fixed six-column string schema ----
|
||||
let rows = client
|
||||
|
||||
@@ -37,7 +37,6 @@ runtime_size = 8
|
||||
[mysql]
|
||||
enable = true
|
||||
addr = "{addrs.mysql_addr}"
|
||||
runtime_size = 2
|
||||
prepared_stmt_cache_size= 10000
|
||||
|
||||
[mysql.tls]
|
||||
@@ -46,7 +45,6 @@ mode = "disable"
|
||||
[postgres]
|
||||
enable = true
|
||||
addr = "{addrs.postgres_addr}"
|
||||
runtime_size = 2
|
||||
|
||||
[procedure]
|
||||
max_retry_times = 3
|
||||
|
||||
Reference in New Issue
Block a user