(
scx: &StatementContext,
explainee: Explainee<Aug>,
params: &Params,
)
| 644 | } |
| 645 | |
| 646 | fn plan_explainee( |
| 647 | scx: &StatementContext, |
| 648 | explainee: Explainee<Aug>, |
| 649 | params: &Params, |
| 650 | ) -> Result<plan::Explainee, PlanError> { |
| 651 | use crate::plan::ExplaineeStatement; |
| 652 | |
| 653 | let is_replan = matches!( |
| 654 | explainee, |
| 655 | Explainee::ReplanView(_) | Explainee::ReplanMaterializedView(_) | Explainee::ReplanIndex(_) |
| 656 | ); |
| 657 | |
| 658 | let explainee = match explainee { |
| 659 | Explainee::View(name) | Explainee::ReplanView(name) => { |
| 660 | let item = scx.get_item_by_resolved_name(&name)?; |
| 661 | let item_type = item.item_type(); |
| 662 | if item_type != CatalogItemType::View { |
| 663 | sql_bail!("Expected {name} to be a view, not a {item_type}"); |
| 664 | } |
| 665 | match is_replan { |
| 666 | true => crate::plan::Explainee::ReplanView(item.id()), |
| 667 | false => crate::plan::Explainee::View(item.id()), |
| 668 | } |
| 669 | } |
| 670 | Explainee::MaterializedView(name) | Explainee::ReplanMaterializedView(name) => { |
| 671 | let item = scx.get_item_by_resolved_name(&name)?; |
| 672 | let item_type = item.item_type(); |
| 673 | if item_type != CatalogItemType::MaterializedView { |
| 674 | sql_bail!("Expected {name} to be a materialized view, not a {item_type}"); |
| 675 | } |
| 676 | match is_replan { |
| 677 | true => crate::plan::Explainee::ReplanMaterializedView(item.id()), |
| 678 | false => crate::plan::Explainee::MaterializedView(item.id()), |
| 679 | } |
| 680 | } |
| 681 | Explainee::Index(name) | Explainee::ReplanIndex(name) => { |
| 682 | let item = scx.get_item_by_resolved_name(&name)?; |
| 683 | let item_type = item.item_type(); |
| 684 | if item_type != CatalogItemType::Index { |
| 685 | sql_bail!("Expected {name} to be an index, not a {item_type}"); |
| 686 | } |
| 687 | match is_replan { |
| 688 | true => crate::plan::Explainee::ReplanIndex(item.id()), |
| 689 | false => crate::plan::Explainee::Index(item.id()), |
| 690 | } |
| 691 | } |
| 692 | Explainee::Select(select, broken) => { |
| 693 | let (plan, desc) = plan_select_inner(scx, *select, params, None)?; |
| 694 | crate::plan::Explainee::Statement(ExplaineeStatement::Select { broken, plan, desc }) |
| 695 | } |
| 696 | Explainee::CreateView(mut stmt, broken) => { |
| 697 | if stmt.if_exists != IfExistsBehavior::Skip { |
| 698 | // If we don't force this parameter to Skip planning will |
| 699 | // fail for names that already exist in the catalog. This |
| 700 | // can happen even in `Replace` mode if the existing item |
| 701 | // has dependencies. |
| 702 | stmt.if_exists = IfExistsBehavior::Skip; |
| 703 | } else { |
no test coverage detected