-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #331 from max-208/24-java
Rule EC24 in java
- Loading branch information
Showing
4 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
], | ||
"defaultSeverity": "Major", | ||
"compatibleLanguages": [ | ||
"JAVA", | ||
"JAVASCRIPT", | ||
"TYPESCRIPT" | ||
] | ||
|
34 changes: 34 additions & 0 deletions
34
ecocode-rules-specifications/src/main/rules/EC24/java/EC24.asciidoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
:!sectids: | ||
|
||
== Why is this an issue? | ||
|
||
SQL queries often involve processing large amounts of data, and fetching a large number of rows can consume significant CPU resources. | ||
By limiting the number of rows returned, you reduce the amount of processing that needs to be done by the database engine, which in turn lowers CPU consumption. | ||
|
||
Transmitting a large number of rows over a network can be resource-intensive. | ||
By restricting the result set size, you reduce the amount of data that needs to be transferred between the database and the application, improving network efficiency. | ||
|
||
If you store data about customers, you certainly don’t need to retrieve information of all at once, because the larger the table will be, the more elements the query will return. | ||
|
||
[source,java,data-diff-id="1",data-diff-type="noncompliant"] | ||
---- | ||
String query = "SELECT * FROM customers"; // Non-compliant | ||
---- | ||
|
||
It may therefore be a good idea to limit the results and use pagination, for example. | ||
|
||
[source,java,data-diff-id="1",data-diff-type="compliant"] | ||
---- | ||
String query = "SELECT id,name,email FROM customers FETCH FIRST 10 ROWS ONLY"; // Compliant | ||
---- | ||
|
||
== Resources | ||
|
||
=== Documentation | ||
|
||
- https://dev.mysql.com/doc/refman/8.0/en/limit-optimization.html[MySQL Reference Manual] - LIMIT Query Optimization | ||
- https://www.postgresql.org/docs/current/queries-limit.html[PostgreSQL: Documentation] - LIMIT and OFFSET | ||
|
||
=== Articles & blog posts | ||
|
||
- https://www.oreilly.com/library/view/high-performance-mysql/9780596101718/ch04.html[Query Performance Optimization] |