org.apache.ignite.internal.processors.query

## Interface GridQueryIndexing

    public interface GridQueryIndexing

Abstraction for internal indexing implementation.

### Method Summary

All Methods Instance Methods Abstract Methods
`IndexingQueryFilter` `backupFilter(AffinityTopologyVersion topVer, int[] parts)` Returns backup filter.
`void` `cancelQueries(Collection<Long> queries)` Cancel specified queries.
`Collection<ColumnInformation>` `columnsInformation(String schemaNamePtrn, String tblNamePtrn, String colNamePtrn)` Return column information filtered by given patterns.
`void` `destroyOrphanIndex(RootPage page, String indexName, int grpId, PageMemory pageMemory, GridAtomicLong removeId, ReuseList reuseList, boolean mvccEnabled)` Destroy founded index which belongs to stopped cache.
`void` `dynamicAddColumn(String schemaName, String tblName, List<QueryField> cols, boolean ifTblExists, boolean ifColNotExists)` Add columns to dynamic table.
`void` `dynamicDropColumn(String schemaName, String tblName, List<String> cols, boolean ifTblExists, boolean ifColExists)` Drop columns from dynamic table.
`void` `dynamicIndexCreate(String schemaName, String tblName, QueryIndexDescriptorImpl idxDesc, boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor)` Create new index locally.
`void` `dynamicIndexDrop(String schemaName, String idxName, boolean ifExists)` Remove index from the cache.
`UpdateSourceIterator<?>` `executeUpdateOnDataNodeTransactional(GridCacheContext<?,?> cctx, int[] ids, int[] parts, String schema, String qry, Object[] params, int flags, int pageSize, int timeout, AffinityTopologyVersion topVer, MvccSnapshot mvccSnapshot, GridQueryCancel cancel)`
`SqlFieldsQuery` `generateFieldsQuery(String cacheName, SqlQuery qry)` Generate SqlFieldsQuery from SqlQuery.
`boolean` `initCacheContext(GridCacheContext ctx)` Initialize table's cache context created for not started cache.
`boolean` `isStreamableInsertStatement(String schemaName, SqlFieldsQuery sql)` Whether passed sql statement is single insert statement eligible for streaming.
`void` `markAsRebuildNeeded(GridCacheContext cctx)` Mark as rebuild needed for the given cache.
`void` `onClientDisconnect()` Performs necessary actions on disconnect of a stateful client (say, one associated with a transaction).
`void` `onDisconnected(IgniteFuture<?> reconnectFut)` Client disconnected callback.
`void` `onKernalStop()` Cancels all executing queries.
`List<JdbcParameterMeta>` `parameterMetaData(String schemaName, SqlFieldsQuery sql)` Jdbc parameters metadata of the specified query.
`<K,V> GridCloseableIterator<IgniteBiTuple<K,V>>` `queryLocalText(String schemaName, String cacheName, String qry, String typeName, IndexingQueryFilter filter, int limit)` Executes text query.
`List<FieldsQueryCursor<List<?>>>` `querySqlFields(String schemaName, SqlFieldsQuery qry, SqlClientContext cliCtx, boolean keepBinary, boolean failOnMultipleStmts, GridQueryCancel cancel)` Detect whether SQL query should be executed in distributed or local manner and execute it.
`IgniteInternalFuture<?>` `rebuildIndexesFromHash(GridCacheContext cctx)` Rebuild indexes for the given cache if necessary.
`void` `registerCache(String cacheName, String schemaName, GridCacheContextInfo<?,?> cacheInfo)` Registers cache.
`@Nullable GridCacheContextInfo` `registeredCacheInfo(String cacheName)` Return context for registered cache info.
`void` `registerMxBeans(IgniteMBeansManager mbMgr)` Register SQL JMX beans.
`boolean` `registerType(GridCacheContextInfo cacheInfo, GridQueryTypeDescriptor desc, boolean isSql)` Registers type if it was not known before or updates it otherwise.
`void` `remove(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row)` Removes index entry by key.
`@Nullable List<GridQueryFieldMetadata>` `resultMetaData(String schemaName, SqlFieldsQuery sql)` Metadata of the result set that is returned if specified query gets executed.
`GridQueryRowCacheCleaner` `rowCacheCleaner(int cacheGroupId)` Return row cache cleaner.
`Collection<GridRunningQueryInfo>` `runningQueries(long duration)` Collect queries that already running more than specified duration.
`String` `schema(String cacheName)` Gets database schema from cache name.
`Set<String>` `schemasNames()` Gets database schemas names.
`void` `start(GridKernalContext ctx, GridSpinBusyLock busyLock)` Starts indexing.
`void` `stop()` Stops indexing.
`void` `store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row, CacheDataRow prevRow, boolean prevRowAvailable)` Updates index.
`List<Long>` `streamBatchedUpdateQuery(String schemaName, String qry, List<Object[]> params, SqlClientContext cliCtx)` Execute a batched INSERT statement using data streamer as receiver.
`long` `streamUpdateQuery(String schemaName, String qry, @Nullable Object[] params, IgniteDataStreamer<?,?> streamer)` Execute an INSERT statement using data streamer as receiver.
`Collection<TableInformation>` `tablesInformation(String schemaNamePtrn, String tblNamePtrn, String... tblTypes)` Return table information filtered by given patterns.
`void` `unregisterCache(GridCacheContextInfo cacheInfo, boolean rmvIdx)` Unregisters cache.

