[ https://issues.apache.org/jira/browse/PHOENIX-1367?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15390858#comment-15390858 ]
James Taylor edited comment on PHOENIX-1367 at 7/23/16 10:33 PM: ----------------------------------------------------------------- This isn't a duplicate of PHOENIX-1499 after all (and thanks for the test, [~cody.mar...@gmail.com]). We currently only load the indexes on the view being used and on the physical table. To fix this, we can navigate the parent view link instead of the physical table link in MetaDataClient.addIndexesFromPhysicalTable(): {code} String physicalName = view.getPhysicalName().getString(); String schemaName = SchemaUtil.getSchemaNameFromFullName(physicalName); String tableName = SchemaUtil.getTableNameFromFullName(physicalName); {code} We're currently capturing the parent of a view in LinkType.PARENT_TABLE here in MetaDataClient.createTableInternal(): {code} // Add row linking from view to its parent table // FIXME: not currently used, but see PHOENIX-1367 // as fixing that will require it's usage. PreparedStatement linkStatement = connection.prepareStatement(CREATE_VIEW_LINK); linkStatement.setString(1, tenantIdStr); linkStatement.setString(2, schemaName); linkStatement.setString(3, tableName); linkStatement.setString(4, parent.getName().getString()); linkStatement.setByte(5, LinkType.PARENT_TABLE.getSerializedValue()); linkStatement.setString(6, parent.getTenantId() == null ? null : parent.getTenantId().getString()); linkStatement.execute(); {code} We're currently ignoring this link when we build the PTable in MetaDataEndPointImpl.getTable(), but we can capture it here easily: {code} if (colName.getString().isEmpty() && famName != null) { LinkType linkType = LinkType.fromSerializedValue(colKv.getValueArray()[colKv.getValueOffset()]); if (linkType == LinkType.INDEX_TABLE) { addIndexToTable(tenantId, schemaName, famName, tableName, clientTimeStamp, indexes); } else if (linkType == LinkType.PHYSICAL_TABLE) { physicalTables.add(famName); } // TODO else if (link_type == LinkType.PARENT_TABLE) {code} and then pass it through when the PTable is constructed. There's one corner case in that if a view doesn't have a link of type PARENT_TABLE, that means that it's parent is the physical table. We only pass a parent table for an INDEX currently, but we can pass it for a VIEW now as well, in which case for a view table.getParentSchemaName()/getParentTableName()/getParentName() will return it's parent view name. {code} return PTableImpl.makePTable(tenantId, schemaName, tableName, tableType, indexState, timeStamp, tableSeqNum, pkName, saltBucketNum, columns, tableType == INDEX ? schemaName : null, tableType == INDEX ? dataTableName : null, indexes, isImmutableRows, physicalTables, defaultFamilyName, viewStatement, disableWAL, multiTenant, storeNulls, viewType, viewIndexId, indexType, rowKeyOrderOptimizable, transactional, updateCacheFrequency, baseColumnCount, indexDisableTimestamp, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema); {code} We'll also want to make sure there aren't any assumptions about a table having a parent being an index, but instead make sure we're checking the table type as well. [~tdsilva] - do you think you could take this one? was (Author: jamestaylor): This isn't a duplicate of PHOENIX-1499 after all (and thanks for the test, [~cody.mar...@gmail.com]). We currently only load the indexes on the view being used and on the physical table. To fix this, we can navigate the parent view link instead of the physical table link in MetaDataClient.addIndexesFromPhysicalTable(): {code} String physicalName = view.getPhysicalName().getString(); String schemaName = SchemaUtil.getSchemaNameFromFullName(physicalName); String tableName = SchemaUtil.getTableNameFromFullName(physicalName); {code} We're currently capturing the parent of a view in LinkType.PARENT_TABLE here in MetaDataClient.createTableInternal(): {code} // Add row linking from view to its parent table // FIXME: not currently used, but see PHOENIX-1367 // as fixing that will require it's usage. PreparedStatement linkStatement = connection.prepareStatement(CREATE_VIEW_LINK); linkStatement.setString(1, tenantIdStr); linkStatement.setString(2, schemaName); linkStatement.setString(3, tableName); linkStatement.setString(4, parent.getName().getString()); linkStatement.setByte(5, LinkType.PARENT_TABLE.getSerializedValue()); linkStatement.setString(6, parent.getTenantId() == null ? null : parent.getTenantId().getString()); linkStatement.execute(); {code} There's one corner case in that if a view doesn't have a link of type PARENT_TABLE, that means that it's parent is the physical table. We're currently ignoring this link when we build the PTable in MetaDataEndPointImpl.getTable(), but we can capture it here easily: {code} if (colName.getString().isEmpty() && famName != null) { LinkType linkType = LinkType.fromSerializedValue(colKv.getValueArray()[colKv.getValueOffset()]); if (linkType == LinkType.INDEX_TABLE) { addIndexToTable(tenantId, schemaName, famName, tableName, clientTimeStamp, indexes); } else if (linkType == LinkType.PHYSICAL_TABLE) { physicalTables.add(famName); } // TODO else if (link_type == LinkType.PARENT_TABLE) {code} and then pass it through when the PTable is constructed. We only pass a parent table for an INDEX currently, but we can pass it for a VIEW now as well, in which case table.getParent() for a view will return it's parent view. {code} return PTableImpl.makePTable(tenantId, schemaName, tableName, tableType, indexState, timeStamp, tableSeqNum, pkName, saltBucketNum, columns, tableType == INDEX ? schemaName : null, tableType == INDEX ? dataTableName : null, indexes, isImmutableRows, physicalTables, defaultFamilyName, viewStatement, disableWAL, multiTenant, storeNulls, viewType, viewIndexId, indexType, rowKeyOrderOptimizable, transactional, updateCacheFrequency, baseColumnCount, indexDisableTimestamp, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema); {code} We'll also want to make sure there aren't any assumptions about a table having a parent being an index, but instead make sure we're checking the table type as well. [~tdsilva] - do you think you could take this one? > VIEW derived from another VIEW doesn't use parent VIEW indexes > -------------------------------------------------------------- > > Key: PHOENIX-1367 > URL: https://issues.apache.org/jira/browse/PHOENIX-1367 > Project: Phoenix > Issue Type: Sub-task > Reporter: James Taylor > Attachments: PHOENIX_1367.test.patch > > > If a VIEW has an index and another VIEW is derived from it, the child view > will not use the parent view's indexes. -- This message was sent by Atlassian JIRA (v6.3.4#6332)