Disallow joining more than 63 tables

Returns an error instead of panicing
This commit is contained in:
Jussi Saurio
2025-10-13 13:12:33 +03:00
parent bd97c117ed
commit 59a1c2ae2e
3 changed files with 34 additions and 0 deletions

View File

@@ -187,6 +187,12 @@ fn optimize_table_access(
order_by: &mut Vec<(Box<ast::Expr>, SortOrder)>,
group_by: &mut Option<GroupBy>,
) -> Result<Option<Vec<JoinOrderMember>>> {
if table_references.joined_tables().len() > TableReferences::MAX_JOINED_TABLES {
crate::bail_parse_error!(
"Only up to {} tables can be joined",
TableReferences::MAX_JOINED_TABLES
);
}
let access_methods_arena = RefCell::new(Vec::new());
let maybe_order_target = compute_order_target(order_by, group_by.as_mut());
let constraints_per_table =

View File

@@ -583,6 +583,11 @@ pub struct TableReferences {
}
impl TableReferences {
/// The maximum number of tables that can be joined together in a query.
/// This limit is arbitrary, although we currently use a u128 to represent the [crate::translate::planner::TableMask],
/// which can represent up to 128 tables.
/// Even at 63 tables we currently cannot handle the optimization performantly, hence the arbitrary cap.
pub const MAX_JOINED_TABLES: usize = 63;
pub fn new(
joined_tables: Vec<JoinedTable>,
outer_query_refs: Vec<OuterQueryReference>,