apache / shardingsphere

Empowering Data Intelligence with Distributed SQL for Sharding, Scalability, and Security Across All Databases.
Apache License 2.0
20.02k stars 6.77k forks source link

Consider adding ConstraintMetaData to metadata to support constraint segment merge logic #16086

Open strongduanmu opened 2 years ago

strongduanmu commented 2 years ago

Feature Request

To support handling of foreign key constraints in issue #16050, ConstraintMetaData needs to be added to the metadata.

Add Map<String, Constraint MetaData> constraints to TableMetaData:

/**
 * Table meta data.
 */
@Getter
@EqualsAndHashCode
@ToString
public final class TableMetaData {

    private final String name;

    private final Map<String, ColumnMetaData> columns;

    private final Map<String, IndexMetaData> indexes;

    private final Map<String, ConstraintMetaData> constrains;

    private final List<String> primaryKeyColumns = new ArrayList<>();
}

/**
 * Constraint meta data.
 */
@RequiredArgsConstructor
@Getter
@EqualsAndHashCode
@ToString
public final class ConstraintMetaData {

    private final String name;

    private final String referencedTableName;
}

Then add query logic for constraints in MySQLTableMetaDataLoader.

SELECT CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME FROM information_schema.KEY_COLUMN_USAGE
       WHERE TABLE_NAME IN ('bmsql_district_0') AND REFERENCED_TABLE_SCHEMA IS NOT NULL;

Is your feature request related to a problem?

issue #16050

Describe the feature you would like.

TeslaCN commented 2 years ago

Hi @strongduanmu Any update here? Could we finish this in 5.1.1?

strongduanmu commented 2 years ago

@TeslaCN Can not finish in 5.1.1, I will change the milestone.

lhyundeadsoul commented 2 years ago

@strongduanmu For this issue, do you mean we should continue to implement constraint segment merge logic in SQLServer/Oracle/openGauss/Postgresql metadataloader like mysql?

strongduanmu commented 2 years ago

@lhyundeadsoul Yes, are you interested in completing it?

github-actions[bot] commented 2 years ago

Hello , this issue has not received a reply for several days. This issue is supposed to be closed.

github-actions[bot] commented 8 months ago

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

TherChenYang commented 5 months ago

I will handle the Oracle-related part.