Fixed query result caching when FetchMode::COLUMN is used #3686
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.
Internally,
ArrayStatement
expects every row to be represented as an array regardless of the fetch mode, howeverFetchMode::COLUMN
produces one value per row.This issue reveals a more fundamental problem: the cached result set is formed from the data represented to the currently used fetch mode and may not contain all the data needed for fetching from the same statement in a different mode. It means that the behavior of the cache may be unpredictable when the original and subsequent fetch modes are different. For example:
SELECT foo, bar FROM table
;$stmt->fetchAll(FetchMode::COLUMN)
;$stmt->fetchAll(FetchMode::ASSOC)
. The second query will contain only one column from the cache.SELECT t1.id, t2.id FROM t1 JOIN t2
;$stmt->fetchAll(FetchMode::ASSOCIATIVE)
;$stmt->fetchAll(FetchMode::NUMERIC)
. The second query will contain only one column from the cache.