details: https://code.tryton.org/tryton/commit/4586ac328b3d
branch: default
user: Cédric Krier <[email protected]>
date: Wed Jul 22 14:36:17 2026 +0200
description:
Do not create indexes if they already exist
The `IF NOT EXISTS` clause does not prevent PostgreSQL from taking a
ShareLock
on the table if the index exists.
Closes #14966
diffstat:
trytond/trytond/backend/postgresql/table.py | 17 +++++++++--------
1 files changed, 9 insertions(+), 8 deletions(-)
diffs (27 lines):
diff -r 752835f225ff -r 4586ac328b3d trytond/trytond/backend/postgresql/table.py
--- a/trytond/trytond/backend/postgresql/table.py Mon Jul 27 11:55:35
2026 +0200
+++ b/trytond/trytond/backend/postgresql/table.py Wed Jul 22 14:36:17
2026 +0200
@@ -569,14 +569,15 @@
if (idx_valid := cursor.fetchone()) and not idx_valid[0]:
cursor.execute(
SQL("DROP INDEX {}").format(Identifier(name)))
- cursor.execute(
- SQL('CREATE INDEX {} IF NOT EXISTS {} ON {} USING {}')
- .format(
- SQL('CONCURRENTLY' if concurrently else ''),
- Identifier(name),
- Identifier(self.table_name),
- query),
- params)
+ if not idx_valid or not idx_valid[0]:
+ cursor.execute(
+ SQL('CREATE INDEX {} {} ON {} USING {}')
+ .format(
+ SQL('CONCURRENTLY' if concurrently else ''),
+ Identifier(name),
+ Identifier(self.table_name),
+ query),
+ params)
old.discard(name)
for name in old:
if name.startswith('idx_') or name.endswith('_index'):