Commit d6f1b7f
Fix MATCH on brand-new label after CREATE returning 0 rows (#2341)
* Fix MATCH on brand-new label after CREATE returning 0 rows (issue #2193)
When CREATE introduces a new label and a subsequent MATCH references it
(e.g., CREATE (:Person) WITH ... MATCH (p:Person)), the query returns
0 rows on first execution but works on the second.
Root cause: match_check_valid_label() in transform_cypher_match() runs
before transform_prev_cypher_clause() processes the predecessor chain.
Since CREATE has not yet executed its transform (which creates the label
table as a side effect), the label is not in the cache and the check
generates a One-Time Filter: false plan that returns no rows.
Fix: Skip the early label validity check when the predecessor clause
chain contains a data-modifying operation (CREATE, SET, DELETE, MERGE).
After transform_prev_cypher_clause() completes and any new labels exist
in the cache, run a deferred label check. If the labels are still
invalid at that point, generate an empty result via makeBoolConst(false).
This preserves the existing behavior for MATCH without DML predecessors
(e.g., MATCH-MATCH chains still get the early check and proper error
messages for invalid labels).
Depends on: PR #2340 (clause_chain_has_dml helper)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Address review feedback: fix variable registration for deferred label check
When the deferred label validity check (DML predecessor + non-existent
label) found an invalid label, the code skipped transform_match_pattern()
entirely, which meant MATCH-introduced variables were never registered
in the namespace. This would cause errors if a later clause referenced
those variables (e.g., RETURN p).
Fix: mirror the early-check strategy by injecting a paradoxical WHERE
(true = false) and always calling transform_match_pattern(). Variables
get registered normally; zero rows are returned via the impossible qual.
Also add ORDER BY to multi-row regression tests for deterministic output,
and add a test case for DML predecessor + non-existent label + returning
a MATCH-introduced variable.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Address Copilot review: DRY false-where helper, cache has_dml, ORDER BY in tests
- Factor duplicated WHERE true=false construction into
make_false_where_clause() helper (used in both early and deferred
label validation paths)
- Compute clause_chain_has_dml() once and reuse, avoiding repeated
clause chain traversal
- Add ORDER BY to the single-CREATE City regression test for
deterministic result ordering
* Address Copilot review: volatile false predicate, DML side-effect test
1. Prevent plan elimination of DML predecessor: replace constant
(true = false) with volatile (random() IS NULL) in the deferred
label check path. PG's planner can constant-fold the former into
a One-Time Filter: false, skipping the DML scan entirely.
2. Unify make_false_where_clause(bool volatile_needed): merge the
constant and volatile variants into a single parameterized
function. Call sites are now self-documenting:
- make_false_where_clause(false) for non-DML path
- make_false_where_clause(true) for DML predecessor path
3. Document why add_volatile_wrapper() cannot be reused here (it
operates post-transform at the Expr level and returns agtype,
while the WHERE clause is built at the parse-tree level).
4. Add regression test verifying CREATE side effects persist when
MATCH references a non-existent label after a DML predecessor.
All regression tests pass (cypher_match: ok).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Replace non-ASCII em dashes with -- in C comments
ASCII-only codebase convention; avoids encoding/tooling issues.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent a29e281 commit d6f1b7f
3 files changed
Lines changed: 244 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3737 | 3737 | | |
3738 | 3738 | | |
3739 | 3739 | | |
| 3740 | + | |
| 3741 | + | |
| 3742 | + | |
| 3743 | + | |
| 3744 | + | |
| 3745 | + | |
| 3746 | + | |
| 3747 | + | |
| 3748 | + | |
| 3749 | + | |
| 3750 | + | |
| 3751 | + | |
| 3752 | + | |
| 3753 | + | |
| 3754 | + | |
| 3755 | + | |
| 3756 | + | |
| 3757 | + | |
| 3758 | + | |
| 3759 | + | |
| 3760 | + | |
| 3761 | + | |
| 3762 | + | |
| 3763 | + | |
| 3764 | + | |
| 3765 | + | |
| 3766 | + | |
| 3767 | + | |
| 3768 | + | |
| 3769 | + | |
| 3770 | + | |
| 3771 | + | |
| 3772 | + | |
| 3773 | + | |
| 3774 | + | |
| 3775 | + | |
| 3776 | + | |
| 3777 | + | |
| 3778 | + | |
| 3779 | + | |
| 3780 | + | |
| 3781 | + | |
| 3782 | + | |
| 3783 | + | |
| 3784 | + | |
| 3785 | + | |
| 3786 | + | |
| 3787 | + | |
| 3788 | + | |
| 3789 | + | |
| 3790 | + | |
| 3791 | + | |
| 3792 | + | |
| 3793 | + | |
| 3794 | + | |
| 3795 | + | |
| 3796 | + | |
| 3797 | + | |
| 3798 | + | |
| 3799 | + | |
| 3800 | + | |
| 3801 | + | |
| 3802 | + | |
| 3803 | + | |
| 3804 | + | |
| 3805 | + | |
| 3806 | + | |
| 3807 | + | |
| 3808 | + | |
| 3809 | + | |
| 3810 | + | |
| 3811 | + | |
| 3812 | + | |
| 3813 | + | |
| 3814 | + | |
| 3815 | + | |
| 3816 | + | |
| 3817 | + | |
| 3818 | + | |
| 3819 | + | |
| 3820 | + | |
| 3821 | + | |
| 3822 | + | |
| 3823 | + | |
| 3824 | + | |
| 3825 | + | |
| 3826 | + | |
| 3827 | + | |
| 3828 | + | |
| 3829 | + | |
| 3830 | + | |
| 3831 | + | |
| 3832 | + | |
| 3833 | + | |
| 3834 | + | |
| 3835 | + | |
| 3836 | + | |
3740 | 3837 | | |
3741 | 3838 | | |
3742 | 3839 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1558 | 1558 | | |
1559 | 1559 | | |
1560 | 1560 | | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
1561 | 1619 | | |
1562 | 1620 | | |
1563 | 1621 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| 349 | + | |
349 | 350 | | |
350 | 351 | | |
351 | 352 | | |
| |||
2639 | 2640 | | |
2640 | 2641 | | |
2641 | 2642 | | |
2642 | | - | |
| 2643 | + | |
| 2644 | + | |
| 2645 | + | |
| 2646 | + | |
| 2647 | + | |
| 2648 | + | |
| 2649 | + | |
| 2650 | + | |
| 2651 | + | |
2643 | 2652 | | |
2644 | | - | |
2645 | | - | |
2646 | | - | |
2647 | | - | |
2648 | | - | |
2649 | | - | |
2650 | | - | |
2651 | | - | |
2652 | | - | |
2653 | | - | |
2654 | | - | |
2655 | | - | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
2656 | 2656 | | |
2657 | 2657 | | |
2658 | 2658 | | |
| |||
2915 | 2915 | | |
2916 | 2916 | | |
2917 | 2917 | | |
| 2918 | + | |
2918 | 2919 | | |
2919 | 2920 | | |
2920 | 2921 | | |
| |||
2928 | 2929 | | |
2929 | 2930 | | |
2930 | 2931 | | |
2931 | | - | |
| 2932 | + | |
| 2933 | + | |
| 2934 | + | |
2932 | 2935 | | |
2933 | 2936 | | |
2934 | 2937 | | |
| |||
2949 | 2952 | | |
2950 | 2953 | | |
2951 | 2954 | | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
2952 | 2974 | | |
2953 | 2975 | | |
2954 | 2976 | | |
| |||
6621 | 6643 | | |
6622 | 6644 | | |
6623 | 6645 | | |
| 6646 | + | |
| 6647 | + | |
| 6648 | + | |
| 6649 | + | |
| 6650 | + | |
| 6651 | + | |
| 6652 | + | |
| 6653 | + | |
| 6654 | + | |
| 6655 | + | |
| 6656 | + | |
| 6657 | + | |
| 6658 | + | |
| 6659 | + | |
| 6660 | + | |
| 6661 | + | |
| 6662 | + | |
| 6663 | + | |
| 6664 | + | |
| 6665 | + | |
| 6666 | + | |
| 6667 | + | |
| 6668 | + | |
| 6669 | + | |
| 6670 | + | |
| 6671 | + | |
| 6672 | + | |
| 6673 | + | |
| 6674 | + | |
| 6675 | + | |
| 6676 | + | |
| 6677 | + | |
| 6678 | + | |
| 6679 | + | |
| 6680 | + | |
| 6681 | + | |
| 6682 | + | |
| 6683 | + | |
| 6684 | + | |
| 6685 | + | |
| 6686 | + | |
| 6687 | + | |
| 6688 | + | |
| 6689 | + | |
| 6690 | + | |
| 6691 | + | |
| 6692 | + | |
| 6693 | + | |
| 6694 | + | |
| 6695 | + | |
| 6696 | + | |
| 6697 | + | |
| 6698 | + | |
6624 | 6699 | | |
6625 | 6700 | | |
6626 | 6701 | | |
| |||
0 commit comments