codecop 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (315) hide show
  1. {codecop-0.1.0 → codecop-0.2.0}/PKG-INFO +4 -2
  2. {codecop-0.1.0 → codecop-0.2.0}/README.md +2 -1
  3. {codecop-0.1.0 → codecop-0.2.0}/pyproject.toml +5 -2
  4. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/__init__.py +1 -1
  5. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/advisor.py +65 -7
  6. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/advisor_bench.py +69 -7
  7. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/advisor_ch.py +8 -0
  8. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/advisor_view.py +4 -0
  9. codecop-0.2.0/src/codecop/advisor_worth.py +189 -0
  10. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/agentfacts.py +72 -7
  11. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/apply/patch.py +1 -1
  12. codecop-0.2.0/src/codecop/assist.py +782 -0
  13. codecop-0.2.0/src/codecop/assist_cli.py +162 -0
  14. codecop-0.2.0/src/codecop/assist_mcp.py +335 -0
  15. codecop-0.2.0/src/codecop/assist_plan.py +217 -0
  16. codecop-0.2.0/src/codecop/assist_quick.py +353 -0
  17. codecop-0.2.0/src/codecop/assist_realdb.py +262 -0
  18. codecop-0.2.0/src/codecop/assist_sandbox.py +471 -0
  19. codecop-0.2.0/src/codecop/attribution.py +282 -0
  20. codecop-0.2.0/src/codecop/attributioncli.py +60 -0
  21. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/baseline.py +57 -12
  22. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/bench.py +257 -43
  23. codecop-0.2.0/src/codecop/benchorder.py +125 -0
  24. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/blockers.py +64 -6
  25. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/budget.py +104 -3
  26. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/cicmd.py +28 -9
  27. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/cli.py +664 -48
  28. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/client.py +52 -4
  29. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/coverage.py +2 -1
  30. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/coverage_reasons.py +2 -0
  31. codecop-0.2.0/src/codecop/datacli.py +164 -0
  32. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/datagen.py +109 -5
  33. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/datagen_postgres.py +70 -6
  34. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/definitions.py +2 -0
  35. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/__init__.py +117 -17
  36. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/base.py +13 -2
  37. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/dialect.py +45 -11
  38. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/go.py +6 -0
  39. codecop-0.2.0/src/codecop/discover/go_methods.py +231 -0
  40. codecop-0.2.0/src/codecop/discover/hasura.py +1037 -0
  41. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/origins.py +11 -2
  42. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/origins_ts.py +123 -0
  43. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_py.py +3 -3
  44. codecop-0.2.0/src/codecop/discover/orm_py_supabase.py +353 -0
  45. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_sqlalchemy.py +72 -3
  46. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_ts.py +20 -1
  47. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_ts_prisma.py +44 -5
  48. codecop-0.2.0/src/codecop/discover/orm_ts_supabase.py +452 -0
  49. codecop-0.2.0/src/codecop/discover/outbound.py +383 -0
  50. codecop-0.2.0/src/codecop/discover/postgrest.py +658 -0
  51. codecop-0.2.0/src/codecop/discover/resultuse.py +483 -0
  52. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/rust.py +10 -1
  53. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/schema.py +127 -17
  54. codecop-0.2.0/src/codecop/discover/supabase_sql.py +371 -0
  55. codecop-0.2.0/src/codecop/endpointworth.py +128 -0
  56. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/engines/base.py +20 -1
  57. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/engines/clickhouse.py +27 -5
  58. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/engines/pg_hints.py +1 -1
  59. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/engines/postgres.py +45 -7
  60. codecop-0.2.0/src/codecop/enginesplit.py +155 -0
  61. codecop-0.2.0/src/codecop/exec.py +648 -0
  62. codecop-0.2.0/src/codecop/exec_harness/child.py +427 -0
  63. codecop-0.2.0/src/codecop/exec_harness/equal.py +90 -0
  64. codecop-0.2.0/src/codecop/exec_harness/parent.py +183 -0
  65. codecop-0.2.0/src/codecop/execcli.py +85 -0
  66. codecop-0.2.0/src/codecop/expected.py +374 -0
  67. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/fixgroups.py +50 -7
  68. codecop-0.2.0/src/codecop/flagged.py +287 -0
  69. codecop-0.2.0/src/codecop/flips.py +86 -0
  70. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/groupbench.py +44 -4
  71. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/heat.py +33 -2
  72. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/joins.py +19 -3
  73. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/__init__.py +82 -6
  74. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/calls/__init__.py +127 -13
  75. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/calls/extract.py +102 -6
  76. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/calls/harness.py +42 -5
  77. codecop-0.2.0/src/codecop/kinds/calls/inloop.py +345 -0
  78. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/calls/measure.py +94 -0
  79. codecop-0.2.0/src/codecop/kinds/calls/perrequest.py +257 -0
  80. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/calls/rules.py +33 -6
  81. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/calls/runners/run_node.js +25 -0
  82. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/calls/runners/run_python.py +132 -0
  83. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/calls/standin.py +47 -10
  84. codecop-0.2.0/src/codecop/kinds/calls/transport.py +149 -0
  85. codecop-0.2.0/src/codecop/kinds/clientcode.py +174 -0
  86. codecop-0.2.0/src/codecop/kinds/dbconn/__init__.py +434 -0
  87. codecop-0.2.0/src/codecop/kinds/dbshape/__init__.py +131 -0
  88. codecop-0.2.0/src/codecop/kinds/execproof.py +29 -0
  89. codecop-0.2.0/src/codecop/kinds/loop/__init__.py +519 -0
  90. codecop-0.2.0/src/codecop/kinds/loop/codecs.py +68 -0
  91. codecop-0.2.0/src/codecop/kinds/loop/extract.py +478 -0
  92. codecop-0.2.0/src/codecop/kinds/loop/measure.py +254 -0
  93. codecop-0.2.0/src/codecop/kinds/loop/node_codecs.py +50 -0
  94. codecop-0.2.0/src/codecop/kinds/loop/node_extract.py +223 -0
  95. codecop-0.2.0/src/codecop/kinds/loop/node_measure.py +109 -0
  96. codecop-0.2.0/src/codecop/kinds/loop/run_codec.py +487 -0
  97. codecop-0.2.0/src/codecop/kinds/loop/run_node_loop.js +271 -0
  98. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/pipeline.py +7 -1
  99. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/regex/__init__.py +90 -8
  100. codecop-0.2.0/src/codecop/kinds/regex/inputs.py +138 -0
  101. codecop-0.2.0/src/codecop/kinds/resultset/__init__.py +253 -0
  102. codecop-0.2.0/src/codecop/kinds/resultset/extract.py +319 -0
  103. codecop-0.2.0/src/codecop/kinds/resultset/measure.py +276 -0
  104. codecop-0.2.0/src/codecop/kinds/resultset/run_resultset.py +230 -0
  105. codecop-0.2.0/src/codecop/kinds/rls/__init__.py +472 -0
  106. codecop-0.2.0/src/codecop/kinds/rls/lint.py +283 -0
  107. codecop-0.2.0/src/codecop/kinds/rls/sandbox.py +433 -0
  108. codecop-0.2.0/src/codecop/kinds/setup/__init__.py +389 -0
  109. codecop-0.2.0/src/codecop/kinds/setup/extract.py +331 -0
  110. codecop-0.2.0/src/codecop/kinds/standin_builds.py +166 -0
  111. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/transaction/__init__.py +16 -2
  112. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/transaction/measure.py +40 -9
  113. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/transaction/plan.py +6 -1
  114. codecop-0.2.0/src/codecop/kinds/transaction/rows_order.py +178 -0
  115. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/transaction/rules.py +4 -0
  116. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/transaction/sandbox.py +41 -8
  117. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/transaction/scenarios.py +12 -4
  118. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/transaction/schedule.py +52 -4
  119. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/transaction/verify.py +149 -13
  120. codecop-0.2.0/src/codecop/learnanswers.py +41 -0
  121. codecop-0.2.0/src/codecop/learncli.py +359 -0
  122. codecop-0.2.0/src/codecop/learnings.py +1883 -0
  123. codecop-0.2.0/src/codecop/learnmcp.py +204 -0
  124. codecop-0.2.0/src/codecop/lift.py +368 -0
  125. codecop-0.2.0/src/codecop/loadfit.py +112 -0
  126. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/loopbench.py +111 -14
  127. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/loopschema.py +2 -0
  128. codecop-0.2.0/src/codecop/loopworth.py +313 -0
  129. codecop-0.2.0/src/codecop/loopwrites.py +587 -0
  130. codecop-0.2.0/src/codecop/mattersfrom.py +359 -0
  131. codecop-0.2.0/src/codecop/mcpremote.py +158 -0
  132. codecop-0.2.0/src/codecop/mcpserver.py +201 -0
  133. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/multi.py +69 -7
  134. codecop-0.2.0/src/codecop/optionals.py +134 -0
  135. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/patterns.py +10 -2
  136. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/patterns_view.py +16 -1
  137. codecop-0.2.0/src/codecop/payloads.py +130 -0
  138. codecop-0.2.0/src/codecop/prflags.py +137 -0
  139. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/profile.py +33 -9
  140. codecop-0.2.0/src/codecop/projectcli.py +226 -0
  141. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/prompts/rank.md +1 -0
  142. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/prompts/rank_postgres.md +1 -0
  143. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/prompts/rank_sqlite.md +1 -0
  144. codecop-0.2.0/src/codecop/provelarge.py +52 -0
  145. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/rank.py +35 -4
  146. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/report.py +122 -16
  147. codecop-0.2.0/src/codecop/retarget.py +59 -0
  148. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/rules/entry_points.toml +11 -0
  149. codecop-0.2.0/src/codecop/rules/outbound_calls.toml +247 -0
  150. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/rules/sinks.toml +19 -0
  151. codecop-0.2.0/src/codecop/shapes/__init__.py +301 -0
  152. codecop-0.2.0/src/codecop/shapes/bulkwrite.py +225 -0
  153. codecop-0.2.0/src/codecop/shapes/common.py +257 -0
  154. codecop-0.2.0/src/codecop/shapes/count.py +335 -0
  155. codecop-0.2.0/src/codecop/shapes/keyset.py +253 -0
  156. codecop-0.2.0/src/codecop/shapes/substring.py +387 -0
  157. codecop-0.2.0/src/codecop/sharedkinds.py +97 -0
  158. codecop-0.2.0/src/codecop/siblings.py +167 -0
  159. codecop-0.2.0/src/codecop/sizecap.py +84 -0
  160. codecop-0.2.0/src/codecop/sqlglot_compat.py +85 -0
  161. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/sqlinfo.py +25 -5
  162. codecop-0.2.0/src/codecop/testdata.py +952 -0
  163. codecop-0.2.0/src/codecop/usageschema.py +404 -0
  164. codecop-0.2.0/src/codecop/worth.py +509 -0
  165. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/writebench.py +5 -2
  166. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/writecost.py +16 -5
  167. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/writes.py +4 -0
  168. codecop-0.2.0/src/codecop/yesno.py +394 -0
  169. codecop-0.2.0/src/codecop/yesno_merge.py +188 -0
  170. codecop-0.2.0/tests/README.md +20 -0
  171. codecop-0.1.0/src/codecop/mcpserver.py +0 -120
  172. codecop-0.1.0/tests/README.md +0 -11
  173. {codecop-0.1.0 → codecop-0.2.0}/.gitignore +0 -0
  174. {codecop-0.1.0 → codecop-0.2.0}/LICENSE +0 -0
  175. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/access.py +0 -0
  176. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/access_postgres.py +0 -0
  177. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/advisors.py +0 -0
  178. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/agent.py +0 -0
  179. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/apply/__init__.py +0 -0
  180. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/apply/check.py +0 -0
  181. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/apply/cli.py +0 -0
  182. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/apply/clickhouse.py +0 -0
  183. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/apply/common.py +0 -0
  184. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/apply/html.py +0 -0
  185. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/apply/postgres.py +0 -0
  186. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/apply/trial.py +0 -0
  187. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/assemble.py +0 -0
  188. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/catalog_profile.py +0 -0
  189. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/changed.py +0 -0
  190. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/crashlog.py +0 -0
  191. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/datagen_sqlite.py +0 -0
  192. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/dbcli.py +0 -0
  193. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/arms.py +0 -0
  194. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/elixir.py +0 -0
  195. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/engine_go.py +0 -0
  196. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/java.py +0 -0
  197. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/loops.py +0 -0
  198. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/named_go.py +0 -0
  199. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_django.py +0 -0
  200. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_django_models.py +0 -0
  201. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_django_sql.py +0 -0
  202. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_ent.py +0 -0
  203. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_ex_ecto.py +0 -0
  204. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_go.py +0 -0
  205. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_go_bun.py +0 -0
  206. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_go_run.py +0 -0
  207. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_go_types.py +0 -0
  208. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_java.py +0 -0
  209. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_jdbi.py +0 -0
  210. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_jooq.py +0 -0
  211. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_jpa.py +0 -0
  212. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_mybatis.py +0 -0
  213. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_py_peewee.py +0 -0
  214. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_py_prisma.py +0 -0
  215. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_rb_activerecord.py +0 -0
  216. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_rust.py +0 -0
  217. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_rust_seaorm.py +0 -0
  218. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_stats.py +0 -0
  219. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_tables.py +0 -0
  220. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_ts_drizzle.py +0 -0
  221. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_ts_knex.py +0 -0
  222. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_ts_kysely.py +0 -0
  223. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_ts_schema.py +0 -0
  224. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_ts_sequelize.py +0 -0
  225. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/orm_ts_typeorm.py +0 -0
  226. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/probes.py +0 -0
  227. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/python.py +0 -0
  228. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/ruby.py +0 -0
  229. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/schema_ent.py +0 -0
  230. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/schema_ts.py +0 -0
  231. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/tsresolve.py +0 -0
  232. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/typescript.py +0 -0
  233. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/discover/xml_mapper.py +0 -0
  234. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/engines/__init__.py +0 -0
  235. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/engines/pg_ddl.py +0 -0
  236. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/engines/sqlite.py +0 -0
  237. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/__init__.py +0 -0
  238. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/build.py +0 -0
  239. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/cli.py +0 -0
  240. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/coverage_hook.py +0 -0
  241. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/driver.py +0 -0
  242. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/goslice.py +0 -0
  243. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/goslice_tool/go.mod +0 -0
  244. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/goslice_tool/main.go +0 -0
  245. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/holes.py +0 -0
  246. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/images/Dockerfile.go +0 -0
  247. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/images/Dockerfile.python +0 -0
  248. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/images/Dockerfile.rust +0 -0
  249. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/isolate.py +0 -0
  250. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/locate.py +0 -0
  251. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/model.py +0 -0
  252. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/plangate.py +0 -0
  253. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/families/tagpatch.py +0 -0
  254. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/fidelity.py +0 -0
  255. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/formerly.py +0 -0
  256. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/grantscript.py +0 -0
  257. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/groups.py +0 -0
  258. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/groups_view.py +0 -0
  259. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/heatcli.py +0 -0
  260. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/joins_view.py +0 -0
  261. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/calls/runners/RunCalls.java +0 -0
  262. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/calls/runners/run_go.go +0 -0
  263. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/calls/runners/run_rust.rs +0 -0
  264. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/regex/engines/RegexHarness.java +0 -0
  265. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/regex/engines/run_go.go +0 -0
  266. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/regex/engines/run_node.js +0 -0
  267. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/regex/engines/run_python.py +0 -0
  268. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/regex/engines/run_rust.rs +0 -0
  269. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/regex/extract.py +0 -0
  270. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/regex/harness.py +0 -0
  271. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/regex/measure.py +0 -0
  272. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/regex/shapes.py +0 -0
  273. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/regex/syntax.py +0 -0
  274. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/testkind.py +0 -0
  275. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/transaction/bind.py +0 -0
  276. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/kinds/transaction/shapes.py +0 -0
  277. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/live.py +0 -0
  278. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/mechanism.py +0 -0
  279. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/members.py +0 -0
  280. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/observed.py +0 -0
  281. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/parts.py +0 -0
  282. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/plangate.py +0 -0
  283. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/prompts/areas.md +0 -0
  284. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/prompts/observed_variants.md +0 -0
  285. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/prompts/profile.md +0 -0
  286. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/prompts/profile_postgres.md +0 -0
  287. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/prompts/profile_sizes.md +0 -0
  288. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/prompts/profile_sqlite.md +0 -0
  289. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/prompts/scenario_variants.md +0 -0
  290. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/realdb/__init__.py +0 -0
  291. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/realdb/clickhouse.py +0 -0
  292. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/realdb/facts.py +0 -0
  293. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/realdb/locality.py +0 -0
  294. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/realdb/locks.py +0 -0
  295. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/realdb/match.py +0 -0
  296. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/realdb/postgres.py +0 -0
  297. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/realdb/ratios.py +0 -0
  298. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/realdb/sample.py +0 -0
  299. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/relations.py +0 -0
  300. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/resources.py +0 -0
  301. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/resources_view.py +0 -0
  302. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/runsonce.py +0 -0
  303. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/sandboxschema.py +0 -0
  304. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/scenario_agent.py +0 -0
  305. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/scenario_bind.py +0 -0
  306. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/scenario_sql.py +0 -0
  307. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/scenarios.py +0 -0
  308. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/scenarios_view.py +0 -0
  309. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/schemacli.py +0 -0
  310. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/schemas/areas_output.schema.json +0 -0
  311. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/schemas/profile_output.schema.json +0 -0
  312. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/schemas/rank_output.schema.json +0 -0
  313. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/sizes.py +0 -0
  314. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/typedparams.py +0 -0
  315. {codecop-0.1.0 → codecop-0.2.0}/src/codecop/verdicts.py +0 -0
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codecop
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Find every database call in a repo, rank optimization candidates, and test fixes on a sandbox database.
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
7
7
  Requires-Python: >=3.11
8
8
  Requires-Dist: keyring>=24
9
+ Requires-Dist: pg8000>=1.30
9
10
  Requires-Dist: rich>=13
10
11
  Requires-Dist: sqlglot>=26
11
12
  Requires-Dist: tree-sitter-elixir>=0.3
@@ -37,6 +38,7 @@ codecop scan . # discover, rank, benchmark, report
37
38
  codecop coverage <out-dir> # how many reads and writes were judged, and why the rest were not
38
39
  ```
39
40
 
40
- `pip install 'codecop[postgres]'` adds the driver for reading statistics from a real PostgreSQL. Sandboxes need Docker.
41
+ The PostgreSQL driver (pg8000, pure Python) is installed with CodeCop: the transaction and connection sandboxes and
42
+ `codecop db` use it. `codecop[postgres]` still works and adds nothing more. Sandboxes need Docker or Podman.
41
43
 
42
44
  Home: https://codecop.dev · Console: https://app.codecop.dev
@@ -10,6 +10,7 @@ codecop scan . # discover, rank, benchmark, report
10
10
  codecop coverage <out-dir> # how many reads and writes were judged, and why the rest were not
11
11
  ```
12
12
 
13
- `pip install 'codecop[postgres]'` adds the driver for reading statistics from a real PostgreSQL. Sandboxes need Docker.
13
+ The PostgreSQL driver (pg8000, pure Python) is installed with CodeCop: the transaction and connection sandboxes and
14
+ `codecop db` use it. `codecop[postgres]` still works and adds nothing more. Sandboxes need Docker or Podman.
14
15
 
15
16
  Home: https://codecop.dev · Console: https://app.codecop.dev
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "codecop"
7
- version = "0.1.0"
7
+ version = "0.2.0"
8
8
  readme = "README.md"
9
9
  description = "Find every database call in a repo, rank optimization candidates, and test fixes on a sandbox database."
10
10
  requires-python = ">=3.11"
@@ -24,11 +24,14 @@ dependencies = [
24
24
  "tree-sitter-ruby>=0.23",
25
25
  "tree-sitter-elixir>=0.3",
26
26
  "tree-sitter-kotlin>=1.0",
27
+ # the PostgreSQL driver of the transaction and connection sandboxes (and of `codecop db`). Pure Python.
28
+ "pg8000>=1.30",
27
29
  ]
28
30
 
29
31
  [project.optional-dependencies]
30
32
  dev = ["pytest>=8", "pg8000>=1.30"]
31
- # `codecop db` against a real PostgreSQL. Pure Python. ClickHouse needs nothing: it is read over HTTPS with the standard library.
33
+ # kept for older install lines: pg8000 is a core dependency now (the transaction and connection sandboxes need it).
34
+ # ClickHouse needs nothing: it is read over HTTPS with the standard library.
32
35
  postgres = ["pg8000>=1.30"]
33
36
 
34
37
  [project.scripts]
@@ -2,6 +2,6 @@ import os as _os
2
2
 
3
3
  from . import formerly as _formerly
4
4
 
5
- __version__ = "0.1.0"
5
+ __version__ = "0.2.0"
6
6
 
7
7
  _formerly.environ(_os.environ) # QOPT_X stands in for an unset CODECOP_X (formerly.py)
@@ -62,6 +62,11 @@ DEFAULTS = {
62
62
  "static_loop_factor": 10.0, # without a pull: a statement in a loop weighs this many times one that is not
63
63
  "vm_touch_share": 0.2, # index-only claims: share of heap pages rewritten without VACUUM for the honest run
64
64
  "regression_ratio": 1.15, # a statement the index does not serve that touches more than this x its pages got worse
65
+ # a measured statement whose time with the index is more than this x its time without, and slower by more than
66
+ # `regression_time_floor_ms` (timer noise on sub-millisecond runs), got slower: the index is a trade-off, never Fixed,
67
+ # even when it reads the same rows and pages
68
+ "regression_time_ratio": 1.5,
69
+ "regression_time_floor_ms": 0.2,
65
70
  "max_measured_per_suggestion": 40, # statements measured per suggestion (served first, then the table's others)
66
71
  "max_tables": 400, # tables looked at per run, heaviest first
67
72
  "min_table_rows": 10_000, # a table with fewer rows (real catalog) gets no suggestion: a scan of it is cheap
@@ -74,7 +79,10 @@ BOOL_DEFAULTS = {"covering": True, "expressions": True, "join_keys": True, "part
74
79
  # a candidate that only adds equality columns to statements an existing index already pins by equality
75
80
  "propose_eq_refinements": False,
76
81
  # a key made of boolean columns only (by type) is not proposed
77
- "skip_boolean_keys": True}
82
+ "skip_boolean_keys": True,
83
+ # a statement whose plan (EXPLAIN without running it) a suggested index leaves unchanged is not run again
84
+ # with the index: its baseline stands for that run (it reads the same pages); false runs every one again
85
+ "same_plan_reuse": True}
78
86
  LIST_DEFAULTS = {
79
87
  # functions an expression index can be built on (IMMUTABLE in PostgreSQL); a filter on any other function of a
80
88
  # column is not given an expression index
@@ -92,7 +100,10 @@ REASONS = {
92
100
  "blocked": ("no_variant_reads_less", "fix_results_differ", "fix_costs_inserts", "insert_cost_near_limit", "fix_slows_other_statements"),
93
101
  "not_judged": ("bench_not_run", "statements_not_runnable", "sandbox_table_not_loaded", "sandbox_could_not_run", "sameness_not_shown",
94
102
  "insert_cost_not_measured", "parameters_match_no_rows"),
95
- "nothing_to_gain": ("already_cheap_measured",),
103
+ "nothing_to_gain": ("already_cheap_measured",
104
+ # verified, and not a fix of its own (advisor_worth.py): an alternative of a kept suggestion, or a
105
+ # negligible saving at the size measured
106
+ "same_as_another", "negligible_gain"),
96
107
  }
97
108
  KINDS = ("index", "partial_index", "covering_index", "expression_index")
98
109
  WIDE_TYPE = re.compile(r"\b(?:json|jsonb|bytea|tsvector|xml)\b|\[\]", re.I)
@@ -1306,8 +1317,33 @@ def hygiene(defs: dict[str, TableDef], facts=None) -> list[dict]:
1306
1317
 
1307
1318
  # ---- outcomes, after the sandbox ----------------------------------------------------------------------------------
1308
1319
 
1309
- def verdict_of(s: dict, measured: dict | None, insert_settings: dict | None = None, bench_ran: bool = False) -> dict:
1310
- """One of the four states for one suggestion, from what advisor_bench measured (`measured`: its record)."""
1320
+ def slower_in_time(rows: list[dict], settings: dict | None = None) -> list[dict]:
1321
+ """The measured statements (served or not) the index made clearly slower in time: after > regression_time_ratio x
1322
+ before and slower by more than regression_time_floor_ms. Rows and pages equal do not excuse it: the time is what the
1323
+ caller waits for. [{statement, before_ms, after_ms, ratio, serves}]."""
1324
+ cfg = {**DEFAULTS, **{k: v for k, v in (settings or {}).items() if k in DEFAULTS and isinstance(v, (int, float))}}
1325
+ ratio, floor = float(cfg["regression_time_ratio"]), float(cfg["regression_time_floor_ms"])
1326
+ out = []
1327
+ for x in rows or []:
1328
+ b, a = x.get("before") or {}, x.get("after") or {}
1329
+ if b.get("ok") is False or a.get("ok") is False:
1330
+ continue
1331
+ try:
1332
+ bm, am = float(b.get("duration_ms")), float(a.get("duration_ms"))
1333
+ except (TypeError, ValueError):
1334
+ continue
1335
+ if bm > 0 and am > ratio * bm and am - bm > floor:
1336
+ out.append({"statement": x.get("statement"), "before_ms": round(bm, 3), "after_ms": round(am, 3), "ratio": round(am / bm, 2),
1337
+ "serves": bool(x.get("serves"))})
1338
+ return out
1339
+
1340
+
1341
+ def verdict_of(s: dict, measured: dict | None, insert_settings: dict | None = None, bench_ran: bool = False,
1342
+ settings: dict | None = None, write_class: dict | None = None, blocker_settings: dict | None = None) -> dict:
1343
+ """One of the four states for one suggestion, from what advisor_bench measured (`measured`: its record). `settings`:
1344
+ the advisor's (DEFAULTS), for the time-regression thresholds. `write_class`: how busy the suggestion's table is with
1345
+ inserts (worth.write_class): the insert limit is then weighed exactly as a statement finding's (worth.reweigh_insert),
1346
+ so one index on one table gets one verdict whichever path proposed it."""
1311
1347
  from . import blockers
1312
1348
 
1313
1349
  def done(state, reason, src="sandbox", **ev):
@@ -1329,8 +1365,14 @@ def verdict_of(s: dict, measured: dict | None, insert_settings: dict | None = No
1329
1365
  if "rejected" in honest:
1330
1366
  return done("blocked", "fix_results_differ", statements=len(ran))
1331
1367
  regress = [x["statement"] for x in others if x.get("verdict") == "slower"]
1368
+ # a statement the index is meant to serve that got slower with it: never Fixed while one does
1369
+ regress += [x["statement"] for x, h in zip(ran, honest) if h == "slower" or x.get("verdict") == "slower"]
1370
+ slow = slower_in_time([x for x in measured.get("statements") or [] if x.get("verdict") not in ("failed", "untested")], settings)
1371
+ regress += [x["statement"] for x in slow if x["statement"] not in regress]
1332
1372
  wins = [x for x, h in zip(ran, honest) if h == "win"]
1333
1373
  ev = {"statements_measured": len(ran), "statements_won": len(wins), "claimed_not_measured": len(s.get("serves") or []) - len(ran)}
1374
+ if slow:
1375
+ ev["slower_in_time"] = slow
1334
1376
  if wins:
1335
1377
  ic = s.get("write_cost")
1336
1378
  if ic and ic.get("measured"):
@@ -1338,6 +1380,10 @@ def verdict_of(s: dict, measured: dict | None, insert_settings: dict | None = No
1338
1380
  from .writecost import near_limit, settings_of as wc_settings, within
1339
1381
  wc = wc_settings(insert_settings)
1340
1382
  ic = s["write_cost"] = {**ic, "within": within(ic, wc), "near_limit": near_limit(ic, wc)}
1383
+ if write_class:
1384
+ from . import worth
1385
+ ic = s["write_cost"] = worth.reweigh_insert(ic, write_class, blockers.settings_of(blocker_settings),
1386
+ float(wc["insert_cost_max_time_ratio"]), insert_settings)
1341
1387
  ok, costly, unmeasured = blockers.insert_cost_rule([{"kind": "index", "insert_cost": ic}], insert_settings or {})
1342
1388
  if regress:
1343
1389
  return done("blocked", "fix_slows_other_statements", **ev, slower=regress, trade_off=True)
@@ -1382,7 +1428,8 @@ VERDICT_OF = {"verified": "verified", "no_variant_reads_less": "no_change", "fix
1382
1428
  "fix_costs_inserts": "trade_off", "insert_cost_near_limit": "trade_off", "regresses_other_statements": "regresses",
1383
1429
  "bench_not_run": "claimed", "claimed_not_measured": "claimed", "sandbox_table_not_loaded": "failed",
1384
1430
  "sandbox_could_not_run": "failed", "sameness_not_shown": "evidence_only", "insert_cost_not_measured": "not_measured",
1385
- "parameters_match_no_rows": "not_measured", "already_cheap_measured": "no_change"}
1431
+ "parameters_match_no_rows": "not_measured", "already_cheap_measured": "no_change", "same_as_another": "superseded",
1432
+ "negligible_gain": "no_change"}
1386
1433
  WRITE_COST_KEYS = ("measured", "reason", "rows", "blocks", "rounds", "insert_time_ratio", "insert_time_ratios", "insert_time_ratio_range",
1387
1434
  "written_bytes_ratio", "wal_bytes_ratio", "storage_ratio", "parts_ratio", "within", "near_limit", "thresholds",
1388
1435
  "index_bytes", "wal_from")
@@ -1465,6 +1512,16 @@ def shared(s: dict, clean=lambda t: t) -> dict:
1465
1512
  if isinstance(s.get("visibility"), dict):
1466
1513
  ed["visibility"] = _plain(s["visibility"])
1467
1514
  ev = {k: x for k, x in (v.get("evidence") or {}).items() if _scalar(x) or (isinstance(x, list) and all(_scalar(y) for y in x))}
1515
+ slow = {x.get("statement"): x for x in (v.get("evidence") or {}).get("slower_in_time") or [] if isinstance(x, dict)}
1516
+ words = ""
1517
+ if v.get("reason") == "fix_slows_other_statements" and slow:
1518
+ top = max(float(x.get("ratio") or 0) for x in slow.values())
1519
+ words = (f"{len(slow)} measured statement(s) ran clearly slower with it (up to x{top:g} the time): a trade-off, "
1520
+ "not a fix")
1521
+ ev["slower_in_time"] = len(slow)
1522
+ ev["slower_in_time_max_ratio"] = top
1523
+ elif v.get("reason") == "same_as_another" and (v.get("evidence") or {}).get("same_fix_of") == "statement_finding":
1524
+ words = f"verified, the same index as statement finding {(v.get('evidence') or {}).get('same_fix_as')} (a permutation, a covering twin or a prefix): counted there once"
1468
1525
  wc = s.get("write_cost")
1469
1526
  size = s.get("size") or {}
1470
1527
  shares = [x["weight_share"] for x in measured if x.get("weight_share") is not None]
@@ -1480,9 +1537,10 @@ def shared(s: dict, clean=lambda t: t) -> dict:
1480
1537
  "size": {"bytes_sandbox": size.get("index_bytes"), "table_bytes_sandbox": None, "basis": size.get("at") or "sandbox scale"}
1481
1538
  if size.get("index_bytes") is not None else None,
1482
1539
  "verdict": VERDICT_OF.get(reason, "claimed"),
1483
- "outcome": {"state": v.get("state") or "not_judged", "reason": reason, "evidence": ev},
1540
+ "outcome": {"state": v.get("state") or "not_judged", "reason": reason, "evidence": ev, **({"words": words} if words else {})},
1484
1541
  "basis": "rule",
1485
- "others_measured": [{"statement": x.get("statement"), "finding": None, "verdict": x.get("verdict"),
1542
+ "others_measured": [{"statement": x.get("statement"), "finding": None,
1543
+ "verdict": "slower" if x.get("statement") in slow else x.get("verdict"),
1486
1544
  "read_ratio": round(((x.get("after") or {}).get("read_bytes") or 0) /(x.get("before") or {})["read_bytes"], 4)
1487
1545
  if (x.get("before") or {}).get("read_bytes") else None}
1488
1546
  for x in s.get("not_served_checked") or []],
@@ -154,6 +154,8 @@ def touch(sb, table: str, share: float) -> dict:
154
154
  pct = max(min(share * 100.0, 100.0), 0.0)
155
155
  for name in list((getattr(sb, "loaded", None) or {})):
156
156
  if A.short(name) == A.short(table):
157
+ from . import testdata
158
+ testdata.preserve(sb, name, sb.loaded) # saved test data: the table as loaded is kept aside, a copy is rewritten
157
159
  sb.loaded.pop(name, None) # rewritten rows: a later bench of the run loads it again (bench.load_tables)
158
160
  sb.execute(f"UPDATE {q} SET {c} = {c} WHERE ctid = ANY(ARRAY(SELECT ctid FROM {q} TABLESAMPLE SYSTEM ({pct:g}) REPEATABLE (7)))")
159
161
  sb.execute(f"ANALYZE {q}")
@@ -163,6 +165,23 @@ def touch(sb, table: str, share: float) -> dict:
163
165
  "all_visible_share": round(int(vm.get("all_visible") or 0) / pages, 4) if pages else None, "column_rewritten": cols[0]["name"]}
164
166
 
165
167
 
168
+ def plan_shapes(sb, forms: list[dict]) -> list[str | None]:
169
+ """The plan each runnable form gets now, without running it (EXPLAIN (COSTS OFF), one psql call for all): a stable
170
+ text per form, None when it could not be planned. Two equal shapes are one plan: the same pages and rows are read."""
171
+ if not forms or not hasattr(sb, "_psql") or getattr(sb, "engine", "") != "postgres":
172
+ return [None] * len(forms)
173
+ from .engines.postgres import MARK, render_params
174
+ import json as _json
175
+ script = sb.SESSION + "".join(f"\\echo {MARK}\nEXPLAIN (COSTS OFF, FORMAT JSON) "
176
+ f"{sb.frozen(render_params(f['sql'].strip().rstrip(';'), f['params']))};\n" for f in forms)
177
+ try:
178
+ chunks = [c.strip() for c in sb._psql(script).split(MARK)[1:]]
179
+ got = [_json.dumps(_json.loads(c)[0]["Plan"], sort_keys=True) for c in chunks]
180
+ except (QueryError, ValueError, KeyError, IndexError, TypeError):
181
+ return [None] * len(forms)
182
+ return got if len(got) == len(forms) else [None] * len(forms)
183
+
184
+
166
185
  def run_table(sb, table: str, suggestions: list[dict], doc: dict, by_site: dict, by_hash: dict, profile: dict, loaded: set[str], runs: int,
167
186
  cfg: dict, insert_settings: dict | None, log) -> dict[str, dict]:
168
187
  """Every suggestion on one loaded table: {suggestion id: record}."""
@@ -190,6 +209,7 @@ def run_table(sb, table: str, suggestions: list[dict], doc: dict, by_site: dict,
190
209
  compares[ref] = bench_mod.Comparison(sb, {"baseline_sql": f["sql"]}, bases[ref], f["params"])
191
210
  return bases[ref]
192
211
 
212
+ base_shapes: dict[str, str | None] = {} # the plan of each measured statement without any suggested index
193
213
  vm_wanted: list[tuple[dict, list[str]]] = []
194
214
  for s in suggestions:
195
215
  started = time.monotonic()
@@ -207,6 +227,9 @@ def run_table(sb, table: str, suggestions: list[dict], doc: dict, by_site: dict,
207
227
  b = baseline(ref)
208
228
  measured_refs = [r for r in refs if r in bases and bases[r].ok]
209
229
  failed = [r for r in refs if r in bases and not bases[r].ok]
230
+ unshaped = [r for r in measured_refs if r not in base_shapes]
231
+ if unshaped and cfg["same_plan_reuse"]:
232
+ base_shapes.update(zip(unshaped, plan_shapes(sb, [form(r)[0] for r in unshaped])))
210
233
  name = s["name"]
211
234
  variant = {"sql": "", "setup_sql": s["ddl"], "same_results": True}
212
235
  try:
@@ -223,9 +246,14 @@ def run_table(sb, table: str, suggestions: list[dict], doc: dict, by_site: dict,
223
246
  f"SELECT relid FROM pg_partition_tree(c.oid)) x WHERE c.relname = '{name.lower()}' AND c.relkind IN ('i', 'I')")
224
247
  rec["index_bytes"] = int(size[0]["bytes"]) if size else None
225
248
  afters, pending = {}, {}
249
+ # a statement whose plan the index leaves as it was reads what its baseline read: its baseline stands for the
250
+ # run with the index (`same_plan`), and only the statements whose plan changed are run again
251
+ shaped = [r for r in measured_refs if base_shapes.get(r)]
252
+ now = dict(zip(shaped, plan_shapes(sb, [form(r)[0] for r in shaped]))) if shaped else {}
253
+ same_plan = {r for r in shaped if now.get(r) is not None and now[r] == base_shapes[r]}
226
254
  for ref in measured_refs:
227
255
  f, _ = form(ref)
228
- m = sb.measure(f["sql"], f["params"], runs)
256
+ m = bases[ref] if ref in same_plan else sb.measure(f["sql"], f["params"], runs)
229
257
  afters[ref] = m
230
258
  pending[ref] = compares[ref].with_setup({**variant, "sql": f["sql"]}, m)
231
259
  finally:
@@ -240,6 +268,7 @@ def run_table(sb, table: str, suggestions: list[dict], doc: dict, by_site: dict,
240
268
  **({"values_from": f["values_from"]} if f.get("values_from") else {}),
241
269
  "before": _numbers(base), "after": _numbers(m), "verdict": v, "reason": reason, "results_match": match if m.ok else None,
242
270
  "compared": compared, "uses_index": _uses(m, name), "index_only": _index_only(m, name),
271
+ **({"same_plan": True} if ref in same_plan else {}),
243
272
  # local only: what `codecop apply` confirms the index with (never uploaded)
244
273
  "run_sql": f["sql"], "run_params": f["params"]}
245
274
  if ref not in served and m.ok and base.read_bytes > sb.floor_bytes and m.read_bytes > cfg["regression_ratio"] * base.read_bytes:
@@ -354,7 +383,17 @@ def after_scale(doc: dict, rank: dict, runs: int, largest: float, settings: dict
354
383
  results[_key(s)] = {**_ident(s), "skip": "sandbox_table_not_loaded", "error_class": _error_class(failed[t].get("error") or "")}
355
384
  elif t in loaded:
356
385
  by_table.setdefault(t, []).append(s)
357
- for t, suggs in by_table.items():
386
+ from . import benchorder
387
+ heat_t: dict[str, float] = {}
388
+ for c in (rank or {}).get("candidates") or []:
389
+ for tn in c.get("tables") or []:
390
+ heat_t[A.short(tn)] = max(heat_t.get(A.short(tn), -1e9), float(benchorder.HEAT.get(c.get("finding") or "", 0.0)))
391
+ stop = False
392
+ # hottest table first: the time budget (max_bench_seconds, the scan's) leaves the coldest unmeasured
393
+ for t, suggs in sorted(by_table.items(), key=lambda kv: -heat_t.get(kv[0], 0.0)):
394
+ stop = stop or benchorder.checkpoint()
395
+ if stop:
396
+ continue # the scan's time budget, mode "stop": these stay not benchmarked
358
397
  if budget and spent[0] >= budget:
359
398
  for s in suggs:
360
399
  results.setdefault(_key(s), {**_ident(s), "skip": "advisor_time_budget", "error_class": "time_budget"})
@@ -387,12 +426,12 @@ def bench_record(results: dict[str, dict], largest: float, loaded: set[str] | No
387
426
  "loaded": sorted(loaded) if loaded is not None else None}
388
427
 
389
428
 
390
- def apply_record(doc: dict, record: dict | None, insert_settings: dict | None = None) -> dict:
429
+ def apply_record(doc: dict, record: dict | None, insert_settings: dict | None = None, worth_inputs: dict | None = None) -> dict:
391
430
  """advisor.json with a bench record's measurements (`bench_record`, from bench.json or the record written while a
392
431
  bench ran). Without a record every suggestion is "not benchmarked yet". A record of a bench that did not finish
393
432
  judges what it measured; the rest stays not benchmarked."""
394
433
  if not record:
395
- return results_into(doc, {}, bench_ran=False, insert_settings=insert_settings)
434
+ return results_into(doc, {}, bench_ran=False, insert_settings=insert_settings, worth_inputs=worth_inputs)
396
435
  results: dict[str, dict] = {}
397
436
  for sc in record.get("scales") or []:
398
437
  for r in sc.get("results") or []:
@@ -404,7 +443,7 @@ def apply_record(doc: dict, record: dict | None, insert_settings: dict | None =
404
443
  # a record rebuilt from an older advisor.json covers the suggestions of that file only: one it does not know was not run
405
444
  complete = record.get("complete") is not False and record.get("from") != "advisor.json"
406
445
  loaded = set(record["loaded"]) if complete and isinstance(record.get("loaded"), list) else None
407
- return results_into(doc, results, bench_ran=complete, insert_settings=insert_settings, loaded=loaded)
446
+ return results_into(doc, results, bench_ran=complete, insert_settings=insert_settings, loaded=loaded, worth_inputs=worth_inputs)
408
447
 
409
448
 
410
449
  def record_of_doc(doc: dict | None) -> dict | None:
@@ -434,7 +473,7 @@ def chain(*hooks):
434
473
 
435
474
 
436
475
  def results_into(doc: dict, results: dict[str, dict], bench_ran: bool, insert_settings: dict | None = None,
437
- loaded: set[str] | None = None) -> dict:
476
+ loaded: set[str] | None = None, worth_inputs: dict | None = None) -> dict:
438
477
  """advisor.json with each suggestion's measurements, gain, cost and verdict. `loaded`: the tables the bench built at
439
478
  its largest scale (a suggestion on a table the profile does not describe was never built)."""
440
479
  for s in doc.get("table_suggestions") or []:
@@ -465,12 +504,35 @@ def results_into(doc: dict, results: dict[str, dict], bench_ran: bool, insert_se
465
504
  for x in s.get("serves") or []:
466
505
  x["role"] = "claimed"
467
506
  x["why_not_measured"] = (rec or {}).get("skip") or ("no_runnable_form" if bench_ran else "bench_not_run")
468
- s["verdict"] = A.verdict_of(s, rec, insert_settings, bench_ran)
507
+ s["verdict"] = A.verdict_of(s, rec, insert_settings, bench_ran, doc.get("settings"), _write_class(s, worth_inputs),
508
+ (worth_inputs or {}).get("settings"))
509
+ # alternatives of one index count once, and a negligible saving is not a fix (advisor_worth.py); an index a statement
510
+ # finding already proposes and won with (a permutation of it, a covering twin, a prefix) is that finding's fix
511
+ from . import advisor_worth
512
+ doc["worth"] = advisor_worth.apply(doc, (worth_inputs or {}).get("settings"), (worth_inputs or {}).get("plausible"),
513
+ (worth_inputs or {}).get("measured_rows"), (worth_inputs or {}).get("frequency"),
514
+ (worth_inputs or {}).get("statement_indexes"))
469
515
  doc["summary"] = A.summarize(doc)
470
516
  doc["bench"] = {"ran": bench_ran}
471
517
  return doc
472
518
 
473
519
 
520
+ def _write_class(s: dict, worth_inputs: dict | None) -> dict | None:
521
+ """worth.write_class of the suggestion's table, from the inputs the report weighs statement findings with; None
522
+ without an inventory (the flat limit then)."""
523
+ wi = worth_inputs or {}
524
+ if wi.get("inventory") is None or not s.get("table"):
525
+ return None
526
+ from . import worth
527
+ from .blockers import settings_of
528
+ cache = wi.setdefault("_write_classes", {})
529
+ t = worth.short(s["table"])
530
+ if t not in cache:
531
+ cache[t] = worth.write_class(s["table"], wi["inventory"], None, "postgres", (wi.get("plausible") or {}).get(t),
532
+ settings_of(wi.get("settings")))
533
+ return cache[t]
534
+
535
+
474
536
  def read_gain(s: dict) -> dict | None:
475
537
  """Pages before and after over the served statements that were measured (the honest run for index-only reads),
476
538
  and the weighted share of pages saved."""
@@ -1508,6 +1508,14 @@ def prove_table(sb, doc: dict, plan: dict, suggestions: list[dict], stmts: list[
1508
1508
  served = {sv["statement"] for sv in s["serves"]}
1509
1509
  rec = {"fingerprint": s["fingerprint"], "id": s["id"], "kind": s["kind"], "table": s["table"], "statements": []}
1510
1510
  ddl = s["ddl"]
1511
+ detail = s.get("engine_detail") or {}
1512
+ if not any(st["ref"] in served for st in stmts) and (detail.get("production") or {}).get("status") != "answered" \
1513
+ and (detail.get("production_trial") or {}).get("status") != "answered":
1514
+ # no runnable statement it serves: judged "claimed, not measured" whatever the other statements read with it,
1515
+ # so it is not built (building one on a table of many parts took most of a first look)
1516
+ out.append({**rec, "skip": "no_runnable_statement"})
1517
+ log(f"advisor {s['id']} {s['kind']} on {s['table']}: not built (no runnable statement it serves)")
1518
+ continue
1511
1519
  try:
1512
1520
  if s["kind"] == "dedup_on_read":
1513
1521
  mine = [st for st in stmts if st["ref"] in served]
@@ -40,6 +40,10 @@ REASON_WORDS = {
40
40
  "bench_not_run": "not benchmarked yet",
41
41
  "a_projection_serves_it": "a projection with the same order serves the same statements, for less",
42
42
  "already_cheap_measured": "the statements it serves already read little",
43
+ "negligible_gain": "Low value fix: the statements it serves save little per run",
44
+ "already_indexed": "Low value fix: already indexed (an existing index already finds the rows it reads)",
45
+ "same_as_another": "verified, the same index as another suggestion (a permutation, a covering twin or a prefix): counted once",
46
+ "fix_slows_other_statements": "a statement it serves or another of the table reads more or runs clearly slower with it: a trade-off",
43
47
  "not_usable_as_written": "the statements bound a column the projection does not keep: the engine can not use it",
44
48
  "parameters_match_no_rows": "the statements it serves read nothing on the sandbox: their values match no rows there",
45
49
  "sameness_not_shown": "reads less, the same rows not shown",
@@ -0,0 +1,189 @@
1
+ """The PostgreSQL index advisor's Fixed suggestions, weighed the way worth.py weighs statement findings.
2
+
3
+ After each suggestion has its verdict (advisor.verdict_of), over the whole document:
4
+
5
+ one index, one fix Fixed suggestions on one table that are the same index in another column order (a permutation of
6
+ the same key columns), a covering twin (the same key with INCLUDE columns) or a prefix of another
7
+ one's key are alternatives: the one kept serves the most statements (won), then costs inserts the
8
+ least, then has the fewest columns. The others end nothing_to_gain / `same_as_another`, each with the
9
+ suggestion kept and the statements it served; the kept one lists the alternatives.
10
+ already indexed ("Low value fix", reason already indexed) the kept suggestion extends an index the table already has
11
+ (worth.extends: every key column of the existing index is among the suggestion's) and every
12
+ statement it won still reads at least `negligible_kept_share` of its rows: the existing index already
13
+ finds them, the new one saves a sort or heap visits. nothing_to_gain / `already_indexed`.
14
+ negligible ("Low value fix") the kept suggestion's saving per run of the statement it helps most is under
15
+ `negligible_saved_ms` (sub-millisecond) at
16
+ the size measured (the advisor measures one size, so no growth is known: "at this size"), or every
17
+ statement it won still reads and takes most of what it did: nothing_to_gain / `negligible_gain`.
18
+
19
+ Thresholds: blockers.DEFAULTS (`[blockers]` of codecop.toml).
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ from . import worth
25
+
26
+
27
+ def _key(s: dict) -> dict | None:
28
+ k = s.get("key") or {}
29
+ cols = [c.get("column") if isinstance(c, dict) else c for c in k.get("columns") or []]
30
+ return worth.index_key({"table": s.get("table"), "columns": cols, "include": k.get("include") or [], "where": k.get("where") or "",
31
+ "method": k.get("method") or "btree"})
32
+
33
+
34
+ def _won(s: dict) -> list[dict]:
35
+ return [x for x in s.get("serves") or [] if x.get("role") == "measured"
36
+ and (x.get("honest_verdict") or x.get("verdict")) == "win" and (x.get("before") or {}).get("ok") and (x.get("after") or {}).get("ok")]
37
+
38
+
39
+ def _insert_ratio(s: dict) -> float:
40
+ wc = s.get("write_cost") or {}
41
+ r = wc.get("insert_time_ratio")
42
+ return float(r) if isinstance(r, (int, float)) else 9.9
43
+
44
+
45
+ def related(a: dict, b: dict) -> bool:
46
+ """Two keys of one table that are one index for counting: a permutation of the same columns, or one serves the other
47
+ (the same key with other INCLUDE columns, or a prefix)."""
48
+ if not a or not b or a["table"] != b["table"] or a["method"] != b["method"] or a["where"] != b["where"]:
49
+ return False
50
+ return sorted(a["columns"]) == sorted(b["columns"]) or worth.served_by(a, b) or worth.served_by(b, a)
51
+
52
+
53
+ def saving(s: dict) -> dict:
54
+ """{saved_ms, before_ms, after_ms, rows_read, kept_share, statements} over the statements the suggestion won."""
55
+ won = _won(s)
56
+ before = sum(float(x["before"].get("duration_ms") or 0) for x in won)
57
+ after = sum(float(x["after"].get("duration_ms") or 0) for x in won)
58
+ rb = sum(int(x["before"].get("read_rows") or 0) for x in won)
59
+ ra = sum(int(x["after"].get("read_rows") or 0) for x in won)
60
+ shares = [min(int(x["after"].get("read_rows") or 0) / max(int(x["before"].get("read_rows") or 0), 1),
61
+ float(x["after"].get("duration_ms") or 0) / max(float(x["before"].get("duration_ms") or 0), 1e-9)) for x in won]
62
+ each = [max(float(x["before"].get("duration_ms") or 0) - float(x["after"].get("duration_ms") or 0), 0.0) for x in won]
63
+ return {"saved_ms": round(max(each), 3) if each else 0.0, "saved_ms_all_statements": round(max(before - after, 0.0), 3),
64
+ "before_ms": round(before, 3), "after_ms": round(after, 3),
65
+ "rows_read": [rb, ra], "kept_share": round(min(shares), 4) if shares else None, "statements": len(won),
66
+ "measured_at": "one size (the advisor's scale): growth not measured"}
67
+
68
+
69
+ def statement_indexes(rank: dict | None, bench: dict | None) -> list[dict]:
70
+ """The indexes statement findings proposed and won with at the bench's largest scale: [{finding, key}] (worth.index_key)."""
71
+ scales = (bench or {}).get("scales") or []
72
+ if not scales:
73
+ return []
74
+ records = {f.get("finding"): f for f in scales[-1].get("findings") or []}
75
+ out = []
76
+ for c in (rank or {}).get("candidates") or []:
77
+ rec = records.get(c.get("finding"))
78
+ if not rec or not (rec.get("baseline") or {}).get("ok"):
79
+ continue
80
+ for i, v in enumerate(c.get("variants") or []):
81
+ got = (rec.get("variants") or [])[i] if i < len(rec.get("variants") or []) else None
82
+ if not got or got.get("verdict") != "win":
83
+ continue
84
+ k = worth.proposed_index(v)
85
+ if k:
86
+ out.append({"finding": c.get("finding"), "key": k})
87
+ return out
88
+
89
+
90
+ def statement_indexes_of(out_dir) -> list[dict]:
91
+ """statement_indexes from an out dir's rank.json and bench.json ([] when either is missing)."""
92
+ import json
93
+ from pathlib import Path
94
+ try:
95
+ return statement_indexes(json.loads((Path(out_dir) / "rank.json").read_text()), json.loads((Path(out_dir) / "bench.json").read_text()))
96
+ except (OSError, ValueError):
97
+ return []
98
+
99
+
100
+ def apply(doc: dict, settings: dict | None = None, plausible: dict[str, tuple[int, str]] | None = None,
101
+ measured_rows: dict[str, int] | None = None, frequency: dict[str, dict] | None = None,
102
+ statement_indexes: list[dict] | None = None) -> dict:
103
+ """Change, in place, the verdicts of Fixed suggestions that are alternatives of another, or negligible. Returns counts.
104
+ `plausible`: table -> (rows it plausibly reaches, where from); `measured_rows`: table -> rows at the advisor's scale.
105
+ A table measured larger than it plausibly gets has its saving scaled down to that size (linearly: the advisor measures
106
+ one size, so no growth is known); a larger plausible size is said, not projected."""
107
+ from .blockers import settings_of
108
+ cfg = settings_of(settings)
109
+ sugg = [s for s in doc.get("table_suggestions") or [] if (s.get("verdict") or {}).get("state") == "fixed"]
110
+ counts = {"same_as_another": 0, "negligible_gain": 0, "kept": 0}
111
+ keys = {id(s): _key(s) for s in sugg}
112
+ order = sorted(sugg, key=lambda s: (-len(_won(s)), _insert_ratio(s), len((keys[id(s)] or {}).get("columns") or []), s.get("id") or ""))
113
+ kept: list[dict] = []
114
+ for s in order:
115
+ k = keys[id(s)]
116
+ twin = next((x for x in statement_indexes or [] if related(k, x.get("key"))), None)
117
+ if twin is not None:
118
+ # the index of a statement finding that won with it: one fix, counted with that finding
119
+ v = s["verdict"]
120
+ s["verdict"] = {"state": "nothing_to_gain", "reason": "same_as_another", "from": "sandbox",
121
+ "evidence": {**(v.get("evidence") or {}), "same_fix_as": twin.get("finding"), "same_fix_of": "statement_finding",
122
+ "statements_served": [x.get("statement") for x in _won(s)], "verified": True}}
123
+ counts["same_as_another"] += 1
124
+ continue
125
+ best = next((g for g in kept if related(k, keys[id(g)])), None)
126
+ if best is None:
127
+ kept.append(s)
128
+ continue
129
+ v = s["verdict"]
130
+ mine = [x.get("statement") for x in _won(s)]
131
+ s["verdict"] = {"state": "nothing_to_gain", "reason": "same_as_another", "from": "sandbox",
132
+ "evidence": {**(v.get("evidence") or {}), "same_fix_as": best.get("id"), "statements_served": mine, "verified": True}}
133
+ best["verdict"].setdefault("evidence", {}).setdefault("alternatives", []).append(
134
+ {"id": s.get("id"), "ddl": (s.get("ddl") or [""])[0], "statements_served": mine,
135
+ "insert_time_ratio": (s.get("write_cost") or {}).get("insert_time_ratio")})
136
+ counts["same_as_another"] += 1
137
+ min_ms, share = float(cfg["negligible_saved_ms"]), float(cfg["negligible_kept_share"])
138
+ existing = {}
139
+ for t in doc.get("tables") or []:
140
+ existing[worth.short(t.get("table"))] = [
141
+ (ix.get("name"), worth.index_key({"table": t.get("table"), "columns": [str(c) for c in ix.get("columns") or []],
142
+ "include": ix.get("include") or [], "where": ix.get("where") or "", "method": ix.get("method") or "btree"}))
143
+ for ix in t.get("existing_indexes") or [] if not str(ix.get("name") or "").lower().startswith("codecop_")]
144
+ counts["already_indexed"] = 0
145
+ still = []
146
+ for s in kept:
147
+ k = keys[id(s)]
148
+ won = _won(s)
149
+ ext = sorted(((n, x) for n, x in existing.get((k or {}).get("table"), []) if x and worth.extends(k, x)), key=lambda nx: -len(nx[1]["columns"]))
150
+ kept_rows = [int(x["after"].get("read_rows") or 0) / max(int(x["before"].get("read_rows") or 0), 1) for x in won]
151
+ if ext and won and min(kept_rows) >= share:
152
+ v = s["verdict"]
153
+ s["verdict"] = {"state": "nothing_to_gain", "reason": "already_indexed", "from": "sandbox",
154
+ "evidence": {**(v.get("evidence") or {}), "existing_index": ext[0][0], "existing_columns": ext[0][1]["columns"],
155
+ "existing_index_is": "extended", "proposed_columns": k["columns"],
156
+ "rows_kept": round(min(kept_rows), 4), "worth": saving(s), "verified": True}}
157
+ counts["already_indexed"] += 1
158
+ continue
159
+ still.append(s)
160
+ for s in still:
161
+ m = saving(s)
162
+ if not m["before_ms"]:
163
+ counts["kept"] += 1 # no time was measured: nothing to weigh the saving with
164
+ continue
165
+ t = worth.short(s.get("table"))
166
+ size, basis = (plausible or {}).get(t, (0, ""))
167
+ at = int((measured_rows or {}).get(t) or 0)
168
+ if size and at:
169
+ m.update(at_rows=at, plausible_rows=int(size), plausible_from=basis)
170
+ if size < at:
171
+ m["saved_ms_at_plausible"] = round(m["saved_ms"] * size / at, 3)
172
+ m["saved_ms"] = m["saved_ms_at_plausible"]
173
+ v = s["verdict"]
174
+ v.setdefault("evidence", {})["worth"] = m
175
+ days = [worth.runs_per_day((frequency or {}).get(sid)) for x in _won(s) for sid in (x.get("site_ids") or [None])[:1]]
176
+ per_day = max(d for d, _ in days) if days and all(d for d, _ in days) else None
177
+ if per_day:
178
+ m.update(runs_per_day=per_day, runs_basis=next(b for d, b in days if d == per_day),
179
+ saved_s_per_day=round(m["saved_ms"] * per_day / 1000, 3))
180
+ rare = bool(per_day) and m["saved_ms"] * per_day / 1000 < float(cfg["negligible_scheduled_s_per_day"])
181
+ if m["statements"] and (m["saved_ms"] < min_ms or rare or (m["kept_share"] is not None and m["kept_share"] > share)):
182
+ s["verdict"] = {"state": "nothing_to_gain", "reason": "negligible_gain", "from": "sandbox",
183
+ "evidence": {**(v.get("evidence") or {}),
184
+ "why": "small_saving" if m["saved_ms"] < min_ms else "rare_schedule" if rare else "constant_factor",
185
+ "thresholds": {"negligible_saved_ms": min_ms, "negligible_kept_share": share}, "verified": True}}
186
+ counts["negligible_gain"] += 1
187
+ else:
188
+ counts["kept"] += 1
189
+ return counts