# 10-15 seconds of pre-compile

**URL:** <https://www.singlestore.com/forum/t/10-15-seconds-of-pre-compile/1237>\
**Category:** Help\
**Created:** [September 15, 2019, 8:54am UTC](https://www.singlestore.com/forum/t/10-15-seconds-of-pre-compile/1237 "2019-09-15T08:54:45Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![zhou](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/z/3e96dc/32.png) [@zhou](https://www.singlestore.com/forum/u/zhou)\
**Post date:** [October 9, 2019, 4:22am UTC](https://www.singlestore.com/forum/t/10-15-seconds-of-pre-compile/1237/21 "2019-10-09T04:22:10Z")

</div>

Btw, can you try to run the query in interpret mode? Option (interpreter\_mode=interpret).  
It would be helpful to see how long that takes.

---

<div class="post-metadata">

**Author:** ![dtroyan](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/d/c5a1d2/32.png) [@dtroyan](https://www.singlestore.com/forum/u/dtroyan)\
**Post date:** [October 9, 2019, 7:28am UTC](https://www.singlestore.com/forum/t/10-15-seconds-of-pre-compile/1237/22 "2019-10-09T07:28:50Z")

</div>

> [@zhou](#):
>
> Btw, can you try to run the query in interpret mode? Option (interpreter\_mode=interpret).  
> It would be helpful to see how long that takes.

Dear @zhou, I’ve already done it here [10-15 seconds of pre-compile - #11 by dtroyan - Help - SingleStore Forums](https://www.memsql.com/forum/t/10-15-seconds-of-pre-compile/1237/11?u=dtroyan)

---

<div class="post-metadata">

**Author:** ![dtroyan](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/d/c5a1d2/32.png) [@dtroyan](https://www.singlestore.com/forum/u/dtroyan)\
**Post date:** [October 9, 2019, 7:34am UTC](https://www.singlestore.com/forum/t/10-15-seconds-of-pre-compile/1237/23 "2019-10-09T07:34:17Z")

</div>

> [@zhou](#):
>
> @dtroyan Sorry for the late response.  
> I examined the query. Unfortunately, interpFirst is not helping too much in this case. Because this query is generating one single plan the leaves so we won’t get the usual benefit of parallel compilation. In addition since all tables are rowstore, the interpreter will be a lot less efficient so we won’t do meaningful work until compilation finishes.  
> as a result, interpFirst won’t perform better than compile and run.
> 
> (for particular case, it might perform better if the tables are not sharded the same way).
> 
> Thanks again for the meaningful feedback. We will improve this case in later version of memSQL.

Dear @zhou, could you please explain in more details, why exactly is this query taking the whole 3 seconds to execute on the first time, and ~150ms on all consecutive runs?

It’s taking even more than compile times on all leaves combined (600ms+600ms) + the actual execution time (150ms).

The MemSQL becomes very hard to sell to my internal customers with this behaviour, as the live dashboards update for more than 5 seconds sometimes on every filter change, as each time a filter changes the SQL query changes =\> new compilation cycle =\> 3-5 sec (sometimes over 7 secs!) execution.

---

<div class="post-metadata">

**Author:** ![zhou](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/z/3e96dc/32.png) [@zhou](https://www.singlestore.com/forum/u/zhou)\
**Post date:** [October 9, 2019, 2:23pm UTC](https://www.singlestore.com/forum/t/10-15-seconds-of-pre-compile/1237/24 "2019-10-09T14:23:45Z")

</div>

I will try to repro the issue myself.  
Meanwhile, could you run this query? This will skip optimizer.

> SELECT STRAIGHT\_JOIN STR\_TO\_DATE( DATE\_FORMAT(servicedesk.RegisteredOn,’%Y-%m-%d %H’),’%Y-%m-%d %H’) AS RegisteredOn, COUNT() AS count, STR\_TO\_DATE( DATE\_FORMAT(servicedesk.RegisteredOn,’%Y-%m-%d %H’),’%Y-%m-%d %H’) AS op, DATE\_FORMAT(servicedesk.RegisteredOn,’%Y-%m-%d %H’) AS op\_2 FROM ((((test.servicedesk as servicedesk LEFT JOIN ( SELECT WITH(NO\_MERGE\_THIS\_SELECT=1) serviceitem\_\_via\_\_ServiceItemI\_0.id AS id FROM test.serviceitem as serviceitem\_\_via\_\_ServiceItemI\_0 ) AS serviceitem\_\_via\_\_ServiceItemI ON (servicedesk.ServiceItemId = serviceitem\_\_via\_\_ServiceItemI.id)) LEFT JOIN ( SELECT WITH(NO\_MERGE\_THIS\_SELECT=1) casestatus\_\_via\_\_StatusId\_0.id AS id FROM test.casestatus as casestatus\_\_via\_\_StatusId\_0 ) AS casestatus\_\_via\_\_StatusId ON (servicedesk.StatusId = casestatus\_\_via\_\_StatusId.id)) LEFT JOIN ( SELECT WITH(NO\_MERGE\_THIS\_SELECT=1) sysadminunit\_0.id AS id, sysadminunit\_0.name AS name FROM test.sysadminunit as sysadminunit\_0 ) AS sysadminunit ON (sysadminunit.id = servicedesk.GroupId)) LEFT JOIN ( SELECT WITH(NO\_MERGE\_THIS\_SELECT=1) sysadminunit\_prev\_0.id AS id, sysadminunit\_prev\_0.name AS name FROM test.sysadminunit as sysadminunit\_prev\_0 ) AS sysadminunit\_prev ON (sysadminunit\_prev.id = servicedesk.GroupId\_prev)) WHERE ((servicedesk.ins\_upd\_ts \> (‘2019-01-01’!:\>datetime(6) NULL)) AND ( IFNULL(sysadminunit.name,’’) \<\> ‘’) AND (servicedesk.GroupModifiedOn \> (‘2019-01-01’!:\>datetime(6) NULL)) AND ISNULL(sysadminunit\_prev.name) AND (NOT ISNULL(servicedesk.Number))) GROUP BY 3 ORDER BY 3 asc OPTION(NO\_QUERY\_REWRITE=1, INTERPRETER\_MODE=INTERPRET\_FIRST)

---

<div class="post-metadata">

**Author:** ![dtroyan](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/d/c5a1d2/32.png) [@dtroyan](https://www.singlestore.com/forum/u/dtroyan)\
**Post date:** [October 9, 2019, 3:14pm UTC](https://www.singlestore.com/forum/t/10-15-seconds-of-pre-compile/1237/25 "2019-10-09T15:14:14Z")

</div>

Thank you for the reply,

I have run your Query several times consecutively (“Query 2” on the screenshot),  
and then the Query from the [post #11](https://www.memsql.com/forum/t/10-15-seconds-of-pre-compile/1237/11) (“Query 1” on the screenshot) a couple of times as well - just to give you the reference.

 ![image](https://forum-prod-assets20231213123829991800000001.s3.dualstack.us-east-1.amazonaws.com/original/1X/ca1e729f4f64e5622a7552b460b511e1146628c8.png)

---

<div class="post-metadata">

**Author:** ![zhou](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/z/3e96dc/32.png) [@zhou](https://www.singlestore.com/forum/u/zhou)\
**Post date:** [October 10, 2019, 12:02am UTC](https://www.singlestore.com/forum/t/10-15-seconds-of-pre-compile/1237/26 "2019-10-10T00:02:42Z")

</div>

It is not a good thing to do in general, but for these particular kind of query, you might try to run it with  
Select Straight\_join … Option(No\_Query\_rewrite=1);

---

<div class="post-metadata">

**Author:** ![dtroyan](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/d/c5a1d2/32.png) [@dtroyan](https://www.singlestore.com/forum/u/dtroyan)\
**Post date:** [October 10, 2019, 7:16am UTC](https://www.singlestore.com/forum/t/10-15-seconds-of-pre-compile/1237/27 "2019-10-10T07:16:31Z")

</div>

@zhou, it actually does help somehow: first query run time has decreased to ~1.2secs with these hacks.

However, apparently these options do not work when used in a view DDL. I would not want to force all customers add these options in their queries, moreover - all BI tools just cannot be taught to use use them.

Am I right to understand that this behavior will be present in MemSQL for a while? It would be helpful to know if there is any kind of timeline to fix the issue?

---

<div class="post-metadata">

**Author:** ![nikita](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/n/a8b319/32.png) [@nikita](https://www.singlestore.com/forum/u/nikita)\
**Post date:** [October 10, 2019, 5:43pm UTC](https://www.singlestore.com/forum/t/10-15-seconds-of-pre-compile/1237/28 "2019-10-10T17:43:03Z")

</div>

@dtroyan. i assume you are from PA Networks. At this point, please file a support ticket. We provide “best effort” support to our community users but take customer support very seriously. Filing a support ticket will put the investigation on a faster track. We will update the community once we solve this.

---

<div class="post-metadata">

**Author:** ![dtroyan](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/d/c5a1d2/32.png) [@dtroyan](https://www.singlestore.com/forum/u/dtroyan)\
**Post date:** [October 11, 2019, 7:09am UTC](https://www.singlestore.com/forum/t/10-15-seconds-of-pre-compile/1237/29 "2019-10-11T07:09:16Z")

</div>

Dear @nikita,  
Could you clarify what is “PA Networks”? If that is supposed to be a company - I do not work there, nor do I know about its existence.

I cannot file a support ticket, as we do not have a paid subscription with MemSQL. This is the last issue with MemSQL that, from my perspective, should be settled before suggesting MemSQL to be our real-time analytics platform of choice in the future.

5-10 seconds for the initial query run time is unfortunately not acceptable:(

---

<div class="post-metadata">

**Author:** ![nikita](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/n/a8b319/32.png) [@nikita](https://www.singlestore.com/forum/u/nikita)\
**Post date:** [October 12, 2019, 1:09am UTC](https://www.singlestore.com/forum/t/10-15-seconds-of-pre-compile/1237/30 "2019-10-12T01:09:36Z")

</div>

@dtroyan. I’m sorry I wrongly assumed u r on the same team with Ziv. We will keep digging and get to the bottom of it. Would you be able to give us access to the cluster? Over Webex or zoom?

[Previous page](https://www.singlestore.com/forum/t/10-15-seconds-of-pre-compile/1237.md?page=1)
