lowka commented on code in PR #4180:
URL: https://github.com/apache/ignite-3/pull/4180#discussion_r1705832473


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/schema/SqlSchemaManagerImpl.java:
##########
@@ -365,63 +428,154 @@ private static CatalogColumnDescriptor 
createColumnDescriptor(CatalogTableColumn
         return columnDescriptor;
     }
 
-    private static IgniteTable createTable(
+    private IgniteTableImpl createTableDataOnlyTable(
             Catalog catalog,
-            CatalogTableDescriptor tableDescriptor
+            CatalogTableDescriptor table,
+            TableDescriptor descriptor
     ) {
-        TableDescriptor descriptor = 
createTableDescriptorForTable(tableDescriptor);
+        Map<String, IgniteIndex> tableIndexes = getIndexes(catalog,
+                table.id(),
+                table.primaryKeyIndexId()
+        );
 
+        CatalogZoneDescriptor zoneDescriptor = getZoneDescriptor(catalog, 
table.zoneId());
+
+        return createTable(table, descriptor, tableIndexes, 
zoneDescriptor.partitions());
+    }
+
+    private Map<String, IgniteIndex> getIndexes(Catalog catalog, int tableId, 
int primaryKeyIndexId) {
         Map<String, IgniteIndex> tableIndexes = new HashMap<>();
-        for (CatalogIndexDescriptor indexDescriptor : 
catalog.indexes(tableDescriptor.id())) {
+        CatalogTableDescriptor table = catalog.table(tableId);
+        assert table != null;
+
+        for (CatalogIndexDescriptor indexDescriptor : 
catalog.indexes(tableId)) {
             if (indexDescriptor.status() != AVAILABLE) {
                 continue;
             }
 
             String indexName = indexDescriptor.name();
+            long indexKey = cacheKey(indexDescriptor.id(), 
indexDescriptor.status().id());
 
-            IgniteIndex schemaIndex = createSchemaIndex(
-                    indexDescriptor,
-                    descriptor,
-                    indexDescriptor.id() == tableDescriptor.primaryKeyIndexId()
-            );
+            IgniteIndex schemaIndex = indexCache.get(indexKey, (x) -> {
+                RelCollation outputCollation = 
IgniteIndex.createIndexCollation(indexDescriptor, table);
+                Object2IntMap<String> columnToIndex = 
buildColumnToIndexMap(table.columns());
+                IgniteDistribution distribution = createDistribution(table, 
columnToIndex);
+
+                return createSchemaIndex(
+                        indexDescriptor,
+                        outputCollation,
+                        distribution,
+                        indexDescriptor.id() == primaryKeyIndexId
+                );
+            });
 
             tableIndexes.put(indexName, schemaIndex);
         }
 
-        int zoneId = tableDescriptor.zoneId();
+        return tableIndexes;
+    }
+
+    private static CatalogZoneDescriptor getZoneDescriptor(Catalog catalog, 
int zoneId) {
         CatalogZoneDescriptor zoneDescriptor = catalog.zone(zoneId);
         assert zoneDescriptor != null : "Zone is not found in schema: " + 
zoneId;
 
-        return createTable(tableDescriptor, descriptor, tableIndexes, 
zoneDescriptor.partitions());
+        return zoneDescriptor;
     }
 
-    private static IgniteTable createTable(
+    private static IgniteTableImpl createTable(
             CatalogTableDescriptor catalogTableDescriptor,
             TableDescriptor tableDescriptor,
             Map<String, IgniteIndex> indexes,
             int parititions
     ) {
+        IgniteIndex primaryIndex = indexes.values().stream()
+                .filter(IgniteIndex::primaryKey)
+                .findFirst()
+                .orElseThrow();
+
+        // We do not need any index other than the primary index,
+        // all other indexes are stored in full table data cache.
+        Map<String, IgniteIndex> primaryKeyOnlyMap = 
Map.of(primaryIndex.name(), primaryIndex);
+
+        ImmutableIntList primaryKeyColumns = 
primaryIndex.collation().getKeys();
+
         int tableId = catalogTableDescriptor.id();
         String tableName = catalogTableDescriptor.name();
 
         // TODO IGNITE-19558: The table is not available at planning stage.
         // Let's fix table statistics keeping in mind IGNITE-19558 issue.
         IgniteStatistic statistic = new IgniteStatistic(() -> 0.0d, 
tableDescriptor.distribution());
 
-        IgniteIndex primaryIndex = indexes.values().stream()
-                .filter(IgniteIndex::primaryKey)
-                .findFirst()
-                .orElseThrow();
-
         return new IgniteTableImpl(
                 tableName,
                 tableId,
                 catalogTableDescriptor.tableVersion(),
                 tableDescriptor,
-                primaryIndex.collation().getKeys(),
+                primaryKeyColumns,
                 statistic,
-                indexes,
+                primaryKeyOnlyMap,
                 parititions
         );
     }
+
+    private static class ActualIgniteTable extends AbstractIgniteDataSource 
implements IgniteTable {
+
+        /** Cached table by id an version. */

Review Comment:
   Fixed. 
   I think the comment for `Cache<Long, IgniteTableImpl> tableCache` already 
includes this information.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to