pgsql: Reduce an unnecessary O(N^3) loop in lexer. - Mailing list pgsql-committers

From Andrew Gierth
Subject pgsql: Reduce an unnecessary O(N^3) loop in lexer.
Date
Msg-id E1fswXG-0001OV-N1@gemulon.postgresql.org
Whole thread Raw
List 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
------
master

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

Modified Files
--------------
src/backend/parser/scan.l         | 27 ++++++++++++++++++++-------
src/fe_utils/psqlscan.l           | 27 ++++++++++++++++++++-------
src/interfaces/ecpg/preproc/pgc.l | 29 +++++++++++++++++++++--------
3 files changed, 61 insertions(+), 22 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: In libpq, don't look up all the hostnames at once.
Next
From: Andres Freund
Date:
Subject: pgsql: Deduplicate code between slot_getallattrs() andslot_getsomeattr