smi2 / phpClickHouse

php ClickHouse wrapper
MIT License
750 stars 139 forks source link

Fixed silent error occurrence on 200 http status code (ExceptionWhileProcessing query error) #205

Closed anathex closed 9 months ago

anathex commented 9 months ago

Fixes issue https://github.com/smi2/phpClickHouse/issues/144

This problem occurs on partially flushed response to the client with 200 status code with further ClickHouse exception. All details in StatementTest::testIsErrorWithOkStatusCode

I've used _pregmatch instead of stripos (suggested in https://github.com/smi2/phpClickHouse/issues/144) because regexes precompiles and further calls are much cheaper (about 10 times in my tests of clickhouse error regex). Also stripos speed only 30% faster (and less) than first call of _pregmatch on string from 10MB to 1000MB.

anathex commented 9 months ago

This solution still has a caveat that result of correct query like this will be considered as error: SELECT exception FROM system.query_log WHERE event_date = '2024-01-16' AND exception_code > 0 LIMIT 10;

In my opinion that in real life applications this kind of query is less likely to occur than silent "error" on not sufficient memory during query execution. After all having explicit error is much better than silent "successful" query, that might be causing unpleasant side-effects in business logic.