Chg #960: Pass non-null and non-expression values only to dbTypecast() - #1197
Open
KalimeroMK wants to merge 3 commits into
Open
Chg #960: Pass non-null and non-expression values only to dbTypecast()#1197KalimeroMK wants to merge 3 commits into
KalimeroMK wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1197 +/- ##
=========================================
Coverage 98.62% 98.62%
Complexity 1645 1645
=========================================
Files 120 121 +1
Lines 4288 4290 +2
=========================================
+ Hits 4229 4231 +2
Misses 59 59 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Drivers and custom code call ColumnInterface::dbTypecast() directly (e.g. with Expression default values in DDL builders, or Param values). Since Expression is Stringable, removing the ExpressionInterface arms silently stringified expressions instead of passing them through, breaking all driver test matrices. The wrapper function and internal call sites stay; the simplification of implementations needs a coordinated change across driver packages.
Expressions must reach ColumnInterface::dbTypecast(): some implementations process them (for example, MSSQL's binary column unwraps Param values into CONVERT expressions). Filtering them in the wrapper bypassed that processing and broke the MSSQL test matrix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #960
Changes
Adds the
Yiisoft\Db\dbTypecast()function (proposed in the issue) that returnsnullvalues as is, and delegates everything else toColumnInterface::dbTypecast().Internal call sites (
AbstractDMLQueryBuilder,AbstractColumnDefinitionBuilder,DateTimeValueBuilder) now use the function.Column implementations are intentionally left untouched. Two findings from the driver test matrices:
ExpressionisStringable, so removing theExpressionInterfacearms silently stringifies expressions instead of passing them through (breaks DDL builders in db-pgsql/db-mssql that passExpressiondefault values directly).Yiisoft\Db\Mssql\Column\BinaryColumn::dbTypecast()unwrapsParamvalues intoCONVERT(VARBINARY(MAX), ...)expressions, so a wrapper must not filterExpressionInterfaceeither.Net effect: only
nullis safe to pre-filter. Simplifying the implementations needs a coordinated change across the driver packages and can be done as a follow-up for 3.0.Benchmark
2M calls per round, median of 7 rounds, PHP 8.5 with OPcache + JIT (tracing), workload: 80% scalars, 10%
null, 10% expressions,IntegerColumn+StringColumn:dbTypecast()function)The function adds ~4 ns per call on trivial casts. In the real DML path,
buildValue()dominates the per-value cost, so the end-to-end impact is within noise; the same applies to AR inserts/updates where network I/O prevails. The numbers are here so the trade-off is explicit.