private void addToCache(IndexDescriptor idx, StatisticsPayload payload, StatisticsPayload ftsPayload) { String tabIdxIdentifier = buildUniqueIndexIdentifier(idx); if (fIStatsCache.get(tabIdxIdentifier) == null) { if (ftsPayload.getAvgRowSize() >= payload.getAvgRowSize()) { fIStatsCache.put(tabIdxIdentifier, payload); logger.debug("Statistics: fIStatsCache:<{}, {}>",tabIdxIdentifier, payload); } else { StatisticsPayload cappedPayload = new MapRDBStatisticsPayload(ROWCOUNT_UNKNOWN, ROWCOUNT_UNKNOWN, ftsPayload.getAvgRowSize()); fIStatsCache.put(tabIdxIdentifier,cappedPayload); logger.debug("Statistics: fIStatsCache:<{}, {}> (Capped)",tabIdxIdentifier, cappedPayload); } } else { logger.debug("Statistics: Average row size already exists for :<{}, {}>. Skip!",tabIdxIdentifier, payload); } }
fullTableScanPayload = new MapRDBStatisticsPayload(payload.getRowCount(), payload.getLeadingRowCount(), payload.getAvgRowSize()); logger.debug("Statistics: StatsCache:<{}, {}>","NULL", fullTableScanPayload);
/** * Get the estimated average rowsize. DO NOT call this API directly. * Call the stats API instead which modifies the counts based on preference options. * @param index, to use for generating the estimate * @return row count post filtering */ public MapRDBStatisticsPayload getAverageRowSizeStats(IndexDescriptor index) { IndexDesc indexDesc = null; double avgRowSize = AVG_ROWSIZE_UNKNOWN; if (index != null) { indexDesc = (IndexDesc)((MapRDBIndexDescriptor)index).getOriginalDesc(); } // If no index is specified, get it from the primary table if (indexDesc == null && scanSpec.isSecondaryIndex()) { throw new UnsupportedOperationException("getAverageRowSizeStats should be invoked on primary table"); } // Get the index table or primary table and use the DB API to get the estimated number of rows. For size estimates, // we assume that all the columns would be read from the disk. final Table table = this.formatPlugin.getJsonTableCache().getTable(scanSpec.getTableName(), indexDesc, getUserName()); if (table != null) { final MetaTable metaTable = table.getMetaTable(); if (metaTable != null) { avgRowSize = metaTable.getAverageRowSize(); } } logger.debug("index_plan_info: getEstimatedRowCount obtained from DB Client for {}: indexName: {}, indexInfo: {}, " + "avgRowSize: {}, estimatedSize {}", this, (indexDesc == null ? "null" : indexDesc.getIndexName()), (indexDesc == null ? "null" : indexDesc.getIndexInfo()), avgRowSize); return new MapRDBStatisticsPayload(ROWCOUNT_UNKNOWN, ROWCOUNT_UNKNOWN, avgRowSize); }
(stats.getEstimatedNumRows() == 0 ? 0 : stats.getEstimatedSize()/stats.getEstimatedNumRows()), stats.getEstimatedSize(), stats.getTabletCount(), metaTable.getScanStats().getTabletCount(), scalingFactor); return new MapRDBStatisticsPayload(scalingFactor * stats.getEstimatedNumRows(), scalingFactor * stats.getEstimatedNumRows(), ((stats.getEstimatedNumRows() == 0 ? 0 : (double)stats.getEstimatedSize()/stats.getEstimatedNumRows()))); } else { "condition: {} rowCount: UNKNOWN, avgRowSize: UNKNOWN", this, (index == null ? "null" : index.getIndexName()), (index == null ? "null" : index.getIndexInfo()), (condition == null ? "null" : condition.toString())); return new MapRDBStatisticsPayload(ROWCOUNT_UNKNOWN, ROWCOUNT_UNKNOWN, AVG_ROWSIZE_UNKNOWN);
double leadingRowCount = Math.min(idxPayload.getLeadingRowCount(), rowCount); double avgRowSize = Math.min(idxPayload.getAvgRowSize(), ftsPayload.getAvgRowSize()); StatisticsPayload payload = new MapRDBStatisticsPayload(rowCount, leadingRowCount, avgRowSize); addToCache(idxCondition, idx, context, payload, jTabGrpScan, scanRel, newRowType); addBaseConditions(idxCondition, payload, false, baseConditionMap, scanRel.getRowType()); leadingRowCount = rowCount; avgRowSize = fIStatsCache.get(buildUniqueIndexIdentifier(idx)).getAvgRowSize(); addToCache(idxLeadColCondition, idx, context, new MapRDBStatisticsPayload(rowCount, leadingRowCount, avgRowSize), jTabGrpScan, scanRel, newRowType); addToCache(idxTotColCondition, idx, context, new MapRDBStatisticsPayload(rowCount, leadingRowCount, avgRowSize), jTabGrpScan, scanRel, newRowType); addToCache(idxCondition, idx, context, new MapRDBStatisticsPayload(rowCount, leadingRowCount, avgRowSize), jTabGrpScan, scanRel, newRowType); rowCount = ftsPayload.getRowCount() * computeSelectivity(idxIncColCondition, null, ftsPayload.getRowCount(), scanRel, baseConditionMap).left; addToCache(idxIncColCondition, idx, context, new MapRDBStatisticsPayload(rowCount, rowCount, avgRowSize), jTabGrpScan, scanRel, newRowType); addToCache(condition, null, null, new MapRDBStatisticsPayload(rowCount, ftsLeadingKeyPayload.getRowCount(), ftsPayload.getAvgRowSize()), jTabGrpScan, scanRel, scanRel.getRowType()); addToCache(null, null, null, new MapRDBStatisticsPayload(ftsPayload.getRowCount(), ftsPayload.getRowCount(), ftsPayload.getAvgRowSize()), jTabGrpScan, scanRel, scanRel.getRowType());
private void addToCache(IndexDescriptor idx, StatisticsPayload payload, StatisticsPayload ftsPayload) { String tabIdxIdentifier = buildUniqueIndexIdentifier(idx); if (fIStatsCache.get(tabIdxIdentifier) == null) { if (ftsPayload.getAvgRowSize() >= payload.getAvgRowSize()) { fIStatsCache.put(tabIdxIdentifier, payload); logger.debug("Statistics: fIStatsCache:<{}, {}>",tabIdxIdentifier, payload); } else { StatisticsPayload cappedPayload = new MapRDBStatisticsPayload(ROWCOUNT_UNKNOWN, ROWCOUNT_UNKNOWN, ftsPayload.getAvgRowSize()); fIStatsCache.put(tabIdxIdentifier,cappedPayload); logger.debug("Statistics: fIStatsCache:<{}, {}> (Capped)",tabIdxIdentifier, cappedPayload); } } else { logger.debug("Statistics: Average row size already exists for :<{}, {}>. Skip!",tabIdxIdentifier, payload); } }
fullTableScanPayload = new MapRDBStatisticsPayload(payload.getRowCount(), payload.getLeadingRowCount(), payload.getAvgRowSize()); logger.debug("Statistics: StatsCache:<{}, {}>","NULL", fullTableScanPayload);
/** * Get the estimated average rowsize. DO NOT call this API directly. * Call the stats API instead which modifies the counts based on preference options. * @param index, to use for generating the estimate * @return row count post filtering */ public MapRDBStatisticsPayload getAverageRowSizeStats(IndexDescriptor index) { IndexDesc indexDesc = null; double avgRowSize = AVG_ROWSIZE_UNKNOWN; if (index != null) { indexDesc = (IndexDesc)((MapRDBIndexDescriptor)index).getOriginalDesc(); } // If no index is specified, get it from the primary table if (indexDesc == null && scanSpec.isSecondaryIndex()) { throw new UnsupportedOperationException("getAverageRowSizeStats should be invoked on primary table"); } // Get the index table or primary table and use the DB API to get the estimated number of rows. For size estimates, // we assume that all the columns would be read from the disk. final Table table = this.formatPlugin.getJsonTableCache().getTable(scanSpec.getTableName(), indexDesc, getUserName()); if (table != null) { final MetaTable metaTable = table.getMetaTable(); if (metaTable != null) { avgRowSize = metaTable.getAverageRowSize(); } } logger.debug("index_plan_info: getEstimatedRowCount obtained from DB Client for {}: indexName: {}, indexInfo: {}, " + "avgRowSize: {}, estimatedSize {}", this, (indexDesc == null ? "null" : indexDesc.getIndexName()), (indexDesc == null ? "null" : indexDesc.getIndexInfo()), avgRowSize); return new MapRDBStatisticsPayload(ROWCOUNT_UNKNOWN, ROWCOUNT_UNKNOWN, avgRowSize); }
(stats.getEstimatedNumRows() == 0 ? 0 : stats.getEstimatedSize()/stats.getEstimatedNumRows()), stats.getEstimatedSize(), stats.getTabletCount(), metaTable.getScanStats().getTabletCount(), scalingFactor); return new MapRDBStatisticsPayload(scalingFactor * stats.getEstimatedNumRows(), scalingFactor * stats.getEstimatedNumRows(), ((stats.getEstimatedNumRows() == 0 ? 0 : (double)stats.getEstimatedSize()/stats.getEstimatedNumRows()))); } else { "condition: {} rowCount: UNKNOWN, avgRowSize: UNKNOWN", this, (index == null ? "null" : index.getIndexName()), (index == null ? "null" : index.getIndexInfo()), (condition == null ? "null" : condition.toString())); return new MapRDBStatisticsPayload(ROWCOUNT_UNKNOWN, ROWCOUNT_UNKNOWN, AVG_ROWSIZE_UNKNOWN);
double leadingRowCount = Math.min(idxPayload.getLeadingRowCount(), rowCount); double avgRowSize = Math.min(idxPayload.getAvgRowSize(), ftsPayload.getAvgRowSize()); StatisticsPayload payload = new MapRDBStatisticsPayload(rowCount, leadingRowCount, avgRowSize); addToCache(idxCondition, idx, context, payload, jTabGrpScan, scanRel, newRowType); addBaseConditions(idxCondition, payload, false, baseConditionMap, scanRel.getRowType()); leadingRowCount = rowCount; avgRowSize = fIStatsCache.get(buildUniqueIndexIdentifier(idx)).getAvgRowSize(); addToCache(idxLeadColCondition, idx, context, new MapRDBStatisticsPayload(rowCount, leadingRowCount, avgRowSize), jTabGrpScan, scanRel, newRowType); addToCache(idxTotColCondition, idx, context, new MapRDBStatisticsPayload(rowCount, leadingRowCount, avgRowSize), jTabGrpScan, scanRel, newRowType); addToCache(idxCondition, idx, context, new MapRDBStatisticsPayload(rowCount, leadingRowCount, avgRowSize), jTabGrpScan, scanRel, newRowType); rowCount = ftsPayload.getRowCount() * computeSelectivity(idxIncColCondition, null, ftsPayload.getRowCount(), scanRel, baseConditionMap).left; addToCache(idxIncColCondition, idx, context, new MapRDBStatisticsPayload(rowCount, rowCount, avgRowSize), jTabGrpScan, scanRel, newRowType); addToCache(condition, null, null, new MapRDBStatisticsPayload(rowCount, ftsLeadingKeyPayload.getRowCount(), ftsPayload.getAvgRowSize()), jTabGrpScan, scanRel, scanRel.getRowType()); addToCache(null, null, null, new MapRDBStatisticsPayload(ftsPayload.getRowCount(), ftsPayload.getRowCount(), ftsPayload.getAvgRowSize()), jTabGrpScan, scanRel, scanRel.getRowType());