From 7ee8f448bfa054a3a18ce166854a6517dbe1f0a1 Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Wed, 9 Nov 2022 08:54:12 +0100 Subject: [PATCH] Add short code path for trivial comparison case --- lib/sqlalchemy/dialects/postgresql/ranges.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sqlalchemy/dialects/postgresql/ranges.py b/lib/sqlalchemy/dialects/postgresql/ranges.py index c35b6d89d4..5706487e4d 100644 --- a/lib/sqlalchemy/dialects/postgresql/ranges.py +++ b/lib/sqlalchemy/dialects/postgresql/ranges.py @@ -166,6 +166,10 @@ class Range(Generic[_T]): elif value2 is None: return 1 if value2_is_lower_bound else -1 + # Short path for trivial case + if bound1 == bound2 and value1 == value2: + return 0 + value1_inc = bound1 in {"[", "]"} value2_inc = bound2 in {"[", "]"} step = self._get_discrete_step() -- 2.47.3