Many legacy codebases have significant portions of technical debt in their database design.
Many legacy codebases have significant portions of technical debt in their database design.
Such codebases tend to accumulate tons of business logic embedded in database scripts in the shape of stored procedures.
From a maintenance perspective, the quality of that database code is at least as important as the application code. In practice, that’s unfortunately not always the case, and you might find that general software principles aren’t necessarily applied to the SQL design. The consequences are database scripts that are hard to understand and, hence, expensive to maintain and extend. Let’s see how we can uncover and highlight such potential problems.
Analyze SQL Scripts
CodeScene’s main analyses are language neutral, which means that it can detect hotspots and prioritize improvements to SQL scripts too. As an example, have a look at the following analysis of the ambitiousPL/JSONproject that implements genericJSONsupport for Oracle’sPL/SQLdialect.
CodeScene identifies files that tend to be modified together.
In the preceding figure, you see a cluster of three SQL files that are often modified together. CodeScene tells us that those files tend to be changed as part of the same commit in 70% of all cases. That’s quite a strong change coupling and it indicates that those files are logically related. To find out exactlywhythese files co-evolve, we run the X-Ray analysis on that cluster. Here’s what it looks like:
X-Ray a cluster of co-changing files.
Using these X-Ray results, we narrow down our findings and get a view of the different stored procedures that co-evolve. This is data that we use either to guide our changes as we modify legacy code, or to identify refactoring opportunities. For that second purpose it’s interesting to know that CodeScene’s copy-paste detection algorithm works across multiple files too.
On to the Architectural Level
This additional support forPL/SQLanalyses open several new possibilities that will help you get deep insights into large-scale enterprise projects. As a final note, I want to point out an interesting implication of CodeScene’s support for detailed SQL analyses. With that support, you can now uncover change patterns in your whole development stack. Since CodeScene’s change coupling analysis is language neutral, it’s possible to highlight change patterns that go all the way from yourUIcode, which might be JavaScript, TypeScript or similar, all the way to your service logic in Java/C#, down to the database scripts. As CodeScene supports a concept calledlogical changesets, you might be able to get those insights even when your code is stored in different Git repositories.
Try it Yourself
ThePL/SQLX-Ray support will be included in the next release of ouron-premise versionversion. We look to add support for other SQL dialects too.Contact usif you want to know more.