TheGeeky
TheGeeky

Reputation: 971

Is sql views the proper solution

I have a table named 'Customers' which has all the information about users with different types (user, drivers, admins) and I cannot separate this table right now because it's working on production and this is not a proper time to do this.

so If I make 3 views: the first has users types only, the second has drivers and the third has admins.

My goal is to use 3 models instead one in the project I'm working on so is this a good solution and what does it cost on performance?

Upvotes: 0

Views: 60

Answers (2)

Rick James
Rick James

Reputation: 142306

I suggest that it is improper to give end-users logins directly into the database. Instead, all requests should go through a database-access layer (API) that users must log into. This layer can provide the filtering you require without (perhaps) any impact to the user. The layer would, while constructing the needed SELECT, tack on, for example, AND type = 'admin' to achieve the goal.

For performance, you might also need to have type at the beginning of some of the INDEXes.

Upvotes: 0

Vikora
Vikora

Reputation: 174

  1. How big is your table 'Customers'? According to the name it doesn't sounds like heavy one.
  2. How often these views will be queried?
  3. Do you have some indices or pk constraints on the attribute you're are going to use in where clause for the views?

I cannot separate this table right now because it's working on production and this is not a proper time to do this.

From what you said it sounds like a temporarily solution so it probably the good one. Later you сan replace the views with three tables and it will not affect the interface.

Upvotes: 1

Related Questions