### Method Detail

#### start

    void start(GridKernalContext ctx,
               GridSpinBusyLock busyLock)
        throws IgniteCheckedException

Starts indexing.

Parameters:
  `ctx` - Context.
  `busyLock` - Busy lock.
Throws:
  `IgniteCheckedException` - If failed.

#### stop

    void stop()
       throws IgniteCheckedException

Stops indexing.

Throws:
  `IgniteCheckedException` - If failed.

#### onClientDisconnect

    void onClientDisconnect()
                     throws IgniteCheckedException

Performs necessary actions on disconnect of a stateful client (say, one associated with a transaction).

Throws:
  `IgniteCheckedException` - If failed.

#### generateFieldsQuery

    SqlFieldsQuery generateFieldsQuery(String cacheName,
                                       SqlQuery qry)

Generate SqlFieldsQuery from SqlQuery.

Parameters:
  `cacheName` - Cache name.
  `qry` - Query.
Returns:
  Fields query.

#### querySqlFields

    List<FieldsQueryCursor<List<?>>> querySqlFields(String schemaName,
                                                    SqlFieldsQuery qry,
                                                    SqlClientContext cliCtx,
                                                    boolean keepBinary,
                                                    boolean failOnMultipleStmts,
                                                    GridQueryCancel cancel)

Detect whether SQL query should be executed in distributed or local manner and execute it.

Parameters:
  `schemaName` - Schema name.
  `qry` - Query.
  `cliCtx` - Client context.
  `keepBinary` - Keep binary flag.
  `failOnMultipleStmts` - Whether an exception should be thrown for multiple statements query.
Returns:
  Cursor.

#### streamUpdateQuery

    long streamUpdateQuery(String schemaName,
                           String qry,
                           @Nullable
                           @Nullable Object[] params,
                           IgniteDataStreamer<?,?> streamer)
                    throws IgniteCheckedException

Execute an INSERT statement using data streamer as receiver.

Parameters:
  `schemaName` - Schema name.
  `qry` - Query.
  `params` - Query parameters.
  `streamer` - Data streamer to feed data to.
Returns:
  Update counter.
Throws:
  `IgniteCheckedException` - If failed.

#### streamBatchedUpdateQuery

    List<Long> streamBatchedUpdateQuery(String schemaName,
                                        String qry,
                                        List<Object[]> params,
                                        SqlClientContext cliCtx)
                                 throws IgniteCheckedException

Execute a batched INSERT statement using data streamer as receiver.

Parameters:
  `schemaName` - Schema name.
  `qry` - Query.
  `params` - Query parameters.
  `cliCtx` - Client connection context.
Returns:
  Update counters.
Throws:
  `IgniteCheckedException` - If failed.

