-
Website
http://awesomeful.net/ -
Original page
http://awesomeful.net/posts/45-postgresql-rails-and-why-you-should-care -
Subscribe
All Comments -
Community
-
Top Commenters
-
posterhuhu
1 comment · 1 points
-
joeri
1 comment · 1 points
-
John Trupiano
1 comment · 1 points
-
technicalpickles
1 comment · 1 points
-
Saturn Flyer
1 comment · 2 points
-
-
Popular Threads
Also, the Postgres Optimizer is light-years ahead of MySQL. The MySQL docs even say it cannot use indexes in a sub query. And Postgres can build partial indexes and indexes on a function. For example, you can index only the open orders, so you can pull up open orders quickly, but don't have the overhead of indexing a billion closed orders.
There's some overlap with ActiveRecord models, but it's a manageable problem and in my opinion, better than combining sources or using ActiveResource. I have a client running a forum, cms, and custom app with shared tables and the concerns for the applications are kept separate.
SELECT * FROM parts WHERE ordered_at > '2009-01-01 00:00:00' AND delivered_at < '2009-01-15 10:00:00'
Given this, and an index on (ordered_at, delivered_at) MySQL will only be able to use the first column of the index. Any tips on whether PostgreSQL handles this better?
[1]: http://dev.mysql.com/doc/refman/5.0/en/range-ac...
PostgreSQL it would definitely use both columns if you define an index on the
ordered_at and delivered_at columns. Here's a quick example:
http://gist.github.com/160963
when deciding whether to use two separate indexes or one index with both
columns:
http://www.postgresql.org/docs/8.4/interactive/...
I personally don't think one is better than the other, they both have their strengths and weaknesses, what I've found is that if you're really familiar with one over the other you're probably going to build a better, more efficient system due to the knowledge in the other RDBMS not being as up to par.
A _Ruby_ user on the other hand...
Check out Enterprise Rails (2008, O'Reilly) by Dan Chak to learn more about leveraging "advanced" database features. Dan is obviously very opinionated, and while it's arguable everything he writes should be accepted without further questioning (i.e. he refuses to use Rails migrations, which imho are a great tool), it's still an intriguing read, making you ask yourself if everything Rails does is really the best approach to handle things.
you definitely have a good point regarding ActiveRecord: it will abstract out and move most functionality to the ORM layer as opposed to living at the database layer, which is A Good Thing (TM). In most Rails app this will suffice, especially on the small to medium sized ones.
I have however used some of Postgres' features in a Rails project. For instance, I've used views and rules in a Rails project, and ActiveRecord happily thought it was just a table. Some may argue that triggers are a safer way to do things like database auditing, especially when the Rails app is not the only system that is inserting/updating the database. As an aside, we implemented a very data heavy system that required ETL'ing data from numerous sources and that's where something like Pl/Ruby or Pl/PGSql came in handy.
In any case, this is aside from my main point: it's all about PostgreSQL's license and community. The slew of features and awesomeness of the DBMS are just there to back up my argument.
Because rails don't use any "great features" of postgresql likes RULES, TRIGGERS, VIEWS, FK, PostGIS or FullText Search (easy implementable I think if it's likes in Django), and I don't think we can use RULES, FK or other "exotics things" with rails without brake it...
Mysql is also great for some features that boot performances likes the Query Cache (but useless if you have a good caching strategy on the rails app), and easy master/slave replication...
I prefer Postgresql (I use it with Django), but i'm not sure if it work great with Rails ? (I plan to migrate from Django to Rails)
Rails will not "use" any of these features, but you can certainly implement them and have Rails' ActiveRecord just keep running queries/inserts/updates as any other ORM would. I have certainly used views and rules in a Rails app. I can imagine using triggers for some stuff (maybe auditing?) without Rails even knowing about it. I use FKs on all my Rails app, helped by the redhillonrails plugin mentioned on other comments above. I've never done PostGIS, but there are two plugins for using tsearch that I want to explore shortly: acts_as_tsearch and tsearchable - google's your friend.
The one plus for MySQL has got to be replication. Slony - probably the most popular package - works well, but it is definitely not easy to set up and does it's work via SQL triggers as opposed to binary log shipping. As mentioned on the post, this is an area that is being worked on, and will be part of the PostgreSQL core soon.
I can tell you, PostgreSQL DOES work great with Rails.
Thanks for stopping by, and welcome to Rails? Hope you enjoy the ride.
A simple master-slave = 8x more data travel on the network (2x on MySQL)
Replication with 4 servers = 32x more data (4x on MySQL)
Replication with 12 servers = 288x more data (12x on MySQL)
It's not useable on huge database cluster....
Source: http://www.wikivs.com/wiki/MySQL_vs_PostgreSQL
And you say : "it's work via SQL triggers", All Foreign Key on Postgresql are managed with hidden Triggers (I discovered that many days ago...) The triggers are on pg_catalog (by example: pg_catalog.RI_FKey_cascade_del() is called when you delete an "ON DELETE CASCADE" foreign key entry)
(I didn't found any article on that, but i don't know what can be the other usage of this triggers, the description said: "referential integrity ON DELETE CASCADE", so I think it's that)
Slony's bandwidth overhead is a direct consequence of the fact that it's not shipping binary logs, but SQL statements over to the slaves. Slony is not the only replication solution for PostgreSQL...