Technically not an answer, but maybe the problem here is SQL? I'm thinking a document-storage system like CouchDB might be a much more effective solution for this scenario.
The "circle" stanza would change name and details depending on the shape. Rectangles would have the corners (similar to "boundingBox"), ellipsoids would have... Whatever defines ellipsoids :p
You could store a list of vertices that define the polygon.
You could store a list of vectors that define the edges of the polygon.
How they could be stored in a database:
Master table of shape, with primary key an identity called "shapeID"
Vector table, with a primary key identifying the vectorID, foreign key to the appropriate ShapeID, origin (x,y,z coords), direction (x,y,z), and length.
Additional meta data can be assigned to a shape with other tables that also reference the shapeID by foreign key.
There isn't really a "best" way to store an inheritance hierarchy in a database. There are 3 models that are taught in most database courses: Single Table with nulls, Table per SubClass, and Table per Concrete Class. You can find a good explanation in this blog post. You can choose whichever one of these that you prefer if you want to simply map the attributes of your shapes in the database.
If you want something more advanced to, MySql provides a Geometry type that is specifically designed to store geometric shapes.
shape type (e.g. 0= circle, 1= square, 3= triangle, ...)
One table, all possible shapes, one shape instance/row
IMHO...
Q: How many different shapes do you think you might have? How many columns do you think each shape might take?
PS: A "polygon" (consisting of an arbitrary number of points) might merit two separate tables. But most shapes (circle, ellipse, square, rectangle, etc) shouldn't need more than 4 or 5 columns/instance, and should easily fit in one table.
I opted for the second solution because is easy to manage and extend. The serialization option is not practical because if the structure of the serialized model changes (example : adding an attribute), I have to manage the model versions. The third option is just not the right approach of building databases.
发布评论
评论(5)
从技术上讲这不是一个答案,但也许这里的问题是 SQL?我认为像 CouchDB 这样的文档存储系统可能是这种情况下更有效的解决方案。
我在想这样的事情:
}
"circle"
节将根据形状更改名称和详细信息。矩形有角(类似于"boundingBox"
),椭圆体有......无论什么定义椭圆体:pTechnically not an answer, but maybe the problem here is SQL? I'm thinking a document-storage system like CouchDB might be a much more effective solution for this scenario.
I'm thinking something like this:
}
The
"circle"
stanza would change name and details depending on the shape. Rectangles would have the corners (similar to"boundingBox"
), ellipsoids would have... Whatever defines ellipsoids :p一些简单的想法:
它们如何存储在数据库中:
可以将其他元数据分配给具有其他表的形状,这些表也通过外键引用 shapeID。
Some simple ideas:
How they could be stored in a database:
Additional meta data can be assigned to a shape with other tables that also reference the shapeID by foreign key.
确实没有一种“最佳”方法可以在数据库中存储继承层次结构。大多数数据库课程教授 3 种模型:带空值的单表、每个子类表和每个具体类表。您可以在 这篇博文。如果您想简单地映射数据库中形状的属性,则可以选择您喜欢的其中之一。
如果你想要更高级的东西,MySql 提供了 Geometry 类型 专门用于存储几何形状。
There isn't really a "best" way to store an inheritance hierarchy in a database. There are 3 models that are taught in most database courses: Single Table with nulls, Table per SubClass, and Table per Concrete Class. You can find a good explanation in this blog post. You can choose whichever one of these that you prefer if you want to simply map the attributes of your shapes in the database.
If you want something more advanced to, MySql provides a Geometry type that is specifically designed to store geometric shapes.
我投票:
制作一个包含所有可能字段的形状表:
...
一张表,所有可能的形状,一个形状实例/行
我直言...
问:您认为您可能有多少种不同的形状?你认为每个形状可能有多少列?
附:
“多边形”(由任意数量的点组成)可能需要两个单独的表。但大多数形状(圆形、椭圆形、正方形、矩形等)每个实例不需要超过 4 或 5 列,并且应该可以轻松放入一张表中。
I'd vote:
Make a Shape table with all possible fields:
...
One table, all possible shapes, one shape instance/row
IMHO...
Q: How many different shapes do you think you might have? How many columns do you think each shape might take?
PS:
A "polygon" (consisting of an arbitrary number of points) might merit two separate tables. But most shapes (circle, ellipse, square, rectangle, etc) shouldn't need more than 4 or 5 columns/instance, and should easily fit in one table.
我选择了第二种解决方案,因为它易于管理和扩展。序列化选项不实用,因为如果序列化模型的结构发生变化(例如:添加属性),我必须管理模型版本。第三种选择并不是构建数据库的正确方法。
I opted for the second solution because is easy to manage and extend. The serialization option is not practical because if the structure of the serialized model changes (example : adding an attribute), I have to manage the model versions. The third option is just not the right approach of building databases.