PHP 的 Oracle PDO 是否挂在 DELETE 上?

发布于 2024-07-14 14:11:16 字数 428 浏览 0 评论 0原文

这在 Php (5.2.6-Win32 + Oracle10g) 中挂起,这是一个错误,还是我做了一些根本错误的事情?

try {
    $conn = new PDO($DB,$USER,$PASSWORD);
    $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    //connected
    try {
        $conn->exec("DELETE FROM MY_TABLE");
        echo "done";
...

注意:我不知道这是否是一个错误,我猜是的。 然而,在快速搜索后我找不到相关的错误报告。 我可能做错了什么,所以我想我应该先在这里问,并为了后代以防其他人遇到类似的问题。

This hangs in Php (5.2.6-Win32 + Oracle10g) is it a bug, or I'm doing something fundamentally wrong?

try {
    $conn = new PDO($DB,$USER,$PASSWORD);
    $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    //connected
    try {
        $conn->exec("DELETE FROM MY_TABLE");
        echo "done";
...

Note: I don't know if this is a bug or not, I'm guessing it is. However as I couldn't find a bug report for this after a quick search. I might be doing something wrong, so I figured I'd ask here first, and for posterity in case someone else has a similar issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

等待圉鍢 2024-07-21 14:11:16

数据库中是否同时进行其他活动? 如果是的话,我怀疑死锁。 某些未提交的 DML 事务可能会锁定 MY_TABLE 的某些行。

如果您不需要回滚功能,请考虑使用 TRUNCATE 而不是 DELETE

Are there other activities going on in the database at the same time? If yes, I'd suspect deadlocks. Some uncommitted DML transaction(s) might be locking some rows of the MY_TABLE.

If you don't need rollback capability, consider using TRUNCATE instead of DELETE.

似最初 2024-07-21 14:11:16

没有 WHERE 的 DELETE 将(很可能)对表进行完整扫描。
这意味着它读取“高水位线”下的每个块 - 即表曾经使用过的每个块。 因此,如果表曾经非常大,那么可能需要很长时间才能删除少量记录。 [因为它不“知道”只有四个记录,直到它读取所有空间。]

截断不会执行此操作。 它只是移动表的高水位线,以便任何正在使用的块很快就会变得未使用。

A DELETE without a WHERE will (most likely) a full scan of the table.
That means it reads every block under the 'high-water mark' - that is every block that has ever been used by the table. So if the table was, at one time, very big, then it can take a very long time to delete just a handful of records. [Because it doesn't 'know' there are only four records until it reads all that space.]

A truncate doesn't do this. It simply moves the high-water mark of the table so that any blocks that were in use quickly become unused.

我偏爱纯白色 2024-07-21 14:11:16

它不太可能挂起,因为 PDO 似乎使用得相当多,但我不知道 Oracle 的使用量有多少。

从 my_table 中删除可能需要一些时间,具体取决于记录的数量。 您等了多长时间才确定它被挂起以及表中有多少条记录?

Pretty unlikely that it's hanging since PDO seems to be in use quite a bit, though how much with Oracle, I don't know.

A delete from my_table may take some time depending on how many records there are. How long did you wait before deciding it was hung and how many records were in the table?

情深缘浅 2024-07-21 14:11:16

如果同一个表上有一个事务正在运行,它可能会阻止您的 DELETE。

If there is a transaction running on the same table, it might block your DELETE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文