db icon indicating copy to clipboard operation
db copied to clipboard

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

Open vjik opened this issue 8 months ago • 5 comments

Seems, all implementations of ColumnInterface::dbTypecast() checks value on null and ExpressionInterface and return it as is for those values:

if ($value === null || $value instanceof ExpressionInterface) {
    return $value;
}

We can check it before call dbTypecast() and simplify simplify both existing implementations and the creation of custom ones.

vjik avatar Apr 17 '25 08:04 vjik

Any ideas how to realize it?

Type casting should be fast, this is one of the bottlenecks of AR. In current realization it is faster then it was before. It's better to first check if the value matches the expected type, and then cast it to the expected type if necessary.

Tigrov avatar Apr 18 '25 07:04 Tigrov

function dbTypecast(ColumnInterface $column, mixed $value): mixed
{
    if ($value === null || $value instanceof ExpressionInterface) {
        return $value;
    }
    return $column->dbTypecast($value);
}

And instead of $column->dbTypecast($value) call dbTypecast($column, $value).

vjik avatar Apr 18 '25 08:04 vjik

What if I need type-casting for null values?

samdark avatar Apr 19 '25 19:04 samdark

What if I need type-casting for null values?

If such a case exists, then check only ExpressionInterface

vjik avatar Apr 28 '25 13:04 vjik

First, needs to benchmark the current and new approaches.

Tigrov avatar Apr 29 '25 03:04 Tigrov