classComparison
final class Comparison
implements Scalar
uses Snapshot
@visibility public.A comparison of two operands, in the order written.
Comparisons belong to the bool_pri level and associate to the left; the right operand is a predicate (MYSQL-PRECEDENCE-001). An operand that would be read differently without a grouping, such as a comparison on the right or a variable assignment on the left, is rejected (Item_func_eq, Item_func_equal, Item_func_ne, Item_func_lt, …).
Rule: MYSQL-COMPARISON-001. Facts: a comparison yields 1, 0 or NULL, an integer; it can be NULL when an operand can, except <=>, which never is. Two rows are compared element by element and must have the same width (MYSQL-OPERAND-COLUMNS-001). Terminates: the operands are strict parts. Source: https://dev.mysql.com/doc/refman/8.4/en/comparison-operators.html, https://dev.mysql.com/doc/refman/8.4/en/row-subqueries.html. Status: Implemented.
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM t WHERE a >= 10');
[$query->statement->where->left->name->value, $query->statement->where->right->text] // => ['a', '10']Properties§
public ComparisonOperator $operatorpublic Scalar $leftpublic Scalar $rightMethods§
public function __construct(
public ComparisonOperator $operator,
public Scalar $left,
public Scalar $right,
)Parameters
$operator | ComparisonOperator | The operator |
$left | Scalar | The left operand |
$right | Scalar | The right operand |
Calls 6
- new Precedence line 51
- static-call Check::input() line 52
- method-call Precedence::fits() line 52
- class-const Precedence::BOOL_PRI() line 52
- method-call Precedence::opening() line 53
- class-const Precedence::PREDICATE() line 53
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives both operands and combines their NULL facts.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 6
- method-call Derivation::scalar() line 61
- new Operands line 63
- method-call Operands::comparable() line 64
- method-call Operands::truth() line 66
- class-const ComparisonOperator::NullSafeEqual() line 66
- class-const Nullability::NotNull() line 66
public function render(Output $out): voidWrites the operands around the operator.
Parameters
$out | Output |
Calls 1
- method-call Output::node() line 74
Test cases 47§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 9
ComparisonTest::testAComparisonAsRightOperandIsRejectedcallsComparisonTest::testAVariableAssignmentAsLeftOperandIsRejectedcallsComparisonTest::testDeriveScalarDependsOnTheOperandsOfAnUndeclaredTablecallsComparisonTest::testDeriveScalarNeverYieldsNullForTheNullSafeEqualitycallsComparisonTest::testDeriveScalarNeverYieldsNullWhenBothOperandsCannotcallsComparisonTest::testDeriveScalarYieldsAnIntegerThatCanBeNullWhenAnOperandCancallsComparisonTest::testRenderKeepsTheLeftAssociationOfAChaincallsComparisonTest::testRenderSpellsTheNotEqualOperatorInItsStandardFormcallsComparisonTest::testRenderWritesTheOperandsAroundTheOperatorInTheOrderWrittencalls
Other tests reaching this symbol 38
ConditionRuleTest::testBooleanLowersAChainOfNullTestsAndComparisonscallsFlowRuleTest::testChoiceLowersASearchedCasecallsFlowRuleTest::testConditionalLowersTheBranchesAndTheElsecallsFlowRuleTest::testJumpLowersReturnLeaveAndIteratecallsFlowRuleTest::testLoopLowersLoopWhileAndRepeatcallsKeyRuleTest::testCheckLowersTheConditioncallsColumnResolverTest::testUnlistedAnswersTheOccurrencesThatMayGiveAHavingPositionTheNamecallsPrecedenceTest::testAdmitsAcceptsTheNonterminalsOfASlotcallsFromScopeTest::testEnterDerivesTheConditionWithTheOperandsBeforeExtensioncallsHavingScopeTest::testGroupingAnswersTheColumnsAsTheHavingPositionSeesThemcallsHavingScopeTest::testLeaveLetsTheArgumentsOfASetFunctionSeeTheColumnscallsHavingScopeTest::testUndecidedAnswersTheColumnsOfIncompletelyKnownOccurrencescallsResultReferencesTest::testFindPrefersAGroupByColumnToASelectListItemcallsResultReferencesTest::testGroupingSkipsAColumnOfAnotherOccurrenceAndReportsTwoDifferentColumnscallsResultReferencesTest::testSelectedIsConditionalWhileAnItemWithoutADecidedNameCouldHaveTheNamecallsResultReferencesTest::testSelectedResolvesAColumnItemToItsColumnAndAnotherItemToTheItemcallsBlockFactsTest::testDeriveDerivesTheCursorQueryInTheScopeOfTheBlockcallsBodyFactsTest::testStatementResolvesAVariableInANestedQuerycallsFlowFactsTest::testBranchesResolvesAVariableInTheConditioncallsFlowFactsTest::testLoopResolvesAVariableInTheConditioncallsNotTest::testRenderNegatesAComparisonWithoutParenthesescallsIntervalAdditionTest::testRenderLetsTheOperandExtendOverAComparisoncallsInListTest::testAComparisonOperandIsRejectedcallsInQueryTest::testAComparisonOperandIsRejectedcallsTruthTestTest::testRenderWritesTheNegatedTestcallsBooleanLiteralTest::testDeriveScalarAnswersBigIntThatIsNeverNullcallsNullLiteralTest::testDeriveScalarAnswersTheNullOnlyTypeThatIsNullablecallsNumberLiteralTest::testDeriveScalarAnswersTheTypeOfTheTextThatIsNeverNullcallsParameterTest::testDeriveScalarDependsOnTheBoundValuecallsParameterTest::testDeriveScalarNamesANamedMarkercallsRadixLiteralTest::testDeriveScalarAnswersVarBinaryWithoutAnIntroducercallsStringLiteralTest::testValueConcatenatesTheAdjacentSegmentscallsTemporalLiteralTest::testDeriveScalarAnswersTheTemporalTypeThatIsNeverNullcallsColumnUseTest::testDeriveScalarAnswersTheFactsOfTheItemAnAliasNamescallsSelectTest::testDeriveQueryDerivesThePredicateInTheScopeOfTheTablecallsSelectTest::testRenderBuildsSqlFromAnExplicitStructurecallsCreateTableTest::testDeriveStatementDerivesTheElementsInTheTablecallsVariableAssignmentTest::testDeriveScalarTakesEverythingRightOfTheOperatorAsTheValuecalls