Projet

Général

Profil

0001-sql-add-indexes-on-snapshots-table-65485.patch

Pierre Ducroquet, 23 mai 2022 16:35

Télécharger (2,06 ko)

Voir les différences:

Subject: [PATCH] sql: add indexes on snapshots table (#65485)

 wcs/sql.py | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
wcs/sql.py
1340 1340
    for field in existing_fields - needed_fields:
1341 1341
        cur.execute('''ALTER TABLE %s DROP COLUMN %s''' % (table_name, field))
1342 1342

  
1343
    # add indexes
1344
    cur.execute(
1345
        '''SELECT indexname 
1346
            FROM pg_indexes 
1347
            WHERE schemaname = 'public'
1348
              AND tablename = %s''',
1349
        (table_name,),
1350
    )
1351
    existing_indexes = {x[0] for x in cur.fetchall()}
1352
    if ('%s_pkey' % table_name) not in existing_indexes:
1353
        cur.execute('''ALTER TABLE %s ADD PRIMARY KEY (id)''' % table_name)
1354
    if ('%s_object_by_date' % table_name) not in existing_indexes:
1355
        cur.execute(
1356
            '''CREATE INDEX %s_object_by_date ON %s(object_type, object_id, timestamp DESC)'''
1357
            % (table_name, table_name)
1358
        )
1343 1359
    conn.commit()
1344 1360
    cur.close()
1345 1361

  
......
4084 4100
# latest migration, number + description (description is not used
4085 4101
# programmaticaly but will make sure git conflicts if two migrations are
4086 4102
# separately added with the same number)
4087
SQL_LEVEL = (62, 're-setweight on formdata & user indexation')
4103
SQL_LEVEL = (63, 'add index on snapshot table')
4088 4104

  
4089 4105

  
4090 4106
def migrate_global_views(conn, cur):
......
4266 4282
                continue
4267 4283
            for formdata in formdef.data_class().select_iterator():
4268 4284
                formdata._set_auto_fields(cur)  # build digests
4269
    if sql_level < 54:
4285
    if sql_level < 63:
4270 4286
        # 42: create snapshots table
4271 4287
        # 54: add patch column
4288
        # 63: add index
4272 4289
        do_snapshots_table()
4273 4290
    if sql_level < 53:
4274 4291
        # 47: store LoggedErrors in SQL
4275
-