Convert a logical node to physical node
(logical: &LogicalNode)
| 479 | |
| 480 | /// Convert a logical node to physical node |
| 481 | fn convert_logical_node(logical: &LogicalNode) -> PhysicalNode { |
| 482 | match logical { |
| 483 | LogicalNode::NodeScan { |
| 484 | variable, |
| 485 | labels, |
| 486 | properties, |
| 487 | } => { |
| 488 | let estimated_rows = 1000; // Should use statistics |
| 489 | let estimated_cost = estimated_rows as f64 * 0.1; |
| 490 | |
| 491 | // Choose between sequential and index scan based on selectivity |
| 492 | if labels.is_empty() { |
| 493 | PhysicalNode::NodeSeqScan { |
| 494 | variable: variable.clone(), |
| 495 | labels: labels.clone(), |
| 496 | properties: properties.clone(), |
| 497 | estimated_rows, |
| 498 | estimated_cost, |
| 499 | } |
| 500 | } else { |
| 501 | PhysicalNode::NodeIndexScan { |
| 502 | variable: variable.clone(), |
| 503 | labels: labels.clone(), |
| 504 | properties: properties.clone(), |
| 505 | estimated_rows: estimated_rows / 10, // More selective |
| 506 | estimated_cost: estimated_cost * 0.5, // Cheaper with index |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | LogicalNode::EdgeScan { |
| 512 | variable, |
| 513 | labels, |
| 514 | properties, |
| 515 | } => { |
| 516 | let estimated_rows = 5000; |
| 517 | let estimated_cost = estimated_rows as f64 * 0.1; |
| 518 | |
| 519 | PhysicalNode::EdgeSeqScan { |
| 520 | variable: variable.clone(), |
| 521 | labels: labels.clone(), |
| 522 | properties: properties.clone(), |
| 523 | estimated_rows, |
| 524 | estimated_cost, |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | LogicalNode::Expand { |
| 529 | from_variable, |
| 530 | edge_variable, |
| 531 | to_variable, |
| 532 | edge_labels, |
| 533 | direction, |
| 534 | properties, |
| 535 | input, |
| 536 | } => { |
| 537 | let input_physical = Box::new(Self::convert_logical_node(input)); |
| 538 | let input_rows = input_physical.get_row_count(); |