Use Views or Write Raw Query? I've run across an interesting topic through my work during the past few months. I use the views module heavily in Drupal projects, but I find Views to be painfully annoying in terms of its speed and how it generates all this extra markup (even using style_plugin-&gt;rendered_fields).

I decided one day to ditch Views for a project and write a raw query using Drupal's PDO layer instead. I feel using the PDO layer (despite the fact that it might not be perfect) gave me the ability to grab only the data that I needed in an efficient query.

I brought up to a coworker, "Why don't we just write raw queries...? Views is obviously not integrated into core yet for a reason..." Their response was that Views are easier for beginners and are generally easier to use and to understand. I agree that's a fair point, but what about the performance differences? Don't the performance differences (if there are even any, I might just be configuring things incorrectly) outweigh the usability of the package?

My question is, is there really a big performance hit with Views? Does it make efficient queries, or does it run node_load for each row? I'd also like to know if there's a reason that Views hasn't been included in core yet.

Is Views better than writing queries using the PDO layer, or is it just a matter of personal preference? What about when working with teams?
Here is my take on it

Views


First and most basic advantage is it has a UI which makes it easier for beginners and people with not much knowledge php of to fetch data and display it just with a few clicks.
You can apply filters and relationships to make any kind of joins and filtration of data just with a few clicks.
It provides easy access to exposed filters which allows you do do sorting of data.
It has ajax support.
It has a built in cache mechanism to cache data.
You can AND or OR your data just by drag and drop.
It has support to display the data in various formats like grid, table etc which are available just at a click.


These are just a few points. Now if you try and compare these points to writing a PDO query then yes PDO is definitely fast but you forget after getting the data you also have to do the processing to display the data. Now if you try and do the above mentioned points in a custom module I am pretty sure you will run over a 500 lines of code to implement most of the features.Also don't forget the custom code which needs to be maintained.

If you want to compare views to a PDO check the views query time and the PDO query time it will not be a major difference. Views takes time to do all the rest of the fancy stuff you need to process sanitize your data and display your data in the format of your choice which takes time.

If you are comfortable with PDO I would definitely recommend you to go ahead and use it. The adv are you are using a core feature, 1 less module to me loaded so less http request to load the js and css files.

UPDATE: 10/03/2012
Also came across this node on drupal.org: http://drupal.org/node/242311