Skip to content

Commit

Permalink
MONDRIAN: Oracle can only handle up to 1000 expressions inside an IN(…
Browse files Browse the repository at this point in the history
…...) clause

[git-p4: depot-paths = "//open/mondrian/": change = 2190]
  • Loading branch information
Andreas Voss committed Jun 22, 2004
1 parent dfa33d0 commit e5cfd82
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/main/mondrian/rolap/agg/Aggregation.java
Expand Up @@ -11,6 +11,9 @@
*/

package mondrian.rolap.agg;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -24,6 +27,7 @@
import mondrian.rolap.RolapStar;
import mondrian.rolap.cache.CachePool;
import mondrian.rolap.cache.SoftCacheableReference;
import mondrian.rolap.sql.SqlQuery;

/**
* A <code>Aggregation</code> is a pre-computed aggregation over a set of
Expand Down Expand Up @@ -72,11 +76,31 @@ public class Aggregation
RolapStar.Column[] columns;
/** List of soft references to segments. **/
List segmentRefs;
boolean oracle = false;

Aggregation(RolapStar star, RolapStar.Column[] columns) {
this.star = star;
this.columns = columns;
this.segmentRefs = Collections.synchronizedList(new ArrayList());

// find out if this is an oracle DB
Connection con = null;
try {
con = star.getJdbcConnection();
DatabaseMetaData md = con.getMetaData();
SqlQuery sqlQuery = new SqlQuery(md);
this.oracle = sqlQuery.isOracle();
} catch (SQLException e) {
throw Util.newInternal(e, "could not query Metadata");
} finally {
if (con != null) {
try {
con.close();
} catch (SQLException e) {
// ignore
}
}
}
}

/**
Expand Down Expand Up @@ -115,6 +139,7 @@ public synchronized Object[][] optimizeConstraints(Object[][] constraintses)
{
Util.assertTrue(constraintses.length == columns.length);
Object[][] newConstraintses = (Object[][]) constraintses.clone();

// build a list of constraints sorted by 'bloat factor'
ConstraintComparator comparator = new ConstraintComparator(
constraintses);
Expand All @@ -129,6 +154,20 @@ public synchronized Object[][] optimizeConstraints(Object[][] constraintses)
// doubles and is greater than 100
double originalCellCount = cellCount,
maxCellCount = originalCellCount * 2 + 10;

// Oracle can only handle up to 1000 elements inside an IN(..) clause
if (oracle) {
final int MAXLEN = 1000;
for (int i = 0; i < newConstraintses.length; i++) {
Object[] arr = newConstraintses[i];
if (arr != null && arr.length > MAXLEN) {
double bloat = comparator.getBloat(i);
cellCount *= bloat;
newConstraintses[i] = null;
}
}
}

for (int i = 0; i < indexes.length; i++) {
int j = indexes[i].intValue();
double bloat = comparator.getBloat(j);
Expand Down

0 comments on commit e5cfd82

Please sign in to comment.