Use GUI displayed results of SQL query vs new queries?

149 views Asked by At

I am developing a program, with a database and a GUI which displays parts of the database.

Let's suppose I have a textblock which contains data from the database (found with a query). If I want to use the value of this textblock somewhere else in the program, should I better read it from the textblock, or call it a second time from the database?

In other words is it OK, in term of performance and maintainability, to use GUI displayed results of SQL query as an input from other functions, instead of doing new queries?

1

There are 1 answers

10
Tobb On BEST ANSWER

There are a few things to consider here:

  • Stale data/concurrency. If multiple people/processes work on the same database objects, keeping the same data in the GUI for a long time might lead to stale data, where the data shown is old and out of sync with the actual data in the database. This might lead to errors when the data is updated.

  • Coupling. Sharing state between multiple GUI components could lead to a maintenance nightmare, since you can't change one part of the GUI without it having an effect on another part of the GUI.

  • Performance. Networks are fast. Optimized queries run towards an optimized database are fast. The performance gain from reusing query data thus shouldn't be too high. And probably not enough to justify not re-fetching the data from the database, ref the other bullet points.