001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2012-2012 Pentaho 008// All Rights Reserved. 009*/ 010package mondrian.spi; 011 012import mondrian.server.Execution; 013 014import javax.sql.DataSource; 015 016/** 017 * Provides estimates of the number of rows in a database. 018 * 019 * <p>Mondrian generally finds statistics providers via the 020 * {@link Dialect#getStatisticsProviders} method on the dialect object for the 021 * current connection. The default implementation of that method looks first at 022 * the "mondrian.statistics.providers.DATABASE" property (substituting the 023 * current database name, e.g. MYSQL or ORACLE, for <i>DATABASE</i>), then at 024 * the {@link mondrian.olap.MondrianProperties#StatisticsProviders "mondrian.statistics.providers"} 025 * property.</p> 026 * 027 * @see mondrian.spi.impl.JdbcStatisticsProvider 028 * @see mondrian.spi.impl.SqlStatisticsProvider 029 * 030 */ 031public interface StatisticsProvider { 032 /** 033 * Returns an estimate of the number of rows in a table. 034 * 035 * @param dialect Dialect 036 * @param dataSource Data source 037 * @param catalog Catalog name 038 * @param schema Schema name 039 * @param table Table name 040 * @param execution Execution 041 * 042 * @return Estimated number of rows in table, or -1 if there 043 * is no estimate 044 */ 045 int getTableCardinality( 046 Dialect dialect, 047 DataSource dataSource, 048 String catalog, 049 String schema, 050 String table, 051 Execution execution); 052 053 /** 054 * Returns an estimate of the number of rows returned by a query. 055 * 056 * @param dialect Dialect 057 * @param dataSource Data source 058 * @param sql Query, e.g. "select * from customers where age < 20" 059 * @param execution Execution 060 * 061 * @return Estimated number of rows returned by query, or -1 if there 062 * is no estimate 063 */ 064 int getQueryCardinality( 065 Dialect dialect, 066 DataSource dataSource, 067 String sql, 068 Execution execution); 069 070 /** 071 * Returns an estimate of the number of rows in a table. 072 * 073 * @param dialect Dialect 074 * @param dataSource Data source 075 * @param catalog Catalog name 076 * @param schema Schema name 077 * @param table Table name 078 * @param column Column name 079 * @param execution Execution 080 * 081 * @return Estimated number of rows in table, or -1 if there 082 * is no estimate 083 */ 084 int getColumnCardinality( 085 Dialect dialect, 086 DataSource dataSource, 087 String catalog, 088 String schema, 089 String table, 090 String column, 091 Execution execution); 092} 093 094// End StatisticsProvider.java