Thursday 15 March 2012

mysql - A SQL story in 2 parts - Are SQL views always good and how can I solve this example? -


I am creating a reporting app, and so I am suppressing very terrible statistics. To create an app in a tight way, one part of your perspective is to use SQL visuals if more than one user is going to take away the DB straining away from all.

An example is:.

  mysql_query ("View View View_CylverPapa_clicks_baby_ $ Select Email SELECT view_email_baby_position.EmailAddress, view_email_baby_position.days, silverpop_campaign_emails.id, silverpop_actions.` click name`, silverpop_circrym. 'Mailing ID` silverpop_uploadsInNER Join On the eMail_baby_position (SilverPop_action.mail = view_mail_bb_position.emailAddress), silverpop_campaign_emails where silverpop_campaign_emails.id = $ email and view_email_baby_position.days silverpop_campaign_emails.low and silverpop_campaign_emails.high and silverpop_actions.Event Type` = ' The book ') or (among the dead mysql_error ());  

And then this later click on the script has a special taste of this email that is used to calculate the number. '' Name '' as 'count' in the form of counting from `visible_silverpip_clicks_bab_ $ email` in the form of` $ sql = "selection number (*);

My question is actually in 2 parts:

  1. Is the ideas always good? Can you have too much?
  2. Can I create a group of other ideas to cache the counting variable in the second snippet of code. If so, how can I reach it? I can not quite know it yet

Thank you!

"itemprop =" text ">

After answering your questions

1.) I do not know that I can think of an example when the scenes and the bad ones are themselves, but it would be bad to use them unnecessarily. Depending on your situation you may be too much.

2.) Counting variables will not be cached because of one more set of ideas, so it will not be beneficial from that point of view.

After saying this, I think that you have a misunderstanding. Is there really a view? A view is just a definition of a particular SQL statement, and it does not cache data. When you select a from MyView *; , the database is still being executed as defined in the Definition View statement that it would be created if a user was executing that statement.

Some database vendors present a different kind of view, which is called physical view. In this case, the necessary table data is stored / cached to create the view and it is usually updated when the refresh rate is specified when you create it. It is "heavy" in this sense that your data is stored twice, but can make better execution plans because the data has already been gathered, collected. Note However, you only see data based on the last refresh of the physical scene, where you are viewing the data with a normal view because it currently exists in the underlying tables, MySQL does not currently support physical ideas.

Some useful uses of ideas are as follows:

  • Create easy / cleaner SQL statements for complex queries (whatever you are doing)

  • Security. If you have tables where you want a user to be able to see some columns or rows, but not other columns / rows, you restrict access to the base table and create a view of the base table which only Selects columns / rows that user should also have access.

  • Create aggregates of tables


No comments:

Post a Comment