Created
November 13, 2024 17:03
-
-
Save ptupitsyn/882b9b9e5e13c82fcf96f83fd53b2777 to your computer and use it in GitHub Desktop.
Ignite.NET SQL index test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net9.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Apache.Ignite" Version="2.16.0" /> | |
<PackageReference Include="Apache.Ignite.Linq" Version="2.16.0" /> | |
</ItemGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> SQL: | |
select _T0._KEY, _T0._VAL from "c".TESTMODEL as _T0 where (_T0.COUNTRYCODE IS NOT DISTINCT FROM ?) | |
>> EXPLANATION: | |
SELECT | |
_T0__Z0._KEY AS __C0_0, | |
_T0__Z0._VAL AS __C0_1 | |
FROM "c".TESTMODEL _T0__Z0 | |
/* "c".TESTMODEL_COUNTRYCODE_ASC_IDX: COUNTRYCODE IS ?1 */ | |
WHERE _T0__Z0.COUNTRYCODE IS ?1 | |
SELECT | |
__C0_0 AS _KEY, | |
__C0_1 AS _VAL | |
FROM PUBLIC.__T0 | |
/* "c"."merge_scan" */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Apache.Ignite.Core; | |
using Apache.Ignite.Core.Cache.Configuration; | |
using Apache.Ignite.Core.Cache.Query; | |
using Apache.Ignite.Linq; | |
using var ignite = Ignition.Start(); | |
var cacheCfg = new CacheConfiguration("c", new QueryEntity(typeof(TestModel))); | |
var cache = ignite.GetOrCreateCache<int, TestModel>(cacheCfg); | |
cache.Put(1, new TestModel(1, "US")); | |
cache.Put(2, new TestModel(2, "UK")); | |
var parameter = "US"; | |
var query = cache.AsCacheQueryable() | |
.Where(x => x.Value.CountryCode == parameter); | |
var queryRes = query.ToList(); | |
foreach (var item in queryRes) | |
{ | |
Console.WriteLine(item.Value.CountryCode); | |
} | |
Console.WriteLine("\n>> SQL: "); | |
var sql = query.ToCacheQueryable().GetFieldsQuery().Sql; | |
Console.WriteLine(sql); | |
Console.WriteLine("\n>> EXPLANATION: "); | |
var explain = cache.Query(new SqlFieldsQuery("EXPLAIN " + sql, parameter)).GetAll(); | |
foreach (var list in explain) | |
{ | |
Console.WriteLine(string.Join(", ", list)); | |
} | |
Console.WriteLine(explain); | |
public record TestModel( | |
[property: QuerySqlField] int Id, | |
[property: QuerySqlField(IsIndexed = true)] string CountryCode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment