Should I bother to build unique PDO for update?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
grNadpa
New php-forum User
New php-forum User
Posts: 24
Joined: Fri Dec 02, 2016 8:32 am

Fri May 11, 2018 6:36 am

In your opinion, is it worthwhile to try to determine which values the user changed and construct a PDO update statement specifically for just those db columns, or simply update all the row's columns even if most of them have not changed.

It seems to me that the effort to determine which values the user changed on the form would require either saving the original query results , such as in $_SESSION , prior to sending the form. Or, upon receiving the $_POST, repeating the database query to get the original values prior to building the update PDO statement.

Then, of course, generating some non-trivial php script to build that custom PDO UPDATE statement.

Though I am ready to do so, I wonder if the effort really buys anything in system performance.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 720
Joined: Mon Feb 22, 2016 5:52 pm

Fri May 11, 2018 7:48 am

If it's 'System performance' that you're concerned about, then I ask you this: do you really need to improve the performance? What justification would you have for this if the answer is yes?

To try to determine if you have achieved any time saving, you would need to benchmark what you have and try a few different ways and see what the results are, the number and type of PHP operations is not always an indicator of execution performance.

I probably would look at the rest of the design before an update sql statement.

chorn
php-forum Fan User
php-forum Fan User
Posts: 559
Joined: Fri Apr 01, 2016 2:18 am

Fri May 11, 2018 8:19 am

I would guess that every sophisticated database would have some build-in functions to update only changed columns to reduce write operations by itself. You could make some benchmarks of it, but i would guess you won't get any real performance boost, if you do not pass mega- or gigabytes of data within your query.

grNadpa
New php-forum User
New php-forum User
Posts: 24
Joined: Fri Dec 02, 2016 8:32 am

Mon May 14, 2018 10:05 am

Thank you for your replies
chorn wrote:
Fri May 11, 2018 8:19 am
I would guess that every sophisticated database would have some build-in functions to update only changed columns to reduce write operations by itself.
hyper wrote:
Fri May 11, 2018 7:48 am
If it's 'System performance' that you're concerned about, then I ask you this: do you really need to improve the performance?
The short answer is 'No, I have no performance issues.' So I take your answers as agreement that the machinations to parse which fields changed is not worth the effort.

My larger issue is simply that I rely on this forum to get a sense of best practices. And answers such as yours are extremely valuable.

Thank You

Post Reply