q = s.query(cls) or_cond = [] for x in id_batch:
pkf = [text(f + "=='" + v + "'") for f,v in zip(cls.SQL_PK, x)] and_cond = (and_(*pkf)) or_cond.append(and_cond)
q = q.filter(or_(*or_cond)).delete(synchronize_session=False)cols = [getattr(cls, colname) for colname in cls.SQL_PK]
%prun import db_api_lib.del_test 1421296 function calls (1277536 primitive calls) in 620.434 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function) 12 615.512 51.293 615.512 51.293 {method 'execute' of 'pyodbc.Cursor' objects}208876/208271 0.316 0.000 0.332 0.000 {built-in method isinstance}96876/96874 0.184 0.000 0.185 0.000 {built-in method getattr} 11123 0.137 0.000 0.242 0.000 elements.py:2927(__init__) 38970/10 0.136 0.000 1.502 0.150 visitors.py:75(_compiler_dispatch) 11123 0.128 0.000 0.397 0.000 elements.py:861(__init__)44492/11123 0.127 0.000 1.504 0.000 operators.py:297(__eq__) 5568 0.116 0.000 0.617 0.000 elements.py:1860(_construct) 11132 0.113 0.000 0.246 0.000 compiler.py:676(visit_column) 11123 0.111 0.000 1.039 0.000 compiler.py:1040(_generate_generic_binary) 5567 0.108 0.000 0.108 0.000 {method 'fetchone' of 'pyodbc.Cursor' objects} 11123 0.099 0.000 0.646 0.000 default_comparator.py:290(_check_literal) 16684 0.095 0.000 0.195 0.000 operators.py:1007(is_precedent) 11123 0.094 0.000 1.010 0.000 default_comparator.py:22(_boolean_compare)33375/11129 0.090 0.000 1.445 0.000 {built-in method eq} 11123 0.075 0.000 0.465 0.000 compiler.py:1164(visit_bindparam) 1 0.075 0.075 619.467 619.467 db_base.py:138(dict_delete) 11139 0.073 0.000 0.331 0.000 base.py:1128(decorate) 68831 0.070 0.000 0.070 0.000 {method 'get' of 'dict' objects} 1 0.068 0.068 620.471 620.471 del_test.py:1(<module>)22250/5567 0.067 0.000 1.482 0.000 compiler.py:806(<genexpr>) 11125 0.066 0.000 0.102 0.000 compiler.py:1265(_process_anon) 11123 0.065 0.000 1.179 0.000 compiler.py:1006(visit_binary) 11123 0.063 0.000 1.263 0.000 base.py:1306(visit_binary) 11123 0.061 0.000 0.458 0.000 elements.py:3818(_bind_param) 22269 0.058 0.000 0.097 0.000 compiler.py:2901(quote) 11125 0.058 0.000 0.261 0.000 compiler.py:1246(_truncated_identifier) 11123 0.058 0.000 1.299 0.000 annotation.py:100(__eq__) 11123 0.056 0.000 1.066 0.000 type_api.py:60(operate) 56386 0.055 0.000 0.055 0.000 {method 'append' of 'list' objects} 11126 0.055 0.000 0.168 0.000 elements.py:3962(__new__) 11123 0.055 0.000 0.334 0.000 compiler.py:1233(_truncate_bindparam) 11125 0.054 0.000 0.192 0.000 elements.py:4073(apply_map) 11206 0.051 0.000 0.089 0.000 elements.py:3918(__new__) 22246 0.051 0.000 0.051 0.000 elements.py:640(self_group)22250/5567 0.049 0.000 1.493 0.000 compiler.py:804(<genexpr>) 2 0.048 0.024 0.049 0.024 {built-in method connect} 11123 0.047 0.000 1.386 0.000 properties.py:269(operate)8689/3128 0.045 0.000 1.508 0.000 {method 'join' of 'str' objects} 11123 0.045 0.000 0.076 0.000 compiler.py:959(_get_operator_dispatch) 11123 0.045 0.000 0.056 0.000 compiler.py:1271(bindparam_string) 11123 0.040 0.000 0.411 0.000 annotation.py:78(_compiler_dispatch)15610/15322 0.038 0.000 0.043 0.000 {built-in method hasattr} 5567 0.038 0.000 0.294 0.000 elements.py:1883(<listcomp>) 11125 0.036 0.000 0.138 0.000 _collections.py:728(__missing__) 16691 0.035 0.000 0.090 0.000 elements.py:4216(_expression_literal_as_text) 5561 0.035 0.000 1.539 0.000 db_base.py:174(<listcomp>) 16704 0.033 0.000 0.055 0.000 elements.py:4220(_literal_as_text) 11123 0.033 0.000 0.073 0.000 type_api.py:504(coerce_compared_value)31584/31469 0.031 0.000 0.032 0.000 {built-in method len} 11123 0.030 0.000 0.165 0.000 elements.py:2986(self_group)
5562 0.030 0.000 0.187 0.000 result.py:1156(fetchone) 11131 0.030 0.000 0.077 0.000 compiler.py:494(<genexpr>) 11123 0.029 0.000 0.047 0.000 type_api.py:452(_cached_bind_processor) ncalls tottime percall cumtime percall filename:lineno(function) 16 1053.794 65.862 1053.794 65.862 {method 'execute' of 'pyodbc.Cursor' objects}348916/348311 0.539 0.000 0.556 0.000 {built-in method isinstance}160920/160918 0.313 0.000 0.313 0.000 {built-in method getattr} 19123 0.282 0.000 0.471 0.000 elements.py:2927(__init__) 66982/14 0.234 0.000 2.561 0.183 visitors.py:75(_compiler_dispatch) 19123 0.231 0.000 0.702 0.000 elements.py:861(__init__)76492/19123 0.228 0.000 2.740 0.000 operators.py:297(__eq__) 9572 0.213 0.000 1.092 0.000 elements.py:1860(_construct) 19123 0.201 0.000 1.878 0.000 default_comparator.py:22(_boolean_compare) 19132 0.194 0.000 0.424 0.000 compiler.py:676(visit_column) 9567 0.190 0.000 0.190 0.000 {method 'fetchone' of 'pyodbc.Cursor' objects} 19123 0.183 0.000 1.761 0.000 compiler.py:1040(_generate_generic_binary) 19123 0.180 0.000 1.155 0.000 default_comparator.py:290(_check_literal) 28684 0.171 0.000 0.347 0.000 operators.py:1007(is_precedent)57379/19133 0.157 0.000 2.634 0.000 {built-in method eq} 19123 0.133 0.000 0.786 0.000 compiler.py:1164(visit_bindparam) 19143 0.123 0.000 0.566 0.000 base.py:1128(decorate) 116835 0.120 0.000 0.120 0.000 {method 'get' of 'dict' objects} 1 0.117 0.117 1061.906 1061.906 del_test.py:1(<module>) 19123 0.116 0.000 2.005 0.000 compiler.py:1006(visit_binary) 19123 0.114 0.000 0.816 0.000 elements.py:3818(_bind_param) 19123 0.113 0.000 2.154 0.000 base.py:1306(visit_binary) 19125 0.111 0.000 0.173 0.000 compiler.py:1265(_process_anon)38254/9571 0.111 0.000 2.528 0.000 compiler.py:806(<genexpr>) 38273 0.102 0.000 0.167 0.000 compiler.py:2901(quote) 19123 0.099 0.000 1.976 0.000 type_api.py:60(operate) 19123 0.098 0.000 0.565 0.000 compiler.py:1233(_truncate_bindparam) 19125 0.097 0.000 0.438 0.000 compiler.py:1246(_truncated_identifier) 19126 0.097 0.000 0.295 0.000 elements.py:3962(__new__) 38246 0.093 0.000 0.093 0.000 elements.py:640(self_group) 19123 0.092 0.000 2.376 0.000 annotation.py:100(__eq__) 19125 0.092 0.000 0.321 0.000 elements.py:4073(apply_map) 19206 0.089 0.000 0.155 0.000 elements.py:3918(__new__) 88398 0.087 0.000 0.087 0.000 {method 'append' of 'list' objects}38254/9571 0.084 0.000 2.547 0.000 compiler.py:804(<genexpr>) 19123 0.082 0.000 2.526 0.000 properties.py:269(operate) 19123 0.075 0.000 0.128 0.000 compiler.py:959(_get_operator_dispatch)12693/3132 0.073 0.000 2.566 0.001 {method 'join' of 'str' objects} 19123 0.069 0.000 0.704 0.000 annotation.py:78(_compiler_dispatch) 19123 0.068 0.000 0.087 0.000 compiler.py:1271(bindparam_string) 1 0.068 0.068 1060.665 1060.665 db_base.py:138(dict_delete) 9571 0.065 0.000 0.520 0.000 elements.py:1883(<listcomp>) 19123 0.065 0.000 2.041 0.000 <string>:1(<lambda>) 9561 0.062 0.000 2.802 0.000 db_base.py:174(<listcomp>)23610/23322 0.062 0.000 0.068 0.000 {built-in method hasattr} 28695 0.061 0.000 0.156 0.000 elements.py:4216(_expression_literal_as_text) 19123 0.059 0.000 0.129 0.000 type_api.py:504(coerce_compared_value) 28716 0.057 0.000 0.095 0.000 elements.py:4220(_literal_as_text) 19125 0.057 0.000 0.229 0.000 _collections.py:728(__missing__) 19123 0.053 0.000 0.294 0.000 elements.py:2986(self_group) 9562 0.053 0.000 0.325 0.000 result.py:1156(fetchone) 19135 0.053 0.000 0.134 0.000 compiler.py:494(<genexpr>) 19123 0.050 0.000 0.070 0.000 sqltypes.py:2608(_resolve_value_to_type) 19123 0.050 0.000 0.082 0.000 type_api.py:452(_cached_bind_processor)
ncalls tottime percall cumtime percall filename:lineno(function) 16 1.840 0.115 1.840 0.115 {method 'execute' of 'pyodbc.Cursor' objects} 9572 0.196 0.000 0.788 0.000 elements.py:1860(_construct) 57700 0.189 0.000 0.189 0.000 {method 'sub' of '_sre.SRE_Pattern' objects} 9567 0.185 0.000 0.185 0.000 {method 'fetchone' of 'pyodbc.Cursor' objects}100329/99724 0.125 0.000 0.142 0.000 {built-in method isinstance} 19123 0.120 0.000 0.200 0.000 elements.py:1225(__init__) 1 0.117 0.117 5.042 5.042 del_test.py:1(<module>) 19123 0.100 0.000 0.222 0.000 compiler.py:737(visit_textclause)38254/9571 0.099 0.000 0.566 0.000 compiler.py:806(<genexpr>) 28738/14 0.096 0.000 0.598 0.043 visitors.py:75(_compiler_dispatch) 19123 0.086 0.000 0.286 0.000 elements.py:1240(_create_text)38254/9571 0.079 0.000 0.585 0.000 compiler.py:804(<genexpr>)12693/3132 0.068 0.000 0.603 0.000 {method 'join' of 'str' objects} 1 0.065 0.065 3.811 3.811 db_base.py:138(dict_delete) 9561 0.062 0.000 0.398 0.000 db_base.py:178(<listcomp>) 9571 0.060 0.000 0.240 0.000 elements.py:1883(<listcomp>) 28695 0.060 0.000 0.156 0.000 elements.py:4216(_expression_literal_as_text) 28716 0.058 0.000 0.096 0.000 elements.py:4220(_literal_as_text) 9562 0.052 0.000 0.317 0.000 result.py:1156(fetchone) 9562 0.051 0.000 0.105 0.000 operators.py:1007(is_precedent) 50154 0.050 0.000 0.050 0.000 {method 'append' of 'list' objects} 19123 0.050 0.000 0.336 0.000 <string>:1(text) 9572 0.048 0.000 0.203 0.000 elements.py:1865(<listcomp>)27063/27061 0.047 0.000 0.048 0.000 {built-in method getattr} 2 0.044 0.022 0.045 0.022 {built-in method connect} 9571/10 0.037 0.000 0.595 0.059 compiler.py:797(visit_clauselist) 9562 0.037 0.000 0.534 0.000 elements.py:1894(and_) 28683 0.036 0.000 0.036 0.000 del_test.py:14(<genexpr>) 9562 0.036 0.000 0.057 0.000 result.py:1085(process_rows) 9561 0.029 0.000 0.159 0.000 elements.py:1971(self_group)28504/28389 0.028 0.000 0.028 0.000 {built-in method len} 125 0.026 0.000 0.026 0.000 {built-in method loads} 750/724 0.026 0.000 0.340 0.000 {built-in method __build_class__} 9561 0.025 0.000 0.560 0.000 <string>:1(and_) 9561 0.024 0.000 0.130 0.000 elements.py:1818(self_group) 9562 0.024 0.000 0.341 0.000 result.py:868(__iter__) 9564 0.022 0.000 0.207 0.000 result.py:1053(_fetchone_impl) 9572 0.022 0.000 0.032 0.000 _collections.py:788(coerce_generator_arg) 9562 0.021 0.000 0.021 0.000 result.py:1098(<listcomp>) 19122 0.021 0.000 0.021 0.000 elements.py:1601(self_group) 21232 0.021 0.000 0.021 0.000 {method 'get' of 'dict' objects} 10 0.019 0.002 0.019 0.002 {method 'commit' of 'pyodbc.Connection' objects} 19123 0.019 0.000 0.019 0.000 compiler.py:734(post_process_text) 290/1 0.016 0.000 5.044 5.044 {built-in method exec} 68 0.015 0.000 0.042 0.001 inspect.py:264(getmembers) 361 0.014 0.000 0.103 0.000 inspect.py:943(getfullargspec) 2884 0.014 0.000 0.020 0.000 sre_parse.py:197(__next) 10420 0.013 0.000 0.013 0.000 {built-in method __new__ of type object at 0x7f9abdca4e40} 9561 0.012 0.000 0.012 0.000 result.py:168(keys) 361 0.012 0.000 0.065 0.000 inspect.py:2383(from_function) 714 0.010 0.000 0.018 0.000 inspect.py:1056(formatargspec) 296 0.010 0.000 0.041 0.000 <frozen importlib._bootstrap>:2016(find_spec)4486/4198 0.010 0.000 0.015 0.000 {built-in method hasattr} 130/38 0.010 0.000 0.044 0.001 sre_parse.py:448(_parse) @classmethod def dict_delete2(cls, dict_in): """ Delete records from the database based on a dictionary keyed by PK tuple """ s = dbc.get_session() keys_in = ["-".join(k) for k in dict_in.keys()] batch_size = 1000 cols = [getattr(cls, colname) for colname in cls.SQL_PK] cols_dash = [] for col in cols: cols_dash.append(col) cols_dash.append('-')
cols_dash = cols_dash[:-1]
print(cols_dash) while len(keys_in): id_batch = keys_in[:batch_size] # print(id_batch) del keys_in[:batch_size] q = s.query(cls)
q = q.filter(func.concat(*cols_dash).in_(id_batch)).delete(synchronize_session=False)
s.commit()
s.close() 673960 function calls (659542 primitive calls) in 2315.534 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function) 16 2312.810 144.551 2312.810 144.551 {method 'execute' of 'pyodbc.Cursor' objects} 9567 0.186 0.000 0.186 0.000 {method 'fetchone' of 'pyodbc.Cursor' objects} 9572 0.166 0.000 0.433 0.000 elements.py:861(__init__) 1 0.119 0.119 2315.536 2315.536 del_test.py:1(<module>)62442/61837 0.101 0.000 0.118 0.000 {built-in method isinstance} 9572 0.068 0.000 0.407 0.000 compiler.py:1164(visit_bindparam) 9575 0.062 0.000 0.171 0.000 elements.py:3962(__new__) 9561 0.060 0.000 0.492 0.000 functions.py:436(_bind_param) 9574 0.059 0.000 0.090 0.000 compiler.py:1265(_process_anon) 9574 0.054 0.000 0.227 0.000 compiler.py:1246(_truncated_identifier) 10 0.052 0.005 0.738 0.074 default_comparator.py:110(_in_impl) 9562 0.051 0.000 0.319 0.000 result.py:1156(fetchone) 9655 0.049 0.000 0.084 0.000 elements.py:3918(__new__) 9572 0.047 0.000 0.291 0.000 compiler.py:1233(_truncate_bindparam) 2 0.047 0.023 0.048 0.024 {built-in method connect} 9574 0.047 0.000 0.163 0.000 elements.py:4073(apply_map) 10 0.042 0.004 0.042 0.004 {method 'commit' of 'pyodbc.Connection' objects} 40649 0.040 0.000 0.040 0.000 {method 'append' of 'list' objects} 9572 0.039 0.000 0.049 0.000 compiler.py:1271(bindparam_string) 9696/14 0.039 0.000 0.521 0.037 visitors.py:75(_compiler_dispatch) 9611 0.039 0.000 0.485 0.000 compiler.py:806(<genexpr>)14090/13802 0.037 0.000 0.042 0.000 {built-in method hasattr}17697/17695 0.037 0.000 0.038 0.000 {built-in method getattr} 9562 0.037 0.000 0.058 0.000 result.py:1085(process_rows) 9561 0.036 0.000 0.080 0.000 elements.py:4254(_is_literal) 28683 0.036 0.000 0.036 0.000 del_test.py:14(<genexpr>) 9562 0.030 0.000 0.068 0.000 type_api.py:504(coerce_compared_value) 22 0.029 0.001 0.103 0.005 elements.py:1784(<listcomp>) 12713 0.027 0.000 0.536 0.000 {method 'join' of 'str' objects} 9572 0.026 0.000 0.038 0.000 sqltypes.py:2608(_resolve_value_to_type) 16 0.026 0.002 0.026 0.002 {method 'close' of 'pyodbc.Cursor' objects} 9574 0.026 0.000 0.116 0.000 _collections.py:728(__missing__) 9584 0.026 0.000 0.067 0.000 compiler.py:494(<genexpr>) 21325 0.025 0.000 0.025 0.000 {method 'get' of 'dict' objects} 125 0.025 0.000 0.025 0.000 {built-in method loads} 750/724 0.025 0.000 0.338 0.000 {built-in method __build_class__} 9572 0.025 0.000 0.041 0.000 type_api.py:452(_cached_bind_processor) 9562 0.024 0.000 0.343 0.000 result.py:868(__iter__) 9564 0.022 0.000 0.209 0.000 result.py:1053(_fetchone_impl) 9603 0.022 0.000 0.022 0.000 elements.py:640(self_group) 10206 0.021 0.000 0.021 0.000 {method 'split' of 'str' objects} 9562 0.021 0.000 0.021 0.000 result.py:1098(<listcomp>) 9611 0.021 0.000 0.506 0.000 compiler.py:804(<genexpr>) 10421 0.020 0.000 0.020 0.000 {built-in method __new__ of type object at 0x7fc6ee607e40} 9603 0.020 0.000 0.053 0.000 elements.py:4216(_expression_literal_as_text) 9624 0.019 0.000 0.033 0.000 elements.py:4220(_literal_as_text)18953/18838 0.019 0.000 0.019 0.000 {built-in method len} 10209 0.016 0.000 0.016 0.000 weakref.py:364(__getitem__) 290/1 0.016 0.000 2315.538 2315.538 {built-in method exec} 68 0.016 0.000 0.042 0.001 inspect.py:264(getmembers) 361 0.014 0.000 0.102 0.000 inspect.py:943(getfullargspec) 2884 0.014 0.000 0.019 0.000 sre_parse.py:197(__next) 9561 0.014 0.000 0.014 0.000 result.py:168(keys) 361 0.012 0.000 0.064 0.000 inspect.py:2383(from_function)
2328928 function calls (2085124 primitive calls) in 1084.925 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function) 26 1074.733 41.336 1074.733 41.336 {method 'execute' of 'pyodbc.Cursor' objects} 2 0.871 0.436 0.872 0.436 {built-in method connect}349128/348523 0.556 0.000 0.573 0.000 {built-in method isinstance} 26 0.502 0.019 0.502 0.019 {method 'close' of 'pyodbc.Cursor' objects} 20 0.485 0.024 0.485 0.024 {method 'commit' of 'pyodbc.Connection' objects}161062/161060 0.317 0.000 0.318 0.000 {built-in method getattr} 19123 0.259 0.000 0.789 0.000 elements.py:861(__init__) 9567 0.258 0.000 0.258 0.000 {method 'fetchone' of 'pyodbc.Cursor' objects}76492/19123 0.248 0.000 2.842 0.000 operators.py:297(__eq__) 67012/24 0.236 0.000 2.601 0.108 visitors.py:75(_compiler_dispatch) 19123 0.234 0.000 0.424 0.000 elements.py:2927(__init__) 9582 0.213 0.000 1.104 0.000 elements.py:1860(_construct) 19132 0.205 0.000 0.435 0.000 compiler.py:676(visit_column) 19123 0.189 0.000 1.806 0.000 compiler.py:1040(_generate_generic_binary) 19123 0.183 0.000 1.263 0.000 default_comparator.py:290(_check_literal)57389/19143 0.173 0.000 2.732 0.000 {built-in method eq} 19123 0.171 0.000 1.912 0.000 default_comparator.py:22(_boolean_compare) 28684 0.169 0.000 0.346 0.000 operators.py:1007(is_precedent) 19126 0.143 0.000 0.352 0.000 elements.py:3962(__new__) 19123 0.129 0.000 0.795 0.000 compiler.py:1164(visit_bindparam) 19123 0.128 0.000 0.918 0.000 elements.py:3818(_bind_param) 19153 0.126 0.000 0.581 0.000 base.py:1128(decorate) 1 0.125 0.125 1084.925 1084.925 del_test.py:1(<module>) 116845 0.121 0.000 0.121 0.000 {method 'get' of 'dict' objects}38264/9581 0.115 0.000 2.567 0.000 compiler.py:806(<genexpr>) 19123 0.113 0.000 2.048 0.000 compiler.py:1006(visit_binary) 19125 0.113 0.000 0.174 0.000 compiler.py:1265(_process_anon) 19125 0.109 0.000 0.451 0.000 compiler.py:1246(_truncated_identifier) 19123 0.108 0.000 2.457 0.000 annotation.py:100(__eq__) 19123 0.107 0.000 2.190 0.000 base.py:1306(visit_binary) 19123 0.104 0.000 2.015 0.000 type_api.py:60(operate) 38283 0.101 0.000 0.167 0.000 compiler.py:2901(quote) 19123 0.095 0.000 0.577 0.000 compiler.py:1233(_truncate_bindparam) 19206 0.094 0.000 0.163 0.000 elements.py:3918(__new__) 19125 0.093 0.000 0.323 0.000 elements.py:4073(apply_map) 38246 0.091 0.000 0.091 0.000 elements.py:640(self_group) 88460 0.088 0.000 0.088 0.000 {method 'append' of 'list' objects} 19123 0.084 0.000 2.621 0.000 properties.py:269(operate)38264/9581 0.084 0.000 2.586 0.000 compiler.py:804(<genexpr>) 19123 0.082 0.000 0.732 0.000 annotation.py:78(_compiler_dispatch)12703/3142 0.076 0.000 2.605 0.001 {method 'join' of 'str' objects} 19123 0.075 0.000 0.129 0.000 compiler.py:959(_get_operator_dispatch) 1 0.071 0.071 1082.250 1082.250 db_base.py:172(dict_delete) 19123 0.070 0.000 0.089 0.000 compiler.py:1271(bindparam_string) 19123 0.070 0.000 2.085 0.000 <string>:1(<lambda>) 9581 0.067 0.000 0.520 0.000 elements.py:1883(<listcomp>) 9561 0.064 0.000 2.905 0.000 db_base.py:208(<listcomp>)23611/23323 0.062 0.000 0.067 0.000 {built-in method hasattr} 28705 0.061 0.000 0.159 0.000 elements.py:4216(_expression_literal_as_text) 28746 0.058 0.000 0.098 0.000 elements.py:4220(_literal_as_text) 19123 0.058 0.000 0.130 0.000 type_api.py:504(coerce_compared_value) 9562 0.056 0.000 0.416 0.000 result.py:1156(fetchone) 19125 0.056 0.000 0.230 0.000 _collections.py:728(__missing__) 19123 0.054 0.000 0.296 0.000 elements.py:2986(self_group)
501 - 0:24:35.558103491 - 0:24:37.197976481 - 0:24:38.909318471 - 0:24:40.645801461 - 0:24:41.954807451 - 0:24:43.628955441 - 0:24:45.246469431 - 0:24:46.662228421 - 0:24:48.192343411 - 0:24:49.839395401 - 0:24:51.513340391 - 0:24:53.153668381 - 0:24:54.836501371 - 0:24:56.372331361 - 0:24:58.034510351 - 0:24:59.714655341 - 0:25:01.401695331 - 0:25:03.026082321 - 0:25:04.657724311 - 0:25:06.324783301 - 0:25:07.946133291 - 0:25:09.347907281 - 0:25:11.000936271 - 0:25:12.640046261 - 0:25:14.281258251 - 0:25:15.939942241 - 0:25:17.651838231 - 0:25:19.307522221 - 0:25:20.931354211 - 0:25:22.589152201 - 0:25:24.223949191 - 0:25:25.868513181 - 0:25:27.540003171 - 0:25:29.198259161 - 0:25:30.492486151 - 0:25:31.778539141 - 0:25:33.292928131 - 0:25:34.966223121 - 0:25:36.623493111 - 0:25:38.276205101 - 0:25:39.99652791 - 0:25:41.37433881 - 0:25:43.01119271 - 0:25:44.63965661 - 0:25:46.29367251 - 0:25:47.95412941 - 0:25:49.66346331 - 0:25:51.33362021 - 0:25:52.84247911 - 0:25:54.4890941 - 0:25:56.1093710 - 0:25:56.431443
@classmethod def dict_delete(cls, dict_in): """ Delete records from the database based on a dictionary keyed by PK tuple """ s = dbc.get_session()
d_start = datetime.datetime.now() keys_in = [k for k in dict_in.keys()] batch_size = 1000 cols = [getattr(cls, colname) for colname in cls.SQL_PK] while len(keys_in): id_batch = keys_in[:batch_size] del keys_in[:batch_size]
or_cond = [] for x in id_batch:
pkf = [(col == v) for (col, v) in zip(cols, x)] and_cond = and_(*pkf) or_cond.append(and_cond)
stmt = cls.__table__.delete(or_(*or_cond)) stmt_comp = str(stmt.compile(dialect=s.bind.dialect, compile_kwargs={"literal_binds": True}))
print(stmt_comp) print(len(keys_in), "-", datetime.datetime.now() - d_start)
s.execute(stmt_comp)
s.commit()
s.close()