#### queryLocalText

    <K,V> GridCloseableIterator<IgniteBiTuple<K,V>> queryLocalText(String schemaName,
                                                                   String cacheName,
                                                                   String qry,
                                                                   String typeName,
                                                                   IndexingQueryFilter filter,
                                                                   int limit)
                                                            throws IgniteCheckedException

Executes text query.

Parameters:
  `schemaName` - Schema name.
  `cacheName` - Cache name.
  `qry` - Text query.
  `typeName` - Type name.
  `filter` - Cache name and key filter. @return Queried rows.
  `limit` - Limits response records count. If 0 or less, the limit considered to be Integer.MAX_VALUE, that is virtually no limit.
Throws:
  `IgniteCheckedException` - If failed.

#### dynamicIndexCreate

    void dynamicIndexCreate(String schemaName,
                            String tblName,
                            QueryIndexDescriptorImpl idxDesc,
                            boolean ifNotExists,
                            SchemaIndexCacheVisitor cacheVisitor)
                     throws IgniteCheckedException

Create new index locally.

Parameters:
  `schemaName` - Schema name.
  `tblName` - Table name.
  `idxDesc` - Index descriptor.
  `ifNotExists` - Ignore operation if index exists (instead of throwing an error).
  `cacheVisitor` - Cache visitor
Throws:
  `IgniteCheckedException` - if failed.

#### dynamicIndexDrop

    void dynamicIndexDrop(String schemaName,
                          String idxName,
                          boolean ifExists)
                   throws IgniteCheckedException

Remove index from the cache.

Parameters:
  `schemaName` - Schema name.
  `idxName` - Index name.
  `ifExists` - Ignore operation if index does not exist (instead of throwing an error).
Throws:
  `IgniteCheckedException` - If failed.

#### dynamicAddColumn

    void dynamicAddColumn(String schemaName,
                          String tblName,
                          List<QueryField> cols,
                          boolean ifTblExists,
                          boolean ifColNotExists)
                   throws IgniteCheckedException

Add columns to dynamic table.

Parameters:
  `schemaName` - Schema name.
  `tblName` - Table name.
  `cols` - Columns to add.
  `ifTblExists` - Ignore operation if target table does not exist (instead of throwing an error).
  `ifColNotExists` - Ignore operation if column already exists (instead of throwing an error) - is honored only for single column case.
Throws:
  `IgniteCheckedException` - If failed.

#### dynamicDropColumn

    void dynamicDropColumn(String schemaName,
                           String tblName,
                           List<String> cols,
                           boolean ifTblExists,
                           boolean ifColExists)
                    throws IgniteCheckedException

Drop columns from dynamic table.

Parameters:
  `schemaName` - Schema name.
  `tblName` - Table name.
  `cols` - Columns to drop.
  `ifTblExists` - Ignore operation if target table does not exist (instead of throwing an error).
  `ifColExists` - Ignore operation if column does not exist (instead of throwing an error) - is honored only for single column case.
Throws:
  `IgniteCheckedException` - If failed.

#### registerCache

    void registerCache(String cacheName,
                       String schemaName,
                       GridCacheContextInfo<?,?> cacheInfo)
                throws IgniteCheckedException

Registers cache.

Parameters:
  `cacheName` - Cache name.
  `schemaName` - Schema name.
  `cacheInfo` - Cache context info.
Throws:
  `IgniteCheckedException` - If failed.

#### unregisterCache

    void unregisterCache(GridCacheContextInfo cacheInfo,
                         boolean rmvIdx)
                  throws IgniteCheckedException

Unregisters cache.

Parameters:
  `cacheInfo` - Cache context info.
  `rmvIdx` - If `true`, will remove index.
Throws:
  `IgniteCheckedException` - If failed to drop cache schema.

#### destroyOrphanIndex

    void destroyOrphanIndex(RootPage page,
                            String indexName,
                            int grpId,
                            PageMemory pageMemory,
                            GridAtomicLong removeId,
                            ReuseList reuseList,
                            boolean mvccEnabled)
                     throws IgniteCheckedException

Destroy founded index which belongs to stopped cache.

