Skip to content

Chg #960: Pass non-null and non-expression values only to dbTypecast() - #1197

Open
KalimeroMK wants to merge 4 commits into
yiisoft:masterfrom
KalimeroMK:pass-non-null-to-dbtypecast
Open

Chg #960: Pass non-null and non-expression values only to dbTypecast()#1197
KalimeroMK wants to merge 4 commits into
yiisoft:masterfrom
KalimeroMK:pass-non-null-to-dbtypecast

Conversation

@KalimeroMK

@KalimeroMK KalimeroMK commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Fix #960

Changes

  • null values are now passed through without calling ColumnInterface::dbTypecast(). The check is inlined at the call sites in AbstractDMLQueryBuilder (insert/update/batch) and AbstractColumnDefinitionBuilder::buildDefault().

  • No new API. The first version of this PR added a dbTypecast() wrapper function, but a wrapper that only filters null adds call overhead for no measurable gain (see benchmark), so the check was inlined instead.

  • DateTimeValueBuilder is untouched: DateTimeValue::$value is non-nullable by type.

  • Column implementations are intentionally left untouched. Two findings from the driver test matrices:

    • Expression is Stringable, so removing the ExpressionInterface arms silently stringifies expressions instead of passing them through (breaks DDL builders in db-pgsql/db-mssql that pass Expression default values directly).
    • Some driver implementations process expressions: Yiisoft\Db\Mssql\Column\BinaryColumn::dbTypecast() unwraps Param values into CONVERT(VARBINARY(MAX), ...) expressions, so expressions must keep reaching dbTypecast().

    Net effect: only null is 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:

approach time per round
current master (direct call) ~34 ms
wrapper function (first version of this PR) ~42 ms
check inlined at the call site (this PR) ~34.5 ms

The inlined check is within noise of master; the wrapper function added ~4 ns per call on trivial casts.

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.62%. Comparing base (f0b0d2b) to head (82017d6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1197   +/-   ##
=========================================
  Coverage     98.62%   98.62%           
- Complexity     1645     1649    +4     
=========================================
  Files           120      120           
  Lines          4288     4289    +1     
=========================================
+ Hits           4229     4230    +1     
  Misses           59       59           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.
@Tigrov

Tigrov commented Aug 22, 2026

Copy link
Copy Markdown
Member

But it seems the function that only checks for null doesn't make sense.

#960 (comment)

@KalimeroMK

Copy link
Copy Markdown
Contributor Author

Agreed that a null-only wrapper doesn't pay for itself — dropped the function and inlined the null check at the call sites in 82017d6. Benchmark is at parity with master now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pass to ColumnInterface::dbTypecast() non-null and non-expression values only

2 participants