← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17178: Analytics, improved performance of approval subquery

 

------------------------------------------------------------
revno: 17178
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-10-20 17:07:35 +0200
message:
  Analytics, improved performance of approval subquery
modified:
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2014-10-19 18:56:12 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2014-10-20 15:07:35 +0000
@@ -424,7 +424,7 @@
             "datasetid INTEGER, " +
             "datasetuid CHARACTER(11), " +
             "datasetname VARCHAR(250), " +
-            "approvedata BOOLEAN, " +
+            "datasetapprovedata BOOLEAN, " +
             "periodtypeid INTEGER, " + 
             "periodtypename VARCHAR(250) )";
         
@@ -435,11 +435,13 @@
         final String deUdInSql = "create unique index in_dataelementstructure_dataelementuid on _dataelementstructure(dataelementuid)";
         final String dsIdInSql = "create index in_dataelementstructure_datasetid on _dataelementstructure(datasetid)";
         final String dsUdInSql = "create index in_dataelementstructure_datasetuid on _dataelementstructure(datasetuid)";
+        final String dsApInSql = "create index in_dataelementstructure_datasetapprovedata on _dataelementstructure(datasetapprovedata)";
         final String ptIdInSql = "create index in_dataelementstructure_periodtypeid on _dataelementstructure(periodtypeid)";
         
         jdbcTemplate.execute( deUdInSql );
         jdbcTemplate.execute( dsIdInSql );
         jdbcTemplate.execute( dsUdInSql );
+        jdbcTemplate.execute( dsApInSql );
         jdbcTemplate.execute( ptIdInSql );
     }
     

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2014-10-19 21:18:10 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2014-10-20 15:07:35 +0000
@@ -213,6 +213,7 @@
             "left join _orgunitstructure ous on dv.sourceid=ous.organisationunitid " +
             "left join _periodstructure ps on dv.periodid=ps.periodid " +
             "left join dataelement de on dv.dataelementid=de.dataelementid " +
+            "left join _dataelementstructure des on de.dataelementid = des.dataelementid " +
             "left join categoryoptioncombo co on dv.categoryoptioncomboid=co.categoryoptioncomboid " +
             "left join period pe on dv.periodid=pe.periodid " +
             "where de.valuetype = '" + valueType + "' " +
@@ -232,12 +233,12 @@
     private String getApprovalSubquery( Collection<OrganisationUnitLevel> levels )
     {
         String sql = "(" +
-            "select coalesce(min(dal.level),999) " +
+            "select min(dal.level) " +
             "from dataapproval da " +
             "inner join dataapprovallevel dal on da.dataapprovallevelid = dal.dataapprovallevelid " +
-            "inner join _dataelementstructure des on da.datasetid = des.datasetid and des.dataelementid = dv.dataelementid " +
             "where da.periodid = dv.periodid " +
-            "and des.approvedata = true " +
+            "and des.datasetid = da.datasetid " +
+            "and des.datasetapprovedata = true " +
             "and (";
         
         for ( OrganisationUnitLevel level : levels )