[英]Where is this SQL statement bottlenecking?
I am trying to write a SQL (Sybase) query to fetch movie theatre information out of a database. 我正在尝试编写SQL(Sybase)查询以从数据库中获取电影院信息。 When I run the query below, the query just keeps running.
当我在下面运行查询时,查询一直在运行。 Eventually, after 5 minutes or so, I just abort it.
最终,大约5分钟后,我就中止了。 There's no bad/illegal SQL, it's just slow !
没有坏/非法的SQL,只是速度很慢 !
SELECT
TM.type_prefix +
right('00000000' + convert(varchar, TM.showing_id), 8) +
right('0000' + convert(varchar, TM.theatre_id), 4) as data_id
FROM
theatre_times..theatre_mappings TM,
theatres..region_codes RC,
title_summaries..movie_summary MS
WHERE
TM.scheme_id = 512 AND
RC.region_code_id = MS.region_code_id
Don't worry about the table names or logic used in the query, I'm just wondering if there's anything obvious that I'm doing wrong or inefficiently. 不用担心查询中使用的表名或逻辑,我只是想知道是否有明显的错误或效率低下。 Here are the counts for all three tables:
这是所有三个表的计数:
theatre_mappings
= 2,094,163 theatre_mappings
= 2,094,163 region_codes
= 11,140,348 region_codes
= 11,140,348 movie_summary
= 6,437,782 movie_summary
= 6,437,782 Thanks in advance! 提前致谢!
You're creating a cartesian product of TM entries to (RC/MS) entries. 您正在创建从TM条目到(RC / MS)条目的笛卡尔乘积。 Do you want to be?
你想成为?
I think Sybase supports ANSI 92 SQL syntax, so your SQL is equivalent to 我认为Sybase支持ANSI 92 SQL语法,因此您的SQL等效于
FROM
theatre_times..theatre_mappings TM,
theatres..region_codes RC
inner join title_summaries..movie_summary MS
on RC.region_code_id = MS.region_code_id
WHERE
TM.scheme_id = 512
Its producing a Cartesian because you're not joining the theatre_mappings
table to the other two.. Without seeing your schema, I can't say for sure, but I suspect you need something like: 因为您没有将
theatre_mappings
表连接到其他两个表,所以产生笛卡尔坐标。.如果没有看到您的架构,我不能肯定地说,但是我怀疑您需要这样的东西:
SELECT
TM.type_prefix +
right('00000000' + convert(varchar, TM.showing_id), 8) +
right('0000' + convert(varchar, TM.theatre_id), 4) as data_id
FROM
theatre_times..theatre_mappings TM,
theatres..region_codes RC,
title_summaries..movie_summary MS
WHERE
TM.scheme_id = 512 AND
TM.region_code_id = RC.region_code_id -- Extra join
RC.region_code_id = MS.region_code_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.