Interbase SQL 语句不起作用
我正在尝试为 Interbase 编写 SQL 语句。
这个SQL有什么问题吗?
md_master (trm) = 主表 cd_Med (cdt) = 详细信息表
SELECT trm.seq_no, trm.recipient_id, trm.payee_fullname, trm.payee_address1, trm.payee_address2, trm.payee_address3, trm.payee_address_city, trm.payee_address_state, trm.recip_zip, trm.recip_zip_4, trm.recip_zip_4_2, trm.check_no, trm.check_date, trm.check_amount,
cdt.com_ss_source_sys, cdt.cd_pay_date, cdt.com_set_amount,
bnk.name, bnk.address, bnk.transit_routing,
act.acct_no
FROM md_master trm, cd_med cdt, accounts act, banks bnk
join cd_med on cdt.master_id = trm.id
join accounts on act.acct_id = trm.account_tag
join banks on bnk.bank_id = act.bank_id
ORDER BY cdt.master_id
我没有收到错误消息,计算机只是继续运行并挂起。
I am trying to write a SQL Statement for Interbase.
Whats wrong with this SQL?
md_master (trm) = Master Table
cd_Med (cdt) = Detail table
SELECT trm.seq_no, trm.recipient_id, trm.payee_fullname, trm.payee_address1, trm.payee_address2, trm.payee_address3, trm.payee_address_city, trm.payee_address_state, trm.recip_zip, trm.recip_zip_4, trm.recip_zip_4_2, trm.check_no, trm.check_date, trm.check_amount,
cdt.com_ss_source_sys, cdt.cd_pay_date, cdt.com_set_amount,
bnk.name, bnk.address, bnk.transit_routing,
act.acct_no
FROM md_master trm, cd_med cdt, accounts act, banks bnk
join cd_med on cdt.master_id = trm.id
join accounts on act.acct_id = trm.account_tag
join banks on bnk.bank_id = act.bank_id
ORDER BY cdt.master_id
I don't get an error, the computer just keeps crunching away and hangs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我具体不了解 Interbase,但是 FROM 子句似乎有点奇怪(也许只是我不熟悉的一些语法)。这有帮助吗?
顺便说一句,您没有 WHERE 子句,因此如果这些表中的任何一个很大,我不会对它需要很长时间来运行感到过于惊讶。
I don't know about Interbase specifically, but that FROM clause seems a little strange (perhaps just some syntax I'm not familiar with though). Does this help?
By the way, you have no WHERE clause so if any of these tables is large, I wouldn't be overly surprised that it takes a long time to run.
您已经被一种名为
隐式联接语法
的反模式所困扰。将对两个表进行交叉联接,选择输出中的 100 万行。
您正在做:
对 4 个表进行交叉联接(之后与普通联接相结合),这可以轻松生成数十亿行。
难怪 interbase 会挂起;它会一直工作到时间结束,以生成比宇宙中原子还要多的行。
解决方案
切勿在 FROM 子句后使用
,
,这是隐式连接,而且是邪恶的。仅使用显式连接,如下所示:
You have been bitten by an anti-pattern called
implicit join syntax
Will do a cross-join on both tables selecting 1 million rows in the output.
You are doing:
A cross join on 4 tables (combined with normal joins afterwards), which could easily generate many billions of rows.
No wonder interbase hangs; it is working until the end of time to generate more rows then there are atoms in the universe.
The solution
Never use
,
after the FROM clause, that is an implicit join and it is evil.Only use explicit joins, like so:
错误在于 from 子句。您使用的一半是逗号分隔的表,在 where 子句中没有关系,一半是连接。
只需使用连接,一切都应该正常工作
The error lie in the from clause. You are using half with comma separated tables without a relation in where clause and half with joins.
Just use joins and all should work fine