Bug #10590
Indices are not taken from the model temp-table
100%
History
#1 Updated by Eduard Soltan 10 months ago
The following example:
def temp-table tt1 field f1 as char
field f2 as int
field f3 as int
field f4 as logical
index idx f4.
def temp-table tt2 LIKE tt1
field f5 as char
index idx2 f5.
Creates the following dmo Tt2_1, with just the index defined in by tt2 definition and the indices of the model table are completely missed out:
@Table(name = "tt8", legacy = "tt2")
@Indices(
{
@Index(name = "idx2", legacy = "idx2", components =
{
@IndexComponent(name = "f5", legacy = "f5")
})
})
public interface Tt2_1
extends Temporary
#3 Updated by Eduard Soltan 10 months ago
- Subject changed from Indices are not taken from the model tmep-table to Indices are not taken from the model temp-table
#4 Updated by Eduard Soltan 10 months ago
I think I found the problem why the indices from model table are not taken into consideration, this the culprit code in SchemaDictionary.finalizeTableDefine:
Iterator<Aast> iter = indices(table);
if (!iter.hasNext())
{
iter = indices(modelTable);
while (iter.hasNext())
{
Aast next = iter.next();
next.graftCopyTo(table, null);
}
}
As you can see the model indices are taken into consideration only if the main temp-table don't have any indices. My proposed solution is to take indices of the modelTable id it is not null
=== modified file 'src/com/goldencode/p2j/schema/SchemaDictionary.java'
--- old/src/com/goldencode/p2j/schema/SchemaDictionary.java 2025-08-04 17:30:00 +0000
+++ new/src/com/goldencode/p2j/schema/SchemaDictionary.java 2025-09-17 18:30:34 +0000
@@ -1872,12 +1872,12 @@
}
Iterator<Aast> iter = indices(table);
- if (!iter.hasNext())
+ if (modelTable != null)
{
- iter = indices(modelTable);
- while (iter.hasNext())
+ Iterator<Aast> modelIter = indices(modelTable);
+ while (modelIter.hasNext())
{
- Aast next = iter.next();
+ Aast next = modelIter.next();
next.graftCopyTo(table, null);
}
}
Have to check what happens with duplicated name indices in OE.
#5 Updated by Eduard Soltan 10 months ago
- Status changed from New to WIP
Committed on 10590a, rev. 16174.
Now the indices of the model temp-table are added to the main temp-table.
I also handled the errors, when we have duplicated index name in temp-table definition and index name duplication between model and main buffer.
#6 Updated by Eduard Soltan 10 months ago
- Status changed from WIP to Review
- % Done changed from 0 to 100
- reviewer Constantin Asofiei added
#7 Updated by Constantin Asofiei 10 months ago
- Assignee set to Eduard Soltan
#8 Updated by Constantin Asofiei 10 months ago
- % Done changed from 100 to 80
- Status changed from Review to WIP
Eduard, the table AST should already have the INDEX nodes. Keeping the dictionary-wide tableIndexesNames map will lead to more memory consumption, both at runtime (which I think may even leak it) and at conversion time.
Instead, please use the SchemaDictionary.getIndex(NameNode, name) or to calculate if an index exists or not.
#9 Updated by Eduard Soltan 10 months ago
Constantin Asofiei wrote:
Instead, please use the
SchemaDictionary.getIndex(NameNode, name)or to calculate if an index exists or not.
I saw that SchemaDictionary.getIndex(NameNode, name) will return an abbreviation match. For example if I have idx on a table, it will return a match on idx1 table even if I don't have such an index on the table.
#10 Updated by Eduard Soltan 10 months ago
- Status changed from WIP to Review
- % Done changed from 80 to 100
Committed on 10590a, rev. 16176. Created new method that will match exactly the index name in the table name.
#11 Updated by Constantin Asofiei 10 months ago
- Status changed from Review to Internal Test
- Fixed DEF TEMP-TABLE ... LIKE ... USE-INDEX - the index lookup must be case-insensitive.
I'll put this into conversion testing with other changes.
#12 Updated by Constantin Asofiei 10 months ago
Constantin Asofiei wrote:
10590a rev 16178 has a change from 9457c 16205:
- Fixed DEF TEMP-TABLE ... LIKE ... USE-INDEX - the index lookup must be case-insensitive.
I'll put this into conversion testing with other changes.
Right fix is in 16180.
#13 Updated by Constantin Asofiei 10 months ago
In rev 16181, it fixes some issues with the initial approach: In 'like' temp-table definitions, indexes are copied only if the model is a temp-table, the model is a perm table and no explicit indexes in the table defined 'like', or USE-INDEX is not used."
Eduard: please check your standalone tests, conversion testing looks like it passed (there are changes, but they make sense). I'll need to do runtime testing.
#14 Updated by Eduard Soltan 10 months ago
Constantin Asofiei wrote:
Eduard: please check your standalone tests, conversion testing looks like it passed (there are changes, but they make sense). I'll need to do runtime testing.
My standalone tests are working with rev. 16181.
#15 Updated by Eduard Soltan 9 months ago
Committed on 10590a, rev. 16182. Fix for #10615-47.
#16 Updated by Constantin Asofiei 9 months ago
Eduard, see 10590a/16183 - a copy of the index AST is required when copying from the model.
#17 Updated by Constantin Asofiei 9 months ago
- Status changed from Internal Test to Merge Pending
Eduard, please merge after 9906a
#18 Updated by Eduard Soltan 9 months ago
- Status changed from Merge Pending to Test
10590a was merged into trunk and archived.