# ICV with reasoning - query plan reuse

**URL:** <https://community.stardog.com/t/icv-with-reasoning-query-plan-reuse/786>\
**Category:** Support\
**Created:** [January 29, 2018, 3:24pm UTC](https://community.stardog.com/t/icv-with-reasoning-query-plan-reuse/786 "2018-01-29T15:24:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hmottestad](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/hmottestad/32/19_2.png) [@hmottestad](https://community.stardog.com/u/hmottestad)\
**Post date:** [January 29, 2018, 3:24pm UTC](https://community.stardog.com/t/icv-with-reasoning-query-plan-reuse/786/1 "2018-01-29T15:24:12Z")

</div>

Hi,

I’m profiling our use of ICV, because it is adding a large overhead to our data processing (3x) and after some digging I see that the biggest difference between using ICV with reasoning vs. without it how much time is used on the query plan.

With reasoing: com.complexible.stardog.plan.eval.QueryEngine.getExecutablePlan(Query) 47%  
Without reasoing: com.complexible.stardog.plan.eval.QueryEngine.getExecutablePlan(Query) 16%

Seems to be caused by createOptimized which uses 41.9 % of the time for icv with reasoning, vs 5.7% without reasoning.

| Stack Trace | Sample Count | Percentage(%) |
| --- | --- | --- |
| WITH REASONING com.complexible.stardog.plan.eval.ExecutablePlanFactory.createOptimized(ExecutionContext, Plan) | 1,044 | 41.961 |
| WITHOUT REASONING com.complexible.stardog.plan.eval.ExecutablePlanFactory.createOptimized(ExecutionContext, Plan) | 113 | 5.762 |

Anything I can do here?

Cheers,  
Håvard

PS: I can send the java flight recorder files if that helps.

---

<div class="post-metadata">

**Author:** ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)\
**Post date:** [January 30, 2018, 11:30am UTC](https://community.stardog.com/t/icv-with-reasoning-query-plan-reuse/786/2 "2018-01-30T11:30:08Z")

</div>

Hi Håvard,

This is the step on which reasoning (query rewriting) happens. Stardog tries to reuse query plans even when reasoning is enabled but it’s not always possible. One obvious example is when schema changes. But there could be more subtle situations, for example, when some predicates (classes or properties) which used to be empty (i.e. there were no data assertions for them in the database) become non-empty, or vice versa. That means some optimizations which were applied when the plan was previously generated can no longer be applied, and the query should be rewritten again.

It’s also possible that plans aren’t reused for a wrong reason. Any chance you can create the smallest update sequence (2 transactions wrt the same constraints) which don’t update the schema but `createOptimized` takes same time for both updates? We can then take a look at the obfuscated data.

Thanks,  
Pavel

---

<div class="post-metadata">

**Author:** ![hmottestad](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/hmottestad/32/19_2.png) [@hmottestad](https://community.stardog.com/u/hmottestad)\
**Post date:** [January 30, 2018, 12:20pm UTC](https://community.stardog.com/t/icv-with-reasoning-query-plan-reuse/786/3 "2018-01-30T12:20:32Z")

</div>

I’ll do that Pavel.

Cheers,  
Håvard

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [February 13, 2018, 12:20pm UTC](https://community.stardog.com/t/icv-with-reasoning-query-plan-reuse/786/4 "2018-02-13T12:20:55Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
