pgsql: Add fast path for validating UTF-8 text

Поиск
Список
Период
Сортировка
От John Naylor
Тема pgsql: Add fast path for validating UTF-8 text
Дата
Msg-id E1mzJMd-0007LH-5j@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Add fast path for validating UTF-8 text

Our previous validator used a traditional algorithm that performed
comparison and branching one byte at a time. It's useful in that
we always know exactly how many bytes we have validated, but that
precision comes at a cost. Input validation can show up prominently
in profiles of COPY FROM, and future improvements to COPY FROM such
as parallelism or faster line parsing will put more pressure on input
validation. Hence, add fast paths for both ASCII and multibyte UTF-8:

Use bitwise operations to check 16 bytes at a time for ASCII. If
that fails, use a "shift-based" DFA on those bytes to handle the
general case, including multibyte. These paths are relatively free
of branches and thus robust against all kinds of byte patterns. With
these algorithms, UTF-8 validation is several times faster, depending
on platform and the input byte distribution.

The previous coding in pg_utf8_verifystr() is retained for short
strings and for when the fast path returns an error.

Review, performance testing, and additional hacking by: Heikki
Linakangas, Vladimir Sitnikov, Amit Khandekar, Thomas Munro, and
Greg Stark

Discussion:
https://www.postgresql.org/message-id/CAFBsxsEV_SzH%2BOLyCiyon%3DiwggSyMh_eF6A3LU2tiWf3Cy2ZQg%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/911588a3f816d875261d8f7d89e2517978831cd5

Modified Files
--------------
src/common/wchar.c                       | 215 +++++++++++++++++++++++++++++++
src/include/mb/pg_wchar.h                |  53 ++++++++
src/test/regress/expected/conversion.out | 169 ++++++++++++++++++++++++
src/test/regress/sql/conversion.sql      | 133 +++++++++++++++++++
4 files changed, 570 insertions(+)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: pgsql: pg_dump: Refactor getIndexes()
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Add a \getenv command to psql.