Database servers have to resolve schema fields when using asterisk symbol (*). Knowing and using the schema saves CPU cycles and network transfer.

Non compliant Code Example

public function foo() {
    ...
    $baseQuery = "SELECT * FROM users"; // Noncompliant
    ...
}

Compliant Solution

public function foo() {
    ...
    $baseQuery = "SELECT id,name, address FROM users ";
    ...
}

The three sources of impacts of a code identified are:

  • Energy: measured in joules (J)

  • Transfer: measured in Bytes (B)

  • Storage: measured in Bytes (B)

The control of these 3 impacts allows to lengthen the life of the terminals as well as reduce their energy consumption.

The ETSdiff tool allows measuring a differential on these three values and in a given context (database and fixed measurement environment).

The results generated by ETSdiff must help define the interest of the rule reported by SonarQube in the context of the code analyzed.

Case for a 1GB database:

ETSdiff percent comparison
Source of impacts Compliant Non-compliant

Energy (J)

0.040610499999999994

0.065223

Transfer (B)

779232

2697937

Storage (B)

637548827

637548827