简体   繁体   English

将常规SQL结果数组保存为另一个表中的条目确实会减少查询数量,不管是否有好主意?

[英]Saving regular SQL result array as an entry in another table do reduce queries number, good idea or not?

I had an idea and I wonder if its completely stupid or a good idea. 我有一个想法,我想知道它是完全愚蠢还是好主意。

I'm working on a web app which analyze GPX tracks and give stats. 我正在开发一个分析GPX曲目并提供统计数据的网络应用程序。 Actually I'm storing the coordinates of each points of each tracks in a table, this way : 实际上我将每个轨道的每个点的坐标存储在一个表中,这样:

point_id | track_id | lat | lon | else | speed | timestamp

and each time I'm selecting entries from this table, I do it by track_id : 每次我从这个表中选择条目时,我都是通过track_id来完成的:

 SELECT * FROM points WHERE 'track_id'=12

And so I'm getting a full array that I then process to get it formatted for example for my map script : 所以我得到一个完整的数组,然后我处理它以格式化为例如我的地图脚本:

[[46.323, 7.543, 1465663049], [46.323, 7.543, 1465663049], [46.323, 7.543, 1465663049]]...

Or for my speed graph script : 或者我的速度图脚本:

[[1465663049, 9, 12], [1465663049, 9, 12], [1465663049, 9, 12], [1465663049, 9, 12]...

But I think that making a query involving hundreds of entries to process them the same way every time is a bit unproductive so I was wondering if I could make a kind of buffer table with my processed results, for example : 但我认为每次进行涉及数百个条目的查询以相同的方式处理它们有点没用,所以我想知道是否可以使用我的处理结果制作一种缓冲表,例如:

track_id | map_array | graph_array 

So I would only have to make one query to get my array, but it means that the field will be quite big as they would need to store thousands of characters an entry. 因此,我只需要进行一次查询来获取我的数组,但这意味着该字段将非常大,因为它们需要存储数千个字符的条目。

Maybe a best choice would be to store them in a json datatype field so it can be easily used by my scripts ? 也许最好的选择是将它们存储在json数据类型字段中,以便我的脚本可以轻松使用它?

Do you think it is a good idea ? 你认为这是个好主意吗?

TL;DR : Storing gps tracks point in several entries or storing them in a single entry with json datatype ? TL; DR:存储gps跟踪多个条目中的点或将它们存储在具有json数据类型的单个条目中?

Thank you for reading me. 谢谢你读我。

François 弗朗索瓦

Thanks to Solarflare advices and some reflexion I think I have the answer for my own case. 感谢Solarflare的建议和一些反思,我想我已经找到了自己案例的答案。

As my queries for tracks will be always identical, it makes no sense to look trough each points it's like always asking the same question when you know the answer. 由于我对曲目的查询总是相同的,所以通过查看每个点都没有意义,就像你知道答案时总是问同样的问题一样。

So here is my database structure I will be using and which I think is the most easy to use and maintain but also the less resource intensive. 所以这是我将使用的数据库结构,我认为它最容易使用和维护,但资源密集程度也较低。 At least in my own case. 至少在我自己的情况下。

  • The gpx files will be decomposed in points that will be stored in the database to be able to have access to the original data. gpx文件将以存储在数据库中的点进行分解,以便能够访问原始数据。
  • In another table, the points will be stored as an array in a text field for quick and simple "one query" access. 在另一个表中,这些点将作为数组存储在文本字段中,以便快速简单地进行“一次查询”访问。

My two tables will be something like that : 我的两个表将是这样的:

Original track points : 原始跟踪点:

point_id | user_id | track_id | lat | lon | else | speed | timestamp

Processed tracks : 处理过的曲目:

track_id | user_id | map_array | graph_array 

I'm not a php or database expert but if I have to query 10 tracks on a page the performance should be different if I have to get 10 * ~600 entries or just 10 entries which doesn't need processing. 我不是一个PHP或数据库专家,但如果我必须查询页面上的10个曲目,如果我必须获得10 * ~600个条目或只需要10个不需要处理的条目,性能应该是不同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM