Proc SQL 删除花费的时间太长

发布于 2024-07-27 14:01:03 字数 246 浏览 6 评论 0原文

我正在运行以下 SAS 命令:

Proc SQL;
Delete From Server003.CustomerList;
Quit;

这需要 8 分钟以上...而读取该文件只需要几秒钟。 是什么原因导致删除花费如此长的时间?我可以采取什么措施使其速度更快?

(我无权删除表,所以我只能删除所有行)

谢谢,

编辑:我显然也无法截断表。

I'm running the following SAS command:

Proc SQL;
Delete From Server003.CustomerList;
Quit;

Which is taking over 8 minutes... when it takes only a few seconds to read that file. What could be cause a delete to take so long and what can I do to make it go faster?

(I do not have access to drop the table, so I can only delete all rows)

Thanks,

Dan

Edit: I also apparently cannot Truncate tables.

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

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

发布评论

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

评论(6

伴梦长久 2024-08-03 14:01:03

这不是常规 SQL。 SAS 的 Proc SQL 不支持 Truncate 语句。 理想情况下,您希望了解 delete from 的性能发生了什么; 但如果您真正需要的是截断功能,那么您始终可以只使用纯 SAS,而根本不使用 SQL。

data Server003.CustomerList;
set Server003.CustomerList (obs=0);
run;

这可以像 Truncate 一样有效地执行和操作。 它维护数据集/表结构,但无法用数据填充它(由于 OBS= 选项)。

This is NOT regular SQL. SAS' Proc SQL does not support the Truncate statement. Ideally, you want to figure out what's going on with the performance of the delete from; but if what you really need is truncate functionality, you could always just use pure SAS and not mess with SQL at all.

data Server003.CustomerList;
set Server003.CustomerList (obs=0);
run;

This effectively performs and operates like a Truncate would. It maintains the dataset/table structure but fails to populate it with data (due to the OBS= option).

等风也等你 2024-08-03 14:01:03

尝试将其添加到您的 LIBNAME 语句中:

DIRECT_EXE=DELETE 

根据 适用于关系数据库的 SAS/ACCESS(R) 9.2:参考

使用 DIRECT_EXE= 可以显着提高性能,因为 SQL 删除语句直接传递到 DBMS,而不是 SAS 读取整个结果集并一次删除一行。

Try adding this to your LIBNAME statement:

DIRECT_EXE=DELETE 

According to SAS/ACCESS(R) 9.2 for Relational Databases: Reference,

Performance improves significantly by using DIRECT_EXE=, because the SQL delete statement is passed directly to the DBMS, instead of SAS reading the entire result set and deleting one row at a time.

白况 2024-08-03 14:01:03

是否有很多其他表具有该表的外键? 如果这些表在外键列上没有索引,那么 SQL 可能需要一段时间才能确定删除这些行是否安全,即使其他表实际上在外键中都没有值列)。

Are there a lot of other tables which have foreign keys to this table? If those tables don't have indexes on the foreign key column(s) then it could take awhile for SQL to determine whether or not it's safe to delete the rows, even if none of the other tables actually has a value in the foreign key column(s).

﹎☆浅夏丿初晴 2024-08-03 14:01:03

我还要提到的是,一般来说 SQL 命令在 SAS PROC SQL 中运行速度较慢。 最近,我做了一个项目,并将 TRUNCATE TABLE 语句移动到存储过程中,以避免将它们放在 SAS 中并由 SQL 优化器和周围的执行 shell 处理的惩罚。 最终,这极大地提高了 TRUNCATE TABLE 的性能。

I would also mention that in general SQL commands run slower in SAS PROC SQL. Recently I did a project and moved the TRUNCATE TABLE statements into a Stored Procedure to avoid the penalty of having them inside SAS and being handled by their SQL Optimizer and surrounding execution shell. In the end this increased the performance of the TRUNCATE TABLE substantially.

请爱~陌生人 2024-08-03 14:01:03

它可能会更慢,因为磁盘写入通常比读取慢。

至于在不删除/截断的情况下解决它的方法,好问题! :)

It might be slower because disk writes are typically slower than reads.

As for a way around it without dropping/truncating, good question! :)

独自唱情﹋歌 2024-08-03 14:01:03

您也可以考虑优雅的:

proc sql; 创建表 libname.tablename 像 libname.tablename; 辞职;

我将生成一个与前一个表具有相同名称和相同元数据的新表,并在同一操作中删除旧表。

You also could consider the elegant:

proc sql; create table libname.tablename like libname.tablename; quit;

I will produce a new table with the same name and same meta data of your previous table and delete the old one in the same operation.

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