Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/query/ast/src/parser/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ pub fn display_parser_error(error: Error, source: &str) -> String {
format!("unexpected `{span_text}`")
};
if let Some(suggestion) = has_suggestion {
msg += &format!(". {}", suggestion);
write!(msg, ". {}", suggestion).unwrap();
labels = vec![(inner.span, msg)];

// Return early to skip context labels when we have intelligent suggestions
Expand Down
54 changes: 36 additions & 18 deletions src/query/service/src/physical_plans/format/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use std::collections::HashMap;
use std::fmt::Write;

use databend_common_ast::ast::FormatTreeNode;
use databend_common_base::base::format_byte_size;
Expand Down Expand Up @@ -70,64 +71,74 @@ pub fn part_stats_info_to_format_tree(info: &PartStatistics) -> Vec<FormatTreeNo

// range pruning status.
if info.pruning_stats.blocks_range_pruning_before > 0 {
blocks_pruning_description += &format!(
write!(
blocks_pruning_description,
"range pruning: {} to {}{}",
info.pruning_stats.blocks_range_pruning_before,
info.pruning_stats.blocks_range_pruning_after,
format_pruning_cost_suffix(info.pruning_stats.blocks_range_pruning_cost)
);
)
.unwrap();
}

// bloom pruning status.
if info.pruning_stats.blocks_bloom_pruning_before > 0 {
if !blocks_pruning_description.is_empty() {
blocks_pruning_description += ", ";
blocks_pruning_description.push_str(", ");
}
blocks_pruning_description += &format!(
write!(
blocks_pruning_description,
"bloom pruning: {} to {}{}",
info.pruning_stats.blocks_bloom_pruning_before,
info.pruning_stats.blocks_bloom_pruning_after,
format_pruning_cost_suffix(info.pruning_stats.blocks_bloom_pruning_cost)
);
)
.unwrap();
}

// inverted index pruning status.
if info.pruning_stats.blocks_inverted_index_pruning_before > 0 {
if !blocks_pruning_description.is_empty() {
blocks_pruning_description += ", ";
blocks_pruning_description.push_str(", ");
}
blocks_pruning_description += &format!(
write!(
blocks_pruning_description,
"inverted pruning: {} to {}{}",
info.pruning_stats.blocks_inverted_index_pruning_before,
info.pruning_stats.blocks_inverted_index_pruning_after,
format_pruning_cost_suffix(info.pruning_stats.blocks_inverted_index_pruning_cost)
);
)
.unwrap();
}

// topn pruning status.
if info.pruning_stats.blocks_topn_pruning_before > 0 {
if !blocks_pruning_description.is_empty() {
blocks_pruning_description += ", ";
blocks_pruning_description.push_str(", ");
}
blocks_pruning_description += &format!(
write!(
blocks_pruning_description,
"topn pruning: {} to {}{}",
info.pruning_stats.blocks_topn_pruning_before,
info.pruning_stats.blocks_topn_pruning_after,
format_pruning_cost_suffix(info.pruning_stats.blocks_topn_pruning_cost)
);
)
.unwrap();
}

// vector index pruning status.
if info.pruning_stats.blocks_vector_index_pruning_before > 0 {
if !blocks_pruning_description.is_empty() {
blocks_pruning_description += ", ";
blocks_pruning_description.push_str(", ");
}
blocks_pruning_description += &format!(
write!(
blocks_pruning_description,
"vector pruning: {} to {}{}",
info.pruning_stats.blocks_vector_index_pruning_before,
info.pruning_stats.blocks_vector_index_pruning_after,
format_pruning_cost_suffix(info.pruning_stats.blocks_vector_index_pruning_cost)
);
)
.unwrap();
}

// Combine segment pruning and blocks pruning descriptions if any
Expand All @@ -137,19 +148,26 @@ pub fn part_stats_info_to_format_tree(info: &PartStatistics) -> Vec<FormatTreeNo
let mut pruning_description = String::new();

if info.pruning_stats.segments_range_pruning_before > 0 {
pruning_description += &format!(
write!(
pruning_description,
"segments: <range pruning: {} to {}{}>",
info.pruning_stats.segments_range_pruning_before,
info.pruning_stats.segments_range_pruning_after,
format_pruning_cost_suffix(info.pruning_stats.segments_range_pruning_cost)
);
)
.unwrap();
}

if !blocks_pruning_description.is_empty() {
if !pruning_description.is_empty() {
pruning_description += ", ";
pruning_description.push_str(", ");
}
pruning_description += &format!("blocks: <{}>", blocks_pruning_description);
write!(
pruning_description,
"blocks: <{}>",
blocks_pruning_description
)
.unwrap();
}

items.push(FormatTreeNode::new(format!(
Expand Down
61 changes: 38 additions & 23 deletions src/query/sql/src/planner/optimizer/pipeline/trace/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use std::collections::BTreeMap;
use std::fmt::Write;
use std::time::Duration;

use databend_common_exception::Result;
Expand Down Expand Up @@ -286,10 +287,12 @@ impl OptimizerTraceCollector {
(0, 0)
};

summary.push_str(&format!(
"[{}] {}: {} ({:.2?})\n",
writeln!(
summary,
"[{}] {}: {} ({:.2?})",
status_symbol, optimizer.index, optimizer.name, optimizer.time
));
)
.unwrap();

if total_rules > 0 {
let applied_percentage = if total_rules > 0 {
Expand All @@ -298,10 +301,12 @@ impl OptimizerTraceCollector {
0
};

summary.push_str(&format!(
" └── Rules: {}/{} Applied ({}%)\n",
writeln!(
summary,
" └── Rules: {}/{} Applied ({}%)",
applied_rules, total_rules, applied_percentage
));
)
.unwrap();

// Add detailed rules summary if available
if let Some(optimizer_rules) = rules.get(&optimizer.name) {
Expand All @@ -312,7 +317,7 @@ impl OptimizerTraceCollector {
// Add indentation to rules summary
for line in rules_summary.lines() {
if !line.trim().is_empty() {
summary.push_str(&format!(" {}\n", line));
writeln!(summary, " {}", line).unwrap();
}
}
}
Expand Down Expand Up @@ -340,16 +345,18 @@ impl OptimizerTraceCollector {
let mut detail = String::new();

// Add basic optimizer information
detail.push_str(&format!(
write!(
detail,
"[{}] {}: {} ({:.2?})\n\n",
status_symbol, optimizer.index, optimizer.name, optimizer.time
));
)
.unwrap();

// Add expression changes if any
if optimizer.had_effect && !optimizer.diff.is_empty() {
detail.push_str(" Changes:\n");
for line in optimizer.diff.lines() {
detail.push_str(&format!(" {}\n", line));
writeln!(detail, " {}", line).unwrap();
}
detail.push('\n');
}
Expand Down Expand Up @@ -389,15 +396,17 @@ impl OptimizerTraceCollector {
return report;
}

report.push_str(&format!("[{}] Rules Summary:\n", optimizer.name));
writeln!(report, "[{}] Rules Summary:", optimizer.name).unwrap();

// List all rules with their status
for rule in &all_rules {
let status_symbol = if rule.had_effect { "✓" } else { "✗" };
report.push_str(&format!(
" [{}] {}.{}: {} ({:.2?})\n",
writeln!(
report,
" [{}] {}.{}: {} ({:.2?})",
status_symbol, optimizer.index, rule.sequence, rule.name, rule.time
));
)
.unwrap();
}
report.push('\n');

Expand All @@ -418,17 +427,21 @@ impl OptimizerTraceCollector {
};

// Add statistics to report
report.push_str(&format!(
" Total Applied Rules: {}/{} ({}%)\n",
writeln!(
report,
" Total Applied Rules: {}/{} ({}%)",
applied_rules, total_rules, applied_percentage
));
)
.unwrap();

report.push_str(&format!(
write!(
report,
" Total Non-Applied Rules: {}/{} ({}%)\n\n",
total_rules - applied_rules,
total_rules,
non_applied_percentage
));
)
.unwrap();

report
}
Expand All @@ -454,16 +467,18 @@ impl OptimizerTraceCollector {
for rule in applied_rules {
// Always use checkmark since we only show rules that had an effect
let status_symbol = "✓";
report.push_str(&format!(
" [{}] {}.{}: {}.{} ({:.2?})\n",
writeln!(
report,
" [{}] {}.{}: {}.{} ({:.2?})",
status_symbol, optimizer.index, rule.sequence, optimizer.name, rule.name, rule.time
));
)
.unwrap();

// Add expression changes if available
if !rule.diff.is_empty() {
report.push_str(" Changes:\n");
for line in rule.diff.lines() {
report.push_str(&format!(" {}\n", line));
writeln!(report, " {}", line).unwrap();
}
}

Expand Down
Loading