Parameters:
  `page` - Root page.
  `indexName` - Index name.
  `grpId` - Group id which contains garbage.
  `pageMemory` - Page memory to work with.
  `removeId` - Global remove id.
  `reuseList` - Reuse list where free pages should be stored.
  `mvccEnabled` - Is mvcc enabled for group or not.
Throws:
  `IgniteCheckedException` - If failed.

#### executeUpdateOnDataNodeTransactional

    UpdateSourceIterator<?> executeUpdateOnDataNodeTransactional(GridCacheContext<?,?> cctx,
                                                                 int[] ids,
                                                                 int[] parts,
                                                                 String schema,
                                                                 String qry,
                                                                 Object[] params,
                                                                 int flags,
                                                                 int pageSize,
                                                                 int timeout,
                                                                 AffinityTopologyVersion topVer,
                                                                 MvccSnapshot mvccSnapshot,
                                                                 GridQueryCancel cancel)
                                                          throws IgniteCheckedException

Parameters:
  `cctx` - Cache context.
  `ids` - Involved cache ids.
  `parts` - Partitions.
  `schema` - Schema name.
  `qry` - Query string.
  `params` - Query parameters.
  `flags` - Flags.
  `pageSize` - Fetch page size.
  `timeout` - Timeout.
  `topVer` - Topology version.
  `mvccSnapshot` - MVCC snapshot.
  `cancel` - Query cancel object.
Returns:
  Cursor over entries which are going to be changed.
Throws:
  `IgniteCheckedException` - If failed.

#### registerType

    boolean registerType(GridCacheContextInfo cacheInfo,
                         GridQueryTypeDescriptor desc,
                         boolean isSql)
                  throws IgniteCheckedException

Registers type if it was not known before or updates it otherwise.

Parameters:
  `cacheInfo` - Cache context info.
  `desc` - Type descriptor.
  `isSql` - `true` in case table has been created from SQL.
Returns:
  `True` if type was registered, `false` if for some reason it was rejected.
Throws:
  `IgniteCheckedException` - If failed.

#### parameterMetaData

    List<JdbcParameterMeta> parameterMetaData(String schemaName,
                                              SqlFieldsQuery sql)
                                       throws IgniteSQLException

Jdbc parameters metadata of the specified query.

Parameters:
  `schemaName` - the default schema name for query.
  `sql` - Sql query.
Returns:
  metadata describing all the parameters, even in case of multi-statement.
Throws:
  `SQLException` - if failed to get meta.
  `IgniteSQLException`

#### resultMetaData

    @Nullable
    @Nullable List<GridQueryFieldMetadata> resultMetaData(String schemaName,
                                                                    SqlFieldsQuery sql)
                                                             throws IgniteSQLException

Metadata of the result set that is returned if specified query gets executed.

Parameters:
  `schemaName` - the default schema name for query.
  `sql` - Sql query.
Returns:
  metadata or `null` if provided query is multi-statement or id it's not a SELECT statement.
Throws:
  `SQLException` - if failed to get meta.
  `IgniteSQLException`

#### store

    void store(GridCacheContext cctx,
               GridQueryTypeDescriptor type,
               CacheDataRow row,
               CacheDataRow prevRow,
               boolean prevRowAvailable)
        throws IgniteCheckedException

Updates index. Note that key is unique for cache, so if cache contains multiple indexes the key should be removed from indexes other than one being updated.

Parameters:
  `cctx` - Cache context.
  `type` - Type descriptor.
  `row` - New row.
  `prevRow` - Previous row.
  `prevRowAvailable` - Whether previous row is available.
Throws:
  `IgniteCheckedException` - If failed.

#### remove

    void remove(GridCacheContext cctx,
                GridQueryTypeDescriptor type,
                CacheDataRow row)
         throws IgniteCheckedException

Removes index entry by key.

Parameters:
  `cctx` - Cache context.
  `type` - Type descriptor.
  `row` - Row.
Throws:
  `IgniteCheckedException` - If failed.

#### rebuildIndexesFromHash

    IgniteInternalFuture<?> rebuildIndexesFromHash(GridCacheContext cctx)

Rebuild indexes for the given cache if necessary.

Parameters:
  `cctx` - Cache context.
