简体   繁体   English

临时表比变量表大查询更快

[英]temp tables faster than variable tables big query

I have always been using With tabes when working with long queries but I recently tried the create temp table and the execution was so much faster.在处理长查询时,我一直使用 With tabes,但我最近尝试了创建临时表,执行速度要快得多。 The one with With tables (variable names) got an error as too heavy after 12 minutes and the one with create or replace temp table finished in less than 2 minutes.带有表(变量名)的那个在 12 分钟后出现错误太重,而带有创建或替换临时表的那个在不到 2 分钟内完成。 Why is that the case?为什么会这样?

Temporary tables give flexibility to make customized tables for data visualization, as per the analytics requirements. 临时表可以根据分析要求灵活地制作用于数据可视化的定制表。 More so, the use-case of TEMP is in the local temporary tables, only visible to the current session.更重要的是,TEMP 的用例在本地临时表中,仅对当前 session 可见。

Meanwhile, the WITH clause acts as a temporary table, but it is actually a result of a subquery which can be used somewhere else.同时, WITH子句充当临时表,但它实际上是可以在其他地方使用的子查询的结果。

The time difference that you get is because temporary tables use cache query results .您得到的时间差是因为临时表使用缓存查询结果 This means that the query values are stored in the cache memory. That's why it is faster to execute than the queries with the WITH clause.这意味着查询值存储在缓存 memory 中。这就是为什么它比WITH子句的查询执行得更快的原因。 Sometimes, when you run a duplicate query, BigQuery attempts to reuse cached results.有时,当您运行重复查询时,BigQuery 会尝试重用缓存的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM