直接从数据库获取发布和过期日期 - 请确认查询是否正确

发布于 2024-12-10 03:14:14 字数 339 浏览 1 评论 0原文

我的网站有点大,使用 Umbraco API 循环遍历所有节点来获取发布和过期日期已经超时..所以我编写了以下查询来查找节点的过期和发布日期..

SELECT D.nodeId, D.releaseDate, D.expireDate
FROM dbo.cmsDocument D  
WHERE D.newest = 1 AND  
(
    D.releaseDate IS NOT NULL  
    OR
    D.expireDate IS NOT NULL 
)

任何人都可以确认它是否对还是错...如果是错的,获取这些值的正确方法是什么..

谢谢
安兹

My website is a bit huge and looping through all the nodes using Umbraco APIs to get release and expire dates is timing out.. so I wrote the following query to find the expire and release dates of nodes..

SELECT D.nodeId, D.releaseDate, D.expireDate
FROM dbo.cmsDocument D  
WHERE D.newest = 1 AND  
(
    D.releaseDate IS NOT NULL  
    OR
    D.expireDate IS NOT NULL 
)

can any one please confirm whether its right or wrong... If its wrong, what is the proper way to get these values..

Thanks
Anz

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

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

发布评论

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

评论(1

一片旧的回忆 2024-12-17 03:14:14

我对 Umbraco 一无所知,但我确实知道并非所有 dbms 都会在计算 your_column_name IS NOT NULL 等表达式时使用索引。

如果您的目标 dbms 不将 IS NOT NULL 视为可控制表达式,那么它不会使用索引。相反,它会进行全表扫描,这在大表上可能需要很长时间。如果需要很长时间,我认为超时仍然是可能的。

也可能releaseDate 或expireDate 上没有索引。在一张大桌子上,这也会让你的速度减慢很多。

如果您想知道哪些文档在今天之前过期,也许您可​​以删除它们,我(也许天真地)希望这个标准 SQL 语句能够工作。 (但我也希望一些 Umbraco 内务处理模块可以使这变得不必要。)

select nodeId
from cmsDocument
where expiredate < CURRENT_DATE

I don't know anything about Umbraco, but I do know that not all dbms will use an index in evaluating expressions like your_column_name IS NOT NULL.

If your target dbms doesn't treat IS NOT NULL as a sargable expression, then it won't use an index. Instead, it will do a full table scan, which can take a long time on a big table. And if it takes a long time, I suppose a timeout is still possible.

It's also possible that there isn't an index on releaseDate or expireDate. On a big table, that will slow you down a lot, too.

If you want to know which documents expired before today, maybe so you can delete them, I'd (perhaps naively) expect this standard SQL statement to work. (But I'd also expect some Umbraco housekeeping module to make this unnecessary.)

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