mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-07-05 21:40:38 +00:00
chore: add repartition debug logs (#8245)
Signed-off-by: WenyXu <wenymedia@gmail.com>
This commit is contained in:
@@ -3,6 +3,8 @@ logging:
|
||||
format: "json"
|
||||
filters:
|
||||
- mito2::sst::file=debug
|
||||
- query::dist_plan::analyzer=debug
|
||||
- query::dist_plan::planner=debug
|
||||
meta:
|
||||
configData: |-
|
||||
[runtime]
|
||||
|
||||
@@ -102,7 +102,6 @@ impl State for UpdatePartitionMetadata {
|
||||
new_table_info
|
||||
.meta
|
||||
.partition_column_names()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
ctx.update_table_info(&table_info_value, table_info_value.update(new_table_info))
|
||||
|
||||
@@ -557,9 +557,13 @@ impl PlanRewriter {
|
||||
let partition_key_indices = info.meta.partition_key_indices.clone();
|
||||
let schema = info.meta.schema.clone();
|
||||
let mut partition_cols = partition_key_indices
|
||||
.into_iter()
|
||||
.map(|index| schema.column_name_by_index(index).to_string())
|
||||
.iter()
|
||||
.map(|index| schema.column_name_by_index(*index).to_string())
|
||||
.collect::<Vec<String>>();
|
||||
debug!(
|
||||
"PlanRewriter: loaded table partition metadata, table: {}, table_id: {}, partition_key_indices: {:?}, partition_columns: {:?}",
|
||||
info.name, info.ident.table_id, info.meta.partition_key_indices, partition_cols,
|
||||
);
|
||||
|
||||
let partition_rules = table.partition_rules();
|
||||
let exist_phy_part_cols_not_in_logical_table = partition_rules
|
||||
|
||||
@@ -60,12 +60,15 @@ impl TreeNodeRewriter for FallbackPlanRewriter {
|
||||
let partition_key_indices = info.meta.partition_key_indices.clone();
|
||||
let schema = info.meta.schema.clone();
|
||||
let partition_cols = partition_key_indices
|
||||
.into_iter()
|
||||
.map(|index| schema.column_name_by_index(index).to_string())
|
||||
.iter()
|
||||
.map(|index| schema.column_name_by_index(*index).to_string())
|
||||
.collect::<Vec<String>>();
|
||||
debug!(
|
||||
"FallbackPlanRewriter: table {} has partition columns: {:?}",
|
||||
info.name, partition_cols
|
||||
"FallbackPlanRewriter: loaded table partition metadata, table: {}, table_id: {}, partition_key_indices: {:?}, partition_columns: {:?}",
|
||||
info.name,
|
||||
info.ident.table_id,
|
||||
info.meta.partition_key_indices,
|
||||
partition_cols,
|
||||
);
|
||||
Some(partition_cols
|
||||
.into_iter()
|
||||
|
||||
@@ -20,6 +20,7 @@ use ahash::HashMap;
|
||||
use async_trait::async_trait;
|
||||
use catalog::CatalogManagerRef;
|
||||
use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME};
|
||||
use common_telemetry::debug;
|
||||
use datafusion::common::Result;
|
||||
use datafusion::datasource::DefaultTableSource;
|
||||
use datafusion::execution::context::SessionState;
|
||||
@@ -225,6 +226,14 @@ impl DistExtensionPlanner {
|
||||
// Extract partition columns
|
||||
let partition_columns: Vec<String> =
|
||||
table_info.meta.partition_column_names().cloned().collect();
|
||||
debug!(
|
||||
"DistExtensionPlanner: loaded table partition metadata, table: {}, table_id: {}, partition_key_indices: {:?}, partition_columns: {:?}, all_regions: {:?}",
|
||||
table_name,
|
||||
table_info.table_id(),
|
||||
table_info.meta.partition_key_indices,
|
||||
partition_columns,
|
||||
all_regions,
|
||||
);
|
||||
if partition_columns.is_empty() {
|
||||
return Ok(all_regions);
|
||||
}
|
||||
|
||||
@@ -161,6 +161,13 @@ pub async fn count_values(db: &MySqlPool, sql: &str) -> Result<ValueCount> {
|
||||
.context(error::ExecuteQuerySnafu { sql })
|
||||
}
|
||||
|
||||
pub async fn count_values_all(db: &MySqlPool, sql: &str) -> Result<Vec<ValueCount>> {
|
||||
sqlx::query_as::<_, ValueCount>(sql)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.context(error::ExecuteQuerySnafu { sql })
|
||||
}
|
||||
|
||||
/// Returns all [RowEntry] of the `table_name`.
|
||||
pub async fn fetch_values(db: &MySqlPool, sql: &str) -> Result<Vec<MySqlRow>> {
|
||||
sqlx::query(sql)
|
||||
|
||||
@@ -60,7 +60,7 @@ use tests_fuzz::utils::{
|
||||
get_gt_fuzz_input_max_rows, init_greptime_connections_via_env,
|
||||
};
|
||||
use tests_fuzz::validator;
|
||||
use tests_fuzz::validator::row::count_values;
|
||||
use tests_fuzz::validator::row::count_values_all;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct FuzzContext {
|
||||
@@ -230,16 +230,26 @@ async fn validate_table_rows(
|
||||
inserted_rows: u64,
|
||||
) -> Result<()> {
|
||||
let count_sql = format!("SELECT COUNT(1) AS count FROM {}", table_ctx.name);
|
||||
let count = count_values(&ctx.greptime, &count_sql).await?;
|
||||
assert_eq!(count.count as u64, inserted_rows);
|
||||
let counts = count_values_all(&ctx.greptime, &count_sql).await?;
|
||||
info!("Validate table row count: sql={count_sql}, expected={inserted_rows}, counts={counts:?}");
|
||||
assert_eq!(counts.len(), 1, "count query must return exactly one row");
|
||||
assert_eq!(counts[0].count as u64, inserted_rows);
|
||||
|
||||
let timestamp_column_name = table_ctx.timestamp_column().unwrap().name.clone();
|
||||
let distinct_count_sql = format!(
|
||||
"SELECT COUNT(DISTINCT {}) AS count FROM {}",
|
||||
timestamp_column_name, table_ctx.name
|
||||
);
|
||||
let distinct_count = count_values(&ctx.greptime, &distinct_count_sql).await?;
|
||||
assert_eq!(distinct_count.count as u64, inserted_rows);
|
||||
let distinct_counts = count_values_all(&ctx.greptime, &distinct_count_sql).await?;
|
||||
info!(
|
||||
"Validate table distinct row count: sql={distinct_count_sql}, expected={inserted_rows}, counts={distinct_counts:?}"
|
||||
);
|
||||
assert_eq!(
|
||||
distinct_counts.len(),
|
||||
1,
|
||||
"distinct count query must return exactly one row"
|
||||
);
|
||||
assert_eq!(distinct_counts[0].count as u64, inserted_rows);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user