Returns:
  Future completed when index rebuild finished.

#### markAsRebuildNeeded

    void markAsRebuildNeeded(GridCacheContext cctx)

Mark as rebuild needed for the given cache.

Parameters:
  `cctx` - Cache context.

#### backupFilter

    IndexingQueryFilter backupFilter(AffinityTopologyVersion topVer,
                                     int[] parts)

Returns backup filter.

Parameters:
  `topVer` - Topology version.
  `parts` - Partitions.
Returns:
  Backup filter.

#### onDisconnected

    void onDisconnected(IgniteFuture<?> reconnectFut)

Client disconnected callback.

Parameters:
  `reconnectFut` - Reconnect future.

#### runningQueries

    Collection<GridRunningQueryInfo> runningQueries(long duration)

Collect queries that already running more than specified duration.

Parameters:
  `duration` - Duration to check.
Returns:
  Collection of long running queries.

#### cancelQueries

    void cancelQueries(Collection<Long> queries)

Cancel specified queries.

Parameters:
  `queries` - Queries ID's to cancel.

#### onKernalStop

    void onKernalStop()

Cancels all executing queries.

#### schema

    String schema(String cacheName)

Gets database schema from cache name.

Parameters:
  `cacheName` - Cache name. `null` would be converted to an empty string.
Returns:
  Schema name. Should not be null since we should not fail for an invalid cache name.

#### schemasNames

    Set<String> schemasNames()

Gets database schemas names.

Returns:
  Schema names.

#### isStreamableInsertStatement

    boolean isStreamableInsertStatement(String schemaName,
                                        SqlFieldsQuery sql)
                                 throws SQLException

Whether passed sql statement is single insert statement eligible for streaming.

Parameters:
  `schemaName` - name of the schema.
  `sql` - sql statement.
Throws:
  `SQLException`

#### rowCacheCleaner

    GridQueryRowCacheCleaner rowCacheCleaner(int cacheGroupId)

Return row cache cleaner.

Parameters:
  `cacheGroupId` - Cache group id.
Returns:
  Row cache cleaner.

#### registeredCacheInfo

    @Nullable
    @Nullable GridCacheContextInfo registeredCacheInfo(String cacheName)

Return context for registered cache info.

Parameters:
  `cacheName` - Cache name.
Returns:
  Cache context for registered cache or `null` in case the cache has not been registered.

#### initCacheContext

    boolean initCacheContext(GridCacheContext ctx)
                      throws IgniteCheckedException

Initialize table's cache context created for not started cache.

Parameters:
  `ctx` - Cache context.
Returns:
  `true` If context has been initialized.
Throws:
  `IgniteCheckedException` - If failed.

#### registerMxBeans

    void registerMxBeans(IgniteMBeansManager mbMgr)
                  throws IgniteCheckedException

Register SQL JMX beans.

Parameters:
  `mbMgr` - Ignite MXBean manager.
Throws:
  `IgniteCheckedException` - On bean registration error.

#### tablesInformation

    Collection<TableInformation> tablesInformation(String schemaNamePtrn,
                                                   String tblNamePtrn,
                                                   String... tblTypes)

Return table information filtered by given patterns.

Parameters:
  `schemaNamePtrn` - Filter by schema name. Can be `null` to don't use the filter.
  `tblNamePtrn` - Filter by table name. Can be `null` to don't use the filter.
  `tblTypes` - Filter by table type. As Of now supported only 'TABLES' and 'VIEWS'. Can be `null` or empty to don't use the filter.
Returns:
  Column information filtered by given patterns.

#### columnsInformation

    Collection<ColumnInformation> columnsInformation(String schemaNamePtrn,
                                                     String tblNamePtrn,
                                                     String colNamePtrn)

Return column information filtered by given patterns.

Parameters:
  `schemaNamePtrn` - Filter by schema name. Can be `null` to don't use the filter.
  `tblNamePtrn` - Filter by table name. Can be `null` to don't use the filter.
  `colNamePtrn` - Filter by column name. Can be `null` to don't use the filter.
Returns:
  Column information filtered by given patterns.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.8.0
Release Date | : February 27 2020