WQL不支持TOP-需要解决方法 [英] WQL does not support TOP - need workaround

查看:92
本文介绍了WQL不支持TOP-需要解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WQL(基本上是WMI的SQL)不支持TOP或LIMIT关键字. Sql Server使用TOP和许多其他RDBMS支持LIMIT等.

WQL (basically SQL for WMI) does not support a TOP or LIMIT keyword. Sql Server used TOP and many other RDBMSs supprt LIMIT etc.

是否有一种变通方法来模拟SELECT查询,使其表现为好像它具有将结果集限制为任意数字的TOP/LIMIT子句一样?

Is there a workaround to emulating a SELECT query to behave as though it had a TOP/LIMIT clause that limits the result set to some arbitrary number?

或者还有其他一些特定于WQL的关键字可以像TOP或LIMIT一样起作用吗?

Or is there some other WQL-specific keyword that works like TOP or LIMIT?

推荐答案

不,没有办法单独使用WQL来模拟TOP.

Nope, there's no way to simulate TOP using WQL alone.

例外:如果您有幸查询一个未断开的WMI类,则将数字实例号用作键,则可以使用大于和小于的比较来限制和分页结果.

Exception: if you're lucky enough to be querying a WMI class which has ungapped, ascending numeric instance numbers used as keys, then you can use greater-than and less-then comparisons to limit and page through the results.

可能 ManagementClass.GetInstances()而不是使用WQL查询可能允许您在收集到足够多的实例后中途取消枚举,从而避免支付一次枚举整个列表的CPU和RAM成本.

It's possible that ManagementClass.GetInstances() instead of using a WQL query might allow you to cancel the enumeration midway once you've collected enough instances, and hence avoid paying the CPU and RAM cost of enumerating the whole list at once.

请注意,CIMV2 WMI提供程序AFAIK本身并不处理WQL,而是仅依靠WMI枚举所有实例,处理WQL并过滤结果,然后再将其返回给调用方.但是昂贵的部分(实际上是获取底层的WMI数据)仍然可以完成.因此,我相信使用WQL与使用GetInstances()并自行过滤结果不会(对于本地WMI查询)会提高效率-如果GetInstances()允许您中途取消,则GetInstances()对于长结果集,可能要便宜得多.

Note that, AFAIK, the CIMV2 WMI provider doesn't natively handle WQL-- instead it simply relies on WMI to enumerate all instances, process the WQL, and filter the results before returning them to the caller. But the expensive part (actually fetching the underlying WMI data) is still done. So I believe there's no efficiency gain to be had (for local WMI queries, that is) by using WQL vs. using GetInstances() and filtering the results yourself-- and if GetInstances() allows you to cancel midway, then GetInstances() may be much cheaper for long result sets.

这篇关于WQL不支持TOP-需要解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