我一直在用Apache Ignite做一些實驗。我開發基於以下代碼使用BinaryObject時,我是否需要每個字段的索引?
public static void main(String[] args) throws IgniteException {
Ignite start = Ignition.start("examples/config/example-ignite.xml");
CacheConfiguration<Integer, BinaryObject> cfg = new CacheConfiguration<>();
cfg.setQueryEntities(new ArrayList<QueryEntity>() {{
QueryEntity e = new QueryEntity();
e.setKeyType("java.lang.Integer");
e.setValueType("BinaryTest");
e.setFields(new LinkedHashMap<String, String>(){{
put("name", "java.lang.String");
}});
add(e);
}});
IgniteCache<Integer, BinaryObject> cache = start.getOrCreateCache(cfg).withKeepBinary();
BinaryObjectBuilder builder = start.binary().builder("BinaryTest");
builder.setField("name", "Test");
cache.put(1, builder.build());
QueryCursor<List<?>> query = cache.query(new SqlFieldsQuery("select name from BinaryTest"));
System.out.println(query.getAll());
不過我不想對各個領域的指數柔軟物體(我懷疑這是昂貴的)。我意識到,沒有索引,這可能會導致較慢的查詢 - 我很好。
使用上面的示例代碼,我不能首先創建該字段的索引形成一個SQL查詢。
是否可以在沒有索引的BinaryObjects上使用SQL查詢? (注意:我只會在每個緩存中存儲一個'類型'的二進制對象)。
感謝 豐富
感謝您的回答的Valentin。是否可以通過使用Map而不是BinaryObject來實現相同的效果?或者其他一些可以參與SQL查詢的類型(但不一定對所有字段都有索引)。 – Rich
您將無法訪問SQL查詢中的地圖元素。 –
我想我們(或者至少我)可能會把我們的電線穿過。使用BinaryObject我需要通過QueryEntity定義字段列表 - 我很酷。但是索引只會爲使用QueryIndex指定的字段創建。因此,對沒有QueryIndex條目的字段的查詢仍然會*工作*,但由於沒有索引存在,所以查詢速度會更慢(全表掃描)。它是否正確? – Rich