# TIP: don't use custom queries in calculations.

**URL:** <https://forum.servoy.com/t/tip-dont-use-custom-queries-in-calculations/17108>\
**Category:** Classic Servoy\
**Created:** [March 11, 2013, 4:29pm UTC](https://forum.servoy.com/t/tip-dont-use-custom-queries-in-calculations/17108 "2013-03-11T16:29:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [March 11, 2013, 4:29pm UTC](https://forum.servoy.com/t/tip-dont-use-custom-queries-in-calculations/17108/1 "2013-03-11T16:29:16Z")

</div>

First those are very bad for performance, because when ever that calc is triggered that query is done, this would really hurt if you would be a in tableview where 1 column is that calculation.

Besides that, now in a few releases of servoy we have a real calculation dependency tracking. This works this way that we know what the calculation did touch to be able to get to its value.  
Then if any of those values change the calc is flagged to be recalculated.

Now if you do this in a calculation:

databaseManager.getDatasetByQuery(“select nicething from anothertable where x = ?”,[dataprovider\_of\_same\_record]);

so you go to a different table where you select something based on something of this record.

Then don’t expect the calculation to be recalculated if something of that anothertable changes, if that “dataprovider\_of\_same\_record” would be the pk column. then this calculation would never be recalculated as long its in memory for that client  
Because the pk would never change.

Always use relations for this so the above code should be:

relation\_to\_anothertable.nicething

now we know you touched that relation and that nicething from that other table, so if now anything in between (primary dataproviders or related dataproviders) that changes we will flag the calculation and it will be recalculated.

The big side effect is also that we do cache that relation so when that is reused it could be that there are also no queries being done to the server.

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [March 11, 2013, 11:00pm UTC](https://forum.servoy.com/t/tip-dont-use-custom-queries-in-calculations/17108/2 "2013-03-11T23:00:05Z")

</div>

I like Johan’s ‘tip-mode’ ![:D]( "Very Happy")

---

<div class="post-metadata">

**Author:** ![david](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@david](https://forum.servoy.com/u/david)\
**Post date:** [March 12, 2013, 12:10am UTC](https://forum.servoy.com/t/tip-dont-use-custom-queries-in-calculations/17108/3 "2013-03-12T00:10:47Z")

</div>

> mboegem:  
> I like Johan’s ‘tip-mode’ ![:D]( "Very Happy")

For sure!

---

<div class="post-metadata">

**Author:** ![chaitanyas](https://avatars.discourse-cdn.com/v4/letter/c/b9bd4f/32.png) [@chaitanyas](https://forum.servoy.com/u/chaitanyas)\
**Post date:** [March 12, 2013, 5:35am UTC](https://forum.servoy.com/t/tip-dont-use-custom-queries-in-calculations/17108/4 "2013-03-12T05:35:49Z")

</div>

Nice tip will get used to it. ![:)]( "Smile")

Thanks  
Chaitanya s

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [March 12, 2013, 11:18am UTC](https://forum.servoy.com/t/tip-dont-use-custom-queries-in-calculations/17108/5 "2013-03-12T11:18:38Z")

</div>

we want more!! ![:D]( "Very Happy")

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [March 12, 2013, 11:40am UTC](https://forum.servoy.com/t/tip-dont-use-custom-queries-in-calculations/17108/6 "2013-03-12T11:40:57Z")

</div>

would love some tips about how to best use entity scopes…

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [March 12, 2013, 1:16pm UTC](https://forum.servoy.com/t/tip-dont-use-custom-queries-in-calculations/17108/7 "2013-03-12T13:16:11Z")

</div>

> swingman:  
> would love some tips about how to best use entity scopes…

This? [https://www.servoy.com/forum/viewtopic.php?f=22&t=19420](https://www.servoy.com/forum/viewtopic.php?f=22&t=19420)

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [March 12, 2013, 1:53pm UTC](https://forum.servoy.com/t/tip-dont-use-custom-queries-in-calculations/17108/8 "2013-03-12T13:53:32Z")

</div>

no those are not entity scopes but normal named global scopes (so the same as globals.js but then named under a different name and there can be only 1 name throughout the complete solutions and its modules)

entity scopes are the foundset scopes to give a foundset extra functionality  
Those just should be used if you have business rules that is based on that table/data, really belong to that datasource, so its just a narrower scope then what a named global scope would be.

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [March 12, 2013, 2:58pm UTC](https://forum.servoy.com/t/tip-dont-use-custom-queries-in-calculations/17108/9 "2013-03-12T14:58:09Z")

</div>

Very nice these Tips !

Hans

---

<div class="post-metadata">

**Author:** ![jcarlos](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@jcarlos](https://forum.servoy.com/u/jcarlos)\
**Post date:** [March 13, 2013, 6:10am UTC](https://forum.servoy.com/t/tip-dont-use-custom-queries-in-calculations/17108/10 "2013-03-13T06:10:06Z")

</div>

Thank you! ![:-)]( "Smile")

---

<div class="post-metadata">

**Author:** ![jcarlos](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@jcarlos](https://forum.servoy.com/u/jcarlos)\
**Post date:** [March 13, 2013, 6:11am UTC](https://forum.servoy.com/t/tip-dont-use-custom-queries-in-calculations/17108/11 "2013-03-13T06:11:31Z")

</div>

> mboegem:  
> I like Johan’s ‘tip-mode’ ![:D]( "Very Happy")

- 1 … You are funny lol
