pgsql: Reduce an unnecessary O(N^3) loop in lexer.

From: Andrew Gierth <rhodiumtoad(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Reduce an unnecessary O(N^3) loop in lexer.
Date: 2018-08-23 20:48:54
Message-ID: E1fswXG-0001Ol-Q7@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Reduce an unnecessary O(N^3) loop in lexer.

The lexer's handling of operators contained an O(N^3) hazard when
dealing with long strings of + or - characters; it seems hard to
prevent this case from being O(N^2), but the additional N multiplier
was not needed.

Backpatch all the way since this has been there since 7.x, and it
presents at least a mild hazard in that trying to do Bind, PREPARE or
EXPLAIN on a hostile query could take excessive time (without
honouring cancels or timeouts) even if the query was never executed.

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ad871a9d78841592938a0b24cc961fd1d4185607

Modified Files
--------------
src/backend/parser/scan.l | 29 +++++++++++++++++++++--------
src/bin/psql/psqlscan.l | 29 +++++++++++++++++++++--------
src/interfaces/ecpg/preproc/pgc.l | 29 +++++++++++++++++++++--------
3 files changed, 63 insertions(+), 24 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2018-08-23 23:59:35 pgsql: Deduplicate code between slot_getallattrs() and slot_getsomeattr
Previous Message Tom Lane 2018-08-23 20:40:00 pgsql: In libpq, don't look up all the hostnames at once.