Project

General

Profile

« Previous | Next » 

Revision 2903

sql.py: mk_select(): Filtering on no match: Lock the joined table in EXCLUSIVE mode to prevent concurrent duplicate keys when used with INSERT SELECT

View differences:

sql.py
562 562
        if join_.type_ is sql_gen.filter_out: # filter no match
563 563
            conds.append((sql_gen.Col(table_not_null_col(db, table), table),
564 564
                sql_gen.CompareCond(None, '~=')))
565
            # Prevent concurrent duplicate keys when used with INSERT SELECT
566
            lock_table(db, sql_gen.underlying_table(table), 'EXCLUSIVE')
565 567
        
566 568
        query += '\n'+join_.to_str(db, left_table)
567 569
        
......
1273 1275
        
1274 1276
        has_joins = join_cols != {}
1275 1277
        
1278
        log_debug('Trying to insert new rows')
1279
        
1276 1280
        # Prepare to insert new rows
1277 1281
        insert_joins = input_joins[:] # don't modify original!
1278 1282
        insert_args = dict(recover=True, cacheable=False)
......
1283 1287
            insert_args.update(dict(returning=out_pkey, into=insert_out_pkeys))
1284 1288
        main_select = mk_main_select(insert_joins, mapping.values())
1285 1289
        
1286
        log_debug('Trying to insert new rows')
1287 1290
        try:
1288 1291
            cur = insert_select(db, out_table, mapping.keys(), main_select,
1289 1292
                **insert_args)

Also available in: Unified diff