0

I'm wondering what method I should use for copying data from one table to another one. I'm letting users post data through a form which uses table1 to save data. Now for displaying results I use data from table2 but I also need some data from table1.

  • Method 1: Copy the needed data on pageload, when the user executes it. Might get slower, but uses live data.
  • Method 2: Use a cronjob. Less resources, but not live data

I'm interested in how much this will affect the speed of the website.

2

Depends on the amount of data.

If:

  • No large/weird/complex queries
  • No large datasets
  • Rowlocking (innoDB) instead of tablelocking (MyISAM)
  • No absurt amount of users/pagehits

Then you have no problem at all. Just make sure you index the right columns, and cleanup what you can so you dont get redundent data. If you're not sure when you should consider something 'a large dataset', you're not using a large dataset.

Easy answer: Just try and you'll see :).
But to my experience, the most influention factor is the queries themselves, just make sure those are right.


If you are talking about duplicating data, then please stop doing that! You can select info from two tables without ANY problem. Just use two queries, or a join.

Duplicate data is a big no-no in databases. 1 small column might provide a handy solution sometime, but always try the best you can to avoid it. This is a part of database normalisation.

  • thanks for your answer. Index is ok, the queries in my opinion are ok, but this isn't the place to discuss the quality of them. But indeed I do duplicate some data, but the two tables each are having another purpose. So I think it's ok to duplicate them? Dataset isn't large except I have no idea of the pagehits... – brobken May 6 '14 at 9:46
  • 1
    I just made an edit about duplicating – Martijn May 6 '14 at 9:48
  • So as I understand from your answer you would suggest me to rewrite the code for displaying the data from table2, so it will display all data from table2 and the needed data from table1? – brobken May 6 '14 at 9:53
  • 3
    Never duplicate. If you have the data in another table, just select the data from that table. – Martijn May 6 '14 at 9:56
  • 1
    It's perfectly normal to select data from two tables, Im afraid don't see the problem you're having. – Martijn May 6 '14 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.