blue
blue

Reputation: 555

Mysql: Views VS recurrent table joins

I have cron jobs that execute queries on a database every minute. In some of these tasks, I need to make the join between two relatively big tables.

I thought of using a view instead, but I am concerned about the performance

The data in those two tables do not vary a lot in term of quantity, but I have a column (not included in the view) that is updated every 40 seconds

Does that mean that my view is updated every 40 seconds?

Is the view in this case a good idea?

Upvotes: 0

Views: 31

Answers (2)

slaakso
slaakso

Reputation: 9080

A view is not updated when the underlying tables change. A view is just a query that is executed when the query is made against the view.

The query performance when using a view depends on the query. You just need to check if your query against the view uses indexes correctly and what is the performance.

Upvotes: 1

Bill Karwin
Bill Karwin

Reputation: 562911

Views are not updated on any cadence, because they don't store anything. At least not in MySQL. Some other brands of SQL database implement materialized views, but MySQL does not.

Querying a view is exactly like running the query yourself. It reads from the base tables at the moment you query the view, and it does so every time you query the view.

So views in MySQL are more like a macro.

Upvotes: 1

Related Questions