joooger commented on a change in pull request #5676: IGNITE-10654 Print warn
message in case of index creating with already existing fields.
URL: https://github.com/apache/ignite/pull/5676#discussion_r267233949
##########
File path:
modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
##########
@@ -822,6 +841,70 @@ public boolean rebuildFromHashInProgress() {
return commitUserIndex(ses, idxName);
}
+ /**
+ * Checks and replace if provided column id matches value alias column.
+ *
+ * @param col Input column.
+ * @return Transformed result if needed.
+ */
+ private String aliasNameTransformer(IndexColumn col) {
+ if (desc.isKeyAliasColumn(col.column.getColumnId()))
+ return QueryUtils.KEY_FIELD_NAME;
+ else if (desc.isValueAliasColumn(col.column.getColumnId()))
+ return QueryUtils.VAL_FIELD_NAME;
+
+ return col.columnName;
+ }
+
+ /**
+ * Check index presence, throw exception if index with same name already
exist or return {@code True} if
+ * index with same fields and search direction found.
+ *
+ * @param curIdx Index to check.
+ * @return {@code True} if equal index exist.
+ * @throws IgniteCheckedException If failed.
+ */
+ private @Nullable Index checkIndexPresence(Index curIdx) throws
IgniteCheckedException {
+ IndexColumn[] curColumns = curIdx.getIndexColumns();
+
+ Index registredIdx = null;
+
+ for (Index idx : idxs) {
+ if (!(idx instanceof H2TreeIndex))
+ continue;
+
+ if (F.eq(curIdx.getName(), idx.getName()))
+ throw new IgniteCheckedException("Index already exists: " +
idx.getName());
+
+ IndexColumn[] idxColumns = idx.getIndexColumns();
+
+ if (idxColumns.length == curColumns.length) {
+ boolean copy = true;
+
+ for (IndexColumn idxCol : idxColumns) {
+ registredIdx = null;
+
+ for (IndexColumn curCol : curColumns) {
+ if (F.eq(aliasNameTransformer(idxCol),
aliasNameTransformer(curCol))
Review comment:
As I understood we can say that index already present only in case when new
index has columns which is subset of old index with the same order of columns
and start from beggining of index....
For Example:
IDX_OLD(id, name, age) - already exist index
IDX_NEW1(id, name) - try to create new index - it is subset of IDX_OLD, we
shouldn't create such index
IDX_NEW2(name, age) - try to create new index - it is subset of IDX_OLD, but
not start from beggining, so we need to create such index.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services