在 Sql Server 2008 中 1 个几何列与 4 个小数列的相对性能是多少?

发布于 2025-01-07 08:19:29 字数 201 浏览 1 评论 0原文

我需要在 SQL Server 2008 数据库中表示四边形 矩形表面的尺寸。我需要根据不同点之间的距离和表面的总面积来执行查询。

使用几何数据类型或 4 个小数列我的性能会更好吗?为什么?

如果在这种情况下几何数据类型是不必要的,那么使用几何数据类型需要多少复杂的几何形状才能有意义?

I need to represent the dimensions of a piece of a quadrilateral rectangle surface in a SQL Server 2008 database. I will need to perform queries based on the distance between different points and the total area of the surface.

Will my performance be better using a geometry datatype or 4 decimal columns? Why?

If the geometry datatype is unnecessary in this situation, what amount of complexity in the geometrical shape would be required for using the geometry datatype to make sense?

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

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

发布评论

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

评论(3

梦罢 2025-01-14 08:19:29

我没有使用过几何数据类型,也从来没有理由去阅读它。即便如此,在我看来,如果您只是对一个简单的几何对象进行基本算术运算,那么普通的旧 SQL 数据类型应该非常有效,特别是如果您为经常使用的计算添加一些计算列。

例如:

--DROP TABLE MyTable
CREATE TABLE MyTable
 (
   X1  decimal  not null
  ,Y1  decimal  not null
  ,X2  decimal  not null
  ,Y2  decimal  not null
  ,Area as abs((X2-X1) * (Y2-Y1))
  ,XLength as abs((X2 - X1))
  ,YLength as abs((Y2 - Y1))
  ,Diagonal as sqrt(power(abs((X2 - X1)), 2) + power(abs((Y2 - Y1)), 2))
 )

INSERT MyTable values (1,1,4,5)
INSERT MyTable values (4,5,1,1)
INSERT MyTable values (0,0,3,3)

SELECT * from MyTable

丑陋的计算,但除非实际引用它们(或者除非您选择对它们建立索引),否则它们不会被执行。我没有统计数据,但通过几何数据类型执行相同的操作可能意味着访问很少使用的数学子例程,可能嵌入在系统 CLR 程序集中,而且我只是看不出它比裸机快得多-bones SQL 算术例程。

我刚刚查看了 BOL 中的几何数据类型。 (a) 响动! (乙)酷!查看“几何数据类型方法参考”下的条目 (在线,但您想要查看此条目下的扩展树视图。)如果这就是您需要的功能,请务必使用几何数据类型,但为了简单处理,我会坚持使用 knucklescraper 数据类型。

I have not used the geometry datatype, and have never had reason to read up on it. Even so, it seems to me that if you’re just doing basic arithmatic on a simple geometric object, the mundane old SQL datatypes should be quite effiicient, particularly if you toss in some calculated columns for frequently used calculations.

For example:

--DROP TABLE MyTable
CREATE TABLE MyTable
 (
   X1  decimal  not null
  ,Y1  decimal  not null
  ,X2  decimal  not null
  ,Y2  decimal  not null
  ,Area as abs((X2-X1) * (Y2-Y1))
  ,XLength as abs((X2 - X1))
  ,YLength as abs((Y2 - Y1))
  ,Diagonal as sqrt(power(abs((X2 - X1)), 2) + power(abs((Y2 - Y1)), 2))
 )

INSERT MyTable values (1,1,4,5)
INSERT MyTable values (4,5,1,1)
INSERT MyTable values (0,0,3,3)

SELECT * from MyTable

Ugly calculations, but they won’t be performed unless and until they are actually referenced (or unless you choose to index them). I have no statistics, but performing the same operations via the Geometry datatype probably means accessing rarely used mathematical subroutines, possibly embedded in system CLR assemblies, and I just can’t see that being significantly faster than the bare-bones SQL arithmatic routines.

I just took a look in BOL on the Geometry datatype. (a) Zounds! (b) Cool! Check out the entries under “geomety Data Type Method Reference” (online here , but you want to look at the expanded treeview under this entry.) If that’s the kind of functionality you’ll be needing, by all means use the Geometry data type, but for simple processing, I’d stick with the knucklescraper datatypes.

初相遇 2025-01-14 08:19:29

几何数据类型比简单的小数更复杂,因此只会产生开销。但它们确实提供了计算两点之间距离的函数,我认为这些函数已经过优化。问题可能是,如果您实现了点之间的距离逻辑 - 这是否会比首先以适当的格式获取数据花费更长的时间。

由于每个数据库问题都可能与插入与选择/计算的比率有关

the geometry data types are more complex than simple decimals so there just be an overhead. But they do provide functions that calculate distance between two points and i would assume these have been optermised. The question might be if you implemented the distance between points logic - would this take longer than having the data in appropriate format in the first place.

As every DB question might relate to the ratio of inserts v selects/calc's

执手闯天涯 2025-01-14 08:19:29

Geometry 数据类型是空间数据,而decimal 不是,

空间数据与非空间数据

空间数据包括位置、形状、大小和方向。
例如,考虑一个特定的正方形:
它的中心(对角线的交点)指定了它的位置
它的形状是正方形
其一侧的长度指定其尺寸
它的对角线与 x 轴的角度指定了它的方向。
空间数据包括空间关系。例如,十个保龄球瓶的排列就是空间数据。

非空间数据(也称为属性或特征数据)是独立于所有几何考虑因素的信息。
例如,人的身高、质量和年龄是非空间数据,因为它们与人的位置无关。
有趣的是,虽然质量是非空间数据,但重量是空间数据,因为某物的重量很大程度上取决于它的位置!

可以忽略空间数据和非空间数据之间的区别。然而,它们之间存在根本区别:
空间数据通常是多维且自相关的。
非空间数据通常是一维且独立的。

这些区别将空间和非空间数据划分为不同的哲学阵营,对概念、处理和存储问题产生深远的影响。
例如,排序可能是执行的最常见和最重要的非空间数据处理功能。
如何对位置数据进行排序以使所有点最终都位于“附近”并不明显。他们最近的邻居。

这些区别证明有必要单独考虑空间和非空间数据模型。除非另有说明,本单元仅关注后者。

如果您有兴趣,还有更多内容:
http://www.ncgia.ucsb.edu/giscc/units/u045 /u045_f.html

这是我找到的有关空间数据仓库基准测试的链接:http://hpc.ac.upc.edu/Talks/dir08/T000327/paper .pdf

Geometry datatype is Spatial and decimal isn't,

Spatial vs. Non-spatial Data

Spatial data includes location, shape, size, and orientation.
For example, consider a particular square:
its center (the intersection of its diagonals) specifies its location
its shape is a square
the length of one of its sides specifies its size
the angle its diagonals make with, say, the x-axis specifies its orientation.
Spatial data includes spatial relationships. For example, the arrangement of ten bowling pins is spatial data.

Non-spatial data (also called attribute or characteristic data) is that information which is independent of all geometric considerations.
For example, a person?s height, mass, and age are non-spatial data because they are independent of the person?s location.
It?s interesting to note that, while mass is non-spatial data, weight is spatial data in the sense that something?s weight is very much dependent on its location!

It is possible to ignore the distinction between spatial and non-spatial data. However, there are fundamental differences between them:
spatial data are generally multi-dimensional and autocorrelated.
non-spatial data are generally one-dimensional and independent.

These distinctions put spatial and non-spatial data into different philosophical camps with far-reaching implications for conceptual, processing, and storage issues.
For example, sorting is perhaps the most common and important non-spatial data processing function that is performed.
It is not obvious how to even sort locational data such that all points end up ?nearby? their nearest neighbors.

These distinctions justify a separate consideration of spatial and non-spatial data models. This unit limits its attention to the latter unless otherwise specified.

Here's some more if you're interested:
http://www.ncgia.ucsb.edu/giscc/units/u045/u045_f.html

Heres a link i found about Benchmarking Spatial Data Warehouses: http://hpc.ac.upc.edu/Talks/dir08/T000327/paper.pdf

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