Project

General

Profile

« Previous | Next » 

Revision 2450

sql.py: put_table(): Log summarizing debug messages with a level of 1.5 so they will be displayed even when the major SQL queries (which have a level of 2) are not shown

View differences:

sql.py
865 865
    for in_table_col in mapping.itervalues():
866 866
        assert isinstance(in_table_col, sql_gen.Col)
867 867
    
868
    def log_debug(msg): db.log_debug(msg, level=1.5)
869
    
868 870
    temp_prefix = out_table.name
869 871
    pkeys = sql_gen.Table(temp_prefix+'_pkeys')
870 872
    
......
876 878
    input_joins = [in_tables0]+[sql_gen.Join(v, {in_pkey: sql_gen.join_same})
877 879
        for v in in_tables_]
878 880
    
879
    db.log_debug('Joining together input tables')
881
    log_debug('Joining together input tables')
880 882
    # Place in new table for speed and so don't modify input if values edited
881 883
    in_table = sql_gen.Table(temp_prefix+'_in')
882 884
    flatten_cols = filter(sql_gen.is_table_col, mapping.values())
......
907 909
            limit=limit_ref[0], start=0)
908 910
    
909 911
    def log_exc(e):
910
        db.log_debug('Caught exception: '+exc.str_(e, first_line_only=True))
912
        log_debug('Caught exception: '+exc.str_(e, first_line_only=True))
911 913
    def remove_all_rows(msg):
912 914
        warnings.warn(DbWarning(msg))
913
        db.log_debug(msg.partition('\n')[0])
914
        db.log_debug('Returning NULL for all rows')
915
        log_debug(msg.partition('\n')[0])
916
        log_debug('Returning NULL for all rows')
915 917
        limit_ref[0] = 0 # just create an empty pkeys table
916 918
    def ignore(in_col, value):
917 919
        in_col_str = str(in_col)
918
        db.log_debug('Adding index on '+in_col_str+' to enable fast filtering')
920
        log_debug('Adding index on '+in_col_str+' to enable fast filtering')
919 921
        index_col(db, in_col)
920
        db.log_debug('Ignoring rows with '+in_col_str+' = '+repr(value))
922
        log_debug('Ignoring rows with '+in_col_str+' = '+repr(value))
921 923
    def remove_rows(in_col, value):
922 924
        ignore(in_col, value)
923 925
        cond = (in_col, sql_gen.CompareCond(value, '!='))
......
945 947
        else:
946 948
            insert_args.update(dict(returning=out_pkey, into=insert_out_pkeys))
947 949
        
948
        db.log_debug('Inserting new rows')
950
        log_debug('Inserting new rows')
949 951
        try:
950 952
            cur = insert_select(db, out_table, mapping.keys(),
951 953
                *mk_main_select(insert_joins, mapping.values()), **insert_args)
......
955 957
            
956 958
            old_join_cols = join_cols.copy()
957 959
            join_cols.update(util.dict_subset(mapping, e.cols))
958
            db.log_debug('Ignoring existing rows, comparing on '+str(join_cols))
960
            log_debug('Ignoring existing rows, comparing on '+str(join_cols))
959 961
            assert join_cols != old_join_cols # avoid infinite loops
960 962
        except NullValueException, e:
961 963
            log_exc(e)
......
982 984
    
983 985
    if has_joins:
984 986
        select_joins = input_joins+[sql_gen.Join(out_table, join_cols)]
985
        db.log_debug('Getting output pkeys of existing/inserted rows')
987
        log_debug('Getting output pkeys of existing/inserted rows')
986 988
        insert_into_pkeys(select_joins, pkeys_cols)
987 989
    else:
988 990
        add_row_num(db, insert_out_pkeys) # for joining with input pkeys
989 991
        
990
        db.log_debug('Getting input pkeys for rows in insert')
992
        log_debug('Getting input pkeys for rows in insert')
991 993
        run_query_into(db, *mk_main_select(input_joins, [in_pkey]),
992 994
            into=insert_in_pkeys)
993 995
        add_row_num(db, insert_in_pkeys) # for joining with output pkeys
......
995 997
        assert table_row_count(db, insert_out_pkeys) == table_row_count(db,
996 998
            insert_in_pkeys)
997 999
        
998
        db.log_debug('Joining together output and input pkeys')
1000
        log_debug('Joining together output and input pkeys')
999 1001
        pkey_joins = [insert_in_pkeys, sql_gen.Join(insert_out_pkeys,
1000 1002
            {row_num_col: sql_gen.join_same_not_null})]
1001 1003
        insert_into_pkeys(pkey_joins, pkeys_names)
1002 1004
    
1003
    db.log_debug('Adding pkey on returned pkeys table to enable fast joins')
1005
    log_debug('Adding pkey on returned pkeys table to enable fast joins')
1004 1006
    index_pkey(db, pkeys)
1005 1007
    
1006
    db.log_debug("Setting missing rows' pkeys to NULL")
1008
    log_debug("Setting missing rows' pkeys to NULL")
1007 1009
    missing_rows_joins = input_joins+[sql_gen.Join(pkeys,
1008 1010
        {in_pkey: sql_gen.join_same_not_null}, sql_gen.filter_out)]
1009 1011
        # must use join_same_not_null or query will take forever

Also available in: Unified diff