英文:
Can SQL scripts with shared CTE names be run in parallel?
问题
你有两个 SQL 脚本,它们都包含公共表达式(CTE)。这两个脚本中的CTE都使用了相同的名称。例如:
脚本1:
with c1 as (
select * from t1
),
c2 as (
select * from t2
)
脚本2:
with c1 as (
select * from t3
)
我的问题是,考虑到这两个脚本都有一个名为 c1
的CTE,我可以并行运行这两个脚本吗?
谢谢
我尝试过并行运行这些脚本,但出现了奇怪的错误,所以我想确保不是两个脚本中共享的CTE名称导致了问题。
英文:
I have two sql scripts, and they both have CTEs. The CTEs have the same name in the two scripts. For example:
Script1:
with c1 as (
select * from t1
),
c2 as (
select * from t2
)
Script2:
with c1 as (
select * from t3
)
My question is, given the fact that both scripts have a CTE named c1
, can I run the scripts in parallel?
Thank you
I have tried running the scripts in parallel, but I'm getting weird errors, so I wanna make sure it's not the share CTE names across the two scripts that's causing the problem.
答案1
得分: 1
是的,您可以并行运行这些脚本。CTE将独立执行,因此不存在数据损坏或竞争条件的风险。但您应考虑为CTE使用不同的名称,以提高代码的可读性。
Script1:
使用c1_t1作为名称,选择t1中的所有内容。
使用c2_t2作为名称,选择t2中的所有内容。
Script2:
使用c1_t3作为名称,选择t3中的所有内容。
英文:
Yes, you can run the scripts in parallel. The CTEs will be executed independently, so there is no risk of data corruption or race conditions. Though you should consider using different names for the CTEs to make your code more readable.
Script1:
with c1_t1 as (
select * from t1
),
c2_t2 as (
select * from t2
)
Script2:
with c1_t3 as (
select * from t3
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论