有效地更新mySQL表?(Updating a mySQL table efficiently?)

我正在寻找关于这种方法的一些一般性建议。

假设我有一个表格布局,如:

Name | 1hr | 2hr | 3hr | 4hr --------------------------------- Joe | 23 | 12 | 45 | 9

小时是指一小时前。 或者3个小时前。 我会每小时更新一次这些数据。 我会用很多行来做这个。 现在我每次更新时都会将值移到右侧。 所以1小时变为2小时等。然后将1小时插入为新的。

我的问题是这样,而不是更新每个单元格,然后插入新值,这将是最有效的方法吗? 我将使用Java和JDBC来控制这些操作。

我最初的意思是像对待圆形阵列一样对待它。 有一个额外的单元格来保存指向开头的指针。 这将导致每次操作2次更新,而不是4次。

这是一个好方法还是有更好的方法?

I'm looking for a bit of general advice on an approach here.

Say I have a table layout that is like:

Name | 1hr | 2hr | 3hr | 4hr --------------------------------- Joe | 23 | 12 | 45 | 9

The hours refer to an hour ago. Or 3 hours ago. And I will be updating this data every hour. I'll be doing this with many rows. Now each time I update I will move the values to the right. So 1hr becomes 2hr etc. And 1hr is then inserted as new.

My questions is this, instead of updating each cell and then the new value is inserted what would be the most efficient way of doing this? I will be using Java and JDBC as to control these operations.

My initial though is to treat it like you would a circular array. Have an extra cell to hold a pointer to the start. This would result in 2 updates per operations vs 4.

Is this a good approach or is there something better?

最满意答案

更好的方法是存储另一个表:

Name | Time | Value -------------------- Joe | 10:00 | 9 Joe | 11:00 | 45 Joe | 12:00 | 12 Joe | 13:00 | 23

然后,您无需执行任何更新,只需在添加值时添加新行。

The better approach would be to store another table:

Name | Time | Value -------------------- Joe | 10:00 | 9 Joe | 11:00 | 45 Joe | 12:00 | 12 Joe | 13:00 | 23

Then you don't have to do anything to update, you just add a new row when you want to add a value.

有效地更新mySQL表?(Updating a mySQL table efficiently?)

我正在寻找关于这种方法的一些一般性建议。

假设我有一个表格布局,如:

Name | 1hr | 2hr | 3hr | 4hr --------------------------------- Joe | 23 | 12 | 45 | 9

小时是指一小时前。 或者3个小时前。 我会每小时更新一次这些数据。 我会用很多行来做这个。 现在我每次更新时都会将值移到右侧。 所以1小时变为2小时等。然后将1小时插入为新的。

我的问题是这样,而不是更新每个单元格,然后插入新值,这将是最有效的方法吗? 我将使用Java和JDBC来控制这些操作。

我最初的意思是像对待圆形阵列一样对待它。 有一个额外的单元格来保存指向开头的指针。 这将导致每次操作2次更新,而不是4次。

这是一个好方法还是有更好的方法?

I'm looking for a bit of general advice on an approach here.

Say I have a table layout that is like:

Name | 1hr | 2hr | 3hr | 4hr --------------------------------- Joe | 23 | 12 | 45 | 9

The hours refer to an hour ago. Or 3 hours ago. And I will be updating this data every hour. I'll be doing this with many rows. Now each time I update I will move the values to the right. So 1hr becomes 2hr etc. And 1hr is then inserted as new.

My questions is this, instead of updating each cell and then the new value is inserted what would be the most efficient way of doing this? I will be using Java and JDBC as to control these operations.

My initial though is to treat it like you would a circular array. Have an extra cell to hold a pointer to the start. This would result in 2 updates per operations vs 4.

Is this a good approach or is there something better?

最满意答案

更好的方法是存储另一个表:

Name | Time | Value -------------------- Joe | 10:00 | 9 Joe | 11:00 | 45 Joe | 12:00 | 12 Joe | 13:00 | 23

然后,您无需执行任何更新,只需在添加值时添加新行。

The better approach would be to store another table:

Name | Time | Value -------------------- Joe | 10:00 | 9 Joe | 11:00 | 45 Joe | 12:00 | 12 Joe | 13:00 | 23

Then you don't have to do anything to update, you just add a new row when you want to add a value.