biandeqiang
biandeqiang

Reputation: 51

How Do I Create a Complex Index?

I have an SQL as follows:

SELECT * FROM AlarmRecord WHERE (originSystemName =?) and nativeMeDn in (?) ORDER BY LATESTOCCURUTC DESC LIMIT 20

How to create a combined index of the three fields (originSystemName, nativeMeDn, and LATESTOCCURUTC)?

@QuerySqlField(orderedGroups = {@QuerySqlField.Group(name = "group_idx", order = 1)})
private String nativeMeDn;

@QuerySqlField(orderedGroups = {@QuerySqlField.Group(name = "group_idx", order = 2)})
private String originSystemName;

@QuerySqlField(orderedGroups = {@QuerySqlField.Group(name = "group_idx", descending = true, order = 3)})
private long latestOccurUtc;

I thought it was right, but it doesn't seem to be.

Please take a look. Thank you.

Upvotes: 0

Views: 83

Answers (1)

Igor Belyakov
Igor Belyakov

Reputation: 885

You should set index = true for all the fields, as well as the order value, should be started from 0 instead of 1:

@QuerySqlField(index = true, orderedGroups = {@QuerySqlField.Group(name = "group_idx", order = 0)})
private String nativeMeDn;

@QuerySqlField(index = true, orderedGroups = {@QuerySqlField.Group(name = "group_idx", order = 1)})
private String originSystemName;

@QuerySqlField(index = true, orderedGroups = {@QuerySqlField.Group(name = "group_idx", descending = true, order = 2)})
private long latestOccurUtc;

You can find an example here.

Upvotes: 1

Related Questions