by noduerme · 1y ago · 0 comments
This month, however, I had to start upgrading a very large db from MySQL 8 to 9, on a codebase that involves a few hundred long and complex queries. I wrote this code, so I know what they do and I understand the schema, but I'm also aware that some of them may violate ONLY_FULL_GROUP_BY, and a few (but can't remember which) had historical oddities unless DERIVED_MERGE was turned off. I was girding myself to run tests on dozens of suspects, but as a lark I handed Claude the whole codebase and the schema and asked it to identify any queries that might break if those two default options were enabled. Astonishingly, it did. It identified 15 queries and explained what they violated. It was wrong about 7 of them... those seven were actually fine, and it acknowledged that it had farmed this out in some way and that whatever it used for evaluation had been overly conservative and had returned false positives. But the other 8 queries were fixable. It was also a bit off about how to rewrite them - it created a lot of slow and inefficient workarounds. It neglected the idea of lateral joins, it didn't write SQL optimized for the indexes, etc. But it saved me hours and hours of locating these queries myself.
To me, this idea of letting the LLM render down a lot of code into potential pain points seems like a much more valuable use of it than asking it to write code itself. I kept my subscription for that reason.
From that I usually get a list of file+lines to manually review, along with some initial leads to chase.
Another use case is when fixing performance issues. I can feature flag my fix and ask the model to confirm the new code path will produce the same result for a given set of inputs. We also have test coverage for this kind of thing, but the LLM can do a once-over and point out some flaws before I ever run those tests.
I haven’t gotten to the point where it writes much code for me beyond the auto-complete, which has been a modest boost in efficiency.
I guess I wouldn't trust it to confirm that new code would give the same result, but it can't hurt to ask, since if it told me the code wouldn't, that would make me look more closely at it.
I think as long as you look at it as part of a distillation process, and aim for false positives, and never actually trust it, it's good at helping to surface issues you may have missed.