Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize sharding table index name rewriting rules and remove unnecessary suffix rewriting #31171

Open
strongduanmu opened this issue May 9, 2024 · 0 comments

Comments

@strongduanmu
Copy link
Member

strongduanmu commented May 9, 2024

Feature Request

Is your feature request related to a problem?

No

Describe the feature you would like.

Background

Now, it was found that when the local index of the sharding table was created, the index name was specially rewritten. The rewriting logic is as follows:

actual local index name (user_id_idx_t_order_0) = logical local index name (user_id_idx) + "_" + sharding real table name (t_order_0)

During metadata loading, IndexReviser is used to decorate the loaded raw metadata. The currently implemented classes include:

  • EncryptIndexReviser: decorate the columns involved in the index and convert the actual columns into logical columns;
  • ShardingIndexReviser: Decorate the index name. Only indexes ending with the actual table name will be decorated as logical indexes. Other index ShardingSphere are not managed, which will cause PRIMARY and user-defined indexes to fail to load into the ShardingSphere;
  • SingleIndexReviser: decorate the index name, remove the suffix of the single table name, and use the index name in the DB without the suffix;

In addition to the above problems, there are also some questions about why the index name in the sharding table needs to be rewritten? In MySQL, the index is at the table level, and as long as the same name index is not created in the same table, it can be created successfully.

image

Reference https://stackoverflow.com/questions/27306539/at-what-level-do-postgres-index-names-need-to-be-unique , in PostgreSQL, the index name needs to be unique in the schema, so when sharding tables in PostgreSQL create indexes, the actual table name needs to be used as a suffix to ensure that the index name is unique in the schema.

Solution

  1. IndexToken and IndexTokenGenerator logic adjustment——Considering that only PG and Oracle index name is unique within the schema range, MySQL/SQLServer do not have similar requirements, you can consider adjusting the sharding table index rewriting logic to only PG and Oracle databases support rewriting (if the PG/Oracle database is only sharded, it does not need to be rewritten), and other databases do not need to be rewritten.

  2. IndexToken is currently used as long as the sharding feature, the index will be suffix rewriting, which is unreasonable for single tables and broadcast tables , the need to remove the logic.

  3. IndexReviser logic adjustment——Delete the logic related to SingleIndexReviser, and there is no need to rewrite or decorate the index name for a single table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant