Level-up Your ActiveRecord Skills: Learn SQL!

Video thumbnail (Frame 0) Video thumbnail (Frame 1636) Video thumbnail (Frame 4509) Video thumbnail (Frame 5945) Video thumbnail (Frame 7541) Video thumbnail (Frame 8724) Video thumbnail (Frame 12173) Video thumbnail (Frame 14445) Video thumbnail (Frame 18406) Video thumbnail (Frame 19855) Video thumbnail (Frame 21376) Video thumbnail (Frame 22545) Video thumbnail (Frame 23708) Video thumbnail (Frame 25785) Video thumbnail (Frame 29528) Video thumbnail (Frame 31218) Video thumbnail (Frame 36540) Video thumbnail (Frame 37865) Video thumbnail (Frame 44487) Video thumbnail (Frame 46516) Video thumbnail (Frame 47318) Video thumbnail (Frame 50780) Video thumbnail (Frame 51992)
Video in TIB AV-Portal: Level-up Your ActiveRecord Skills: Learn SQL!

Formal Metadata

Level-up Your ActiveRecord Skills: Learn SQL!
Title of Series
Part Number
Number of Parts
CC Attribution - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
ActiveRecord is a great tool, but knowing SQL can help you to build better, faster applications and quickly find answers to common business questions. In this talk you'll see an overview of basic-to-intermediate SQL techniques that you can use to: learn about unfamiliar data sets, identify and resolve slow query problems, quickly build ad-hoc reports, combine multiple tables and perform calculations. Specifically targeted to the Junior Rails Developer, we will explore with non-trivial yet approachable examples and see how learning SQL can help you become a better software developer.
Degree (graph theory) Trail Mathematics Computer animation Internetworking Multiplication sign Software developer Videoconferencing Booting
Web page Statistics Sequel Code Weight Multiplication sign Software developer Moment (mathematics) Database Bit Demoscene Formal language Product (business) Word Computer animation Query language Calculation Right angle Physical system Row (database)
Sequel Code Software developer Insertion loss Incidence algebra Line (geometry) Bookmark (World Wide Web) Twitter Web application Computer animation Electronic meeting system Term (mathematics) String (computer science) Self-organization Video game console Data structure Family Row (database)
Sequel Code Multiplication sign System administrator Parameter (computer programming) Field (computer science) Element (mathematics) Attribute grammar Formal language Array data structure Object-oriented programming Bit rate Single-precision floating-point format Data structure Information security Task (computing) Physical system Form (programming) Standard deviation Software developer Interface (computing) Interactive television Electronic mailing list Database Line (geometry) Cartesian coordinate system Type theory Computer animation Software Query language Moving average Object (grammar) Quicksort Table (information) Resultant
MIDI Group action Sequel Inheritance (object-oriented programming) Code Multiplication sign 1 (number) Counting Bit Database Line (geometry) Formal language Process (computing) Computer animation Software Order (biology) Software framework Quicksort Data structure Spacetime Row (database)
Point (geometry) Web page Group action Theory of relativity Real number Electronic mailing list Database Cartesian coordinate system Field (computer science) Formal language Number Human migration Programmer (hardware) Process (computing) Computer animation Forest Authorization Energy level Row (database)
Boss Corporation Information Projective plane Counting Database Client (computing) Mereology System call Type theory Radical (chemistry) Process (computing) Computer animation Authorization Resultant Row (database) Stability theory
Web page Trail Group action Statistics Functional (mathematics) Mobile app Code Multiplication sign Set (mathematics) Event horizon Number Different (Kate Ryan album) Average Forest Single-precision floating-point format Selectivity (electronic) Standard deviation Counting Database Maxima and minima Bit Line (geometry) Word Arithmetic mean Computer animation Personal digital assistant Query language Calculation Summierbarkeit Quicksort Table (information) Resultant Row (database)
Group action Randomization Sequel Combinational logic Total S.A. System call Field (computer science) Number Computer animation Integrated development environment Query language Natural number Authorization Codec Right angle Software testing Quicksort Table (information) Resultant Fiber (mathematics) Row (database)
Type theory Latent heat Computer animation Query language Authorization Row (database)
Laptop Web page Point (geometry) Slide rule Mobile app Server (computing) Sequel Multiplication sign Modal logic Direction (geometry) Function (mathematics) Login Product (business) 2 (number) Different (Kate Ryan album) Traffic reporting Information Software developer Planning Database Bit Cartesian coordinate system Demoscene Subject indexing Type theory Word Uniform resource locator Computer animation Query language Personal digital assistant Video game MiniDisc output Data logger Right angle Cycle (graph theory) Game theory
Functional (mathematics) Sequel Real number Multiplication sign Drop (liquid) Login Neuroinformatik Attribute grammar Product (business) Mathematics Computer programming Extension (kinesiology) Physical system Touchscreen Inheritance (object-oriented programming) Software developer Keyboard shortcut Electronic mailing list Database Cartesian coordinate system System call Computer animation output Remote procedure call Table (information)
Sequel Multiplication sign Equaliser (mathematics) Parameter (computer programming) Mereology Formal language Computer programming String (computer science) Authorization Endliche Modelltheorie Contrast (vision) Computer-assisted translation Arm Key (cryptography) Block (periodic table) Database Cartesian coordinate system System call Connected space Human migration Subject indexing Type theory Arithmetic mean Word Process (computing) Computer animation Personal digital assistant Query language Normal (geometry) Right angle Object (grammar) Table (information) Row (database)
that the the the the good and the bad so alright after everybody How was lunch then Austin also so this is the junior developer track and so I'm kind of curious going into this what people's backgrounds are so how many of you came to rails from some kind of boot camp the OK are how long was that we 8 weeks 6 weeks 12 weeks 6 months 7 months that's a long time that's a degree how many people have registered traditional CS CS degree the mechanical and then how many of you are just kind of learning by doing things watching in the stuff like that yeah well that's just so you know that never changes i've been developing for a long time and Internet videos and just trying things is pretty much the way you have to roll so
behind almost every rails and almost every AP in general is a powerful language called SQL and I got this the idea for this talk when I was working with the junior developer who was trying to build a a dashboard page and try to give some stats on user activity he was using the tools that are built in to Ruby because that's that's what he knew how to use and problem with that is that when you put that code production all of a sudden instead of downloading the couple of hundred a couple dozen rows that you have in your development system and doing some calculations on that now you're asking Ruby to pull down millions of rows in do calculations on that this is a situation where clearly the database is the right place to be doing the heavy lifting and so when we start appearing on this he explained the problem and I just immediately jumped into a a sequel prompt and started writing a sequel query that gave the answers that we were looking for on the dashboard in the thing that he said to me and this is a key word for me wait how did you do that and I found over and over again as I've worked with other developers that any time I say the words weight on and you do that I'm about to learn something and so that was a learning moment for for both of us I learned that you know not everyone has the sequel background in he learned a lot about tools that are available behind the scenes so we spend the whole hour writing a sequel queries and so you know I think we've we we both came away from that learning a few things so out sequel to put it another way the is the hero that rails deserves something we should provide out the way right up
front is it SQL is its equal I go back and forth between both of them it doesn't really matter it's not like we're talking about chips here of SQL is officially the correct way but if you were saying sequel and you know captain actually says well actually it's it's SQL that's so we find you can pull out the fact that it used to be sequel and they changed it when they made the standard just because of some trademark disputes or something with an airline or something like that so it's officially SQL but I say I say both ways right so to their talk a little bit about the the backstory of sequel we're gonna look at some of the wonderful examples in and talk about where you can go from here a little bit about me my
name is ryan delivers but I did not seize through my name there it's actually pronounce that way to lose anyone else you're Polish alright we will find some barbecue Parodi after this incident I've been programming for about 20 years and 15 of those professionally I live in Cincinnati Ohio with my family there are you can find me on Twitter I'm at Lebowski so don't need to tell you my favorite movie I'm a console which pretty much means I can say yes to things before actually know how to do them learning as you go is a skill that you'll learn as a developer and a recently I have started of working as an instructor for Girl Develop it which is an organization that helps adult women and get launched into technology careers so that's something that's interesting to you talk to me afterward and you have to talk about it right so the
world before a warrants all ems that's the the all encompassing term for things like Active Record so in the late nineties we were building web applications but we were using these these tools like Active Record we were just putting the the the SQL directly in line with our code we're using pyrrole we were using cold fusion so we were using um PHP pitch those in use today of the structure PHP px is a lot better today than it used to be and of we we would just put these the sequel Strings right there in line in the code and it got messy in it was complicated in it was frustrating so let me give you an example of
that say we have an application and we wanted to display a list of all the people that are in our system so we would have some SQL that we would write like this very basic query select the name and some other parameters from are people to OK that's that's great so we've got the query and now we have to execute that query against the database and when we do that we're going to get back a bunch of data collected into an array of arrays so you have a big array in each element of the array is 1 role from your database the OK well we got the data but now to use it and application in our kind of object-oriented way we need to collect we need to build those of people and then we need to collect them into a in a rate in our language so will iterate through each roll of the results there will create a new person and then for every single element of data that came back from our query we need to just manually assigned it into the different attributes that are object task and then we have to consider like you see on the last line here things like well in the database it's stored as a 0 or 1 but are object knows about Booleans and so we need to translate that you have to think about all those kinds of little gotchas there and then finally will show that person onto our array of people rinse and repeat but now you have to do the same sort of thing for every single interaction with the database your application hence begins very monotonous it's very error prone and the code is very fragile I mean if you look at it that code there if you can imagine if you change something with the structure of that query it's very easy to break that nothing the the so as a developer I think we all at least I do but I think we all had this proclivity to avoid repetitive tasks and if we see something we have to type would do more than once we try to find a way to automated software and so now is the time where
I admit to something that is hilariously dangerous and naive the 1st application I was ever paid to build on again this is a late nineties it was a PHP at the end it was you know the standard now see MSC type of application Small Business out written in PHP and a lot of forms look like this we have an HTML form we collect a few fields and we submit it but take a look at the top line there where at submitting to its submitting to something called say data . php doesn't seem very specific it doesn't have to be because my fear of getting around the problem was I passed in a Hidden Field called table name and that on the back I went ahead and just took the table name and dynamically build a sequel query to insert data into the database update data to lead data whatever needed to be done this is a very very unsafe if you don't understand why this is unsafe may I suggest you attend some of the application security of course is the of later on this week I think you'll find very interesting my solution to the problem was you know please don't have any of consonant now this was behind an admin interface and stuff so I guess you could kind of justify it like that but really this this is no way this is no way to code so
that's sort of a little bit to the mid 2 thousands and orange are starting to become popular so in the job space we had hibernate in of O jb Indian rails we have active record so with active record you know you take this giant mess code that's that's here and you replace it with a 1 line that's
great so if active record can replace all that why should I bother to learn SQL 1 reason is because as you always everywhere see polite which is the database that ships with rails for is the most of it if not top 5 and most popular widely installed piece of software in the world super light is installed on every entry from every iPhone every Mac everyone those 10 PC every flavor of Linux Chrome Safari Firefox it's in a bunch of cars in airplanes it's literally everywhere right but so what you can still talk to it with Active Record and tools why do you need to learn to seek it's because all Iran's come and go I probably use 3 or 4 different ones they all have a different API it changes every time and when she finally learned how to do something beyond the basics you're looking it up in the documentation in order get to retain any of that so 3 to 4 years from now maybe you're using a different language in a different or well you're not going to be of use all those things you learned about with Active Record there's going to be different on structures there's going to be different Duchess this can be different things at all if you do this and Hibernate everything goes very badly if you do it in Active it's fine but the thing about sequel is that it's pretty much always the same so actually come and go frameworks databases to sequel will live on if you think this poem is incredibly cheesy you can thank Chris Nelson of my friend back in the Cincinnati user groups and he is at super crisply Sweden and tell him how home greatest his poetry is you do have to pronounce equal the unofficial way to make the the syllable count work out for the haiku there no so the real
point of all of this is that you want to learn the native language wherever you are Richard had is the creator of see polite he was on a podcast recently started talking about being at forest and the the thing that he said that really struck me was as a tourist I can get around by pointing at things and I can pick up a few keywords and I can communicate roughly with the people that are there but unless I know the language I can't start a business I can't really succeed on a personal level with people and have have good relationships I have to learn that native language in so by learning SQL which is the native language of any database that's going to help you transition from being a junior tossed programmer to someone who is a seasoned pro who knows when it's the right tool for the job so that's the main point today will look at a couple
examples Norton to do this we need to create a few things of basic schema we will create authors and books I will do this stuff Active record because Active Record is great for this kind of thing and so we have an author which has many books we have a book which belongs to the and then here's the migration seat in Tennessee the fields we've got obviously an incomplete list from which you have been in a real application but for authors we have a name a country in a and a birthday and then for books we've got titles pages a publication date topics and and I see a number and most importantly an author ID so this is how inside the relation of the database of the authors of the books a tied back to the corresponding authors the so say here on a new
project or maybe it's an existing projects and your your boss your client wants some more information about the data that you have maybe they wanna know how many books you have OK the obviously very simple there's the SQL for that and likewise there's the of very simple Active Record call that you would use to get the same thing How many authors we have the the same thing simple select the count of 4 of ideas from the authors stable In in Active Record you just to offer got out OK so
let's look at how we would take this into our database so if you were at the terminal you would type this depends on your database but if you using post-stressed which I I would suggest you do post process very database but almost all of them have a command line tool like this we would launch it against our database and then were dumped into yet another part where we can type things they're commands directly issued to the database and so we will type in a query and we'll get our results and so we've got 4 thousand books likewise will do the same thing on our authors will typing and are a single query and we'll find out we've
got 500 of those OK that's all very basic but we need to get more In in-depth here we could've done all that was just Active Record so how many books do we have in each topic OK that's getting more interesting we need to use as a tool that we haven't used yeah that's called group by so will select our topic in the count of those topics from my books and it will group but all together by topic and so what this is going to give us is a set of results of that just includes 1 line for each of the topics that are in a database an account of all the books that go along with that topic xi makes sense everyone the you could also do that Active record of course it's still simple but these remember are very simple cases as you get more complicated with the use of these queries and like the 1 we're gonna do in just a minute by the time you figure out how to write the Active Record code to make this stuff happened might as well have just done directly in the database the so let's look at something a little more
complicated so it's ask how many books that we have in each topic and let's find the minimum maximum and mean page count by topic OK we I don't know how to do that act record you might have to inline some SQL ability that so will start off with a single query select topic the count of the topic and will give it a of a familiar name forest using that as the word and then will select the minimum pages this is using minimal which is a function that our database provides to us the database provides lots and lots of these kinds of Hindi functions that you can use to do things like minimums maximums an averages standard deviations and all sorts of of statistical functions and other calculations summations so there they're matched pages and then we'll get our average pages and well rounded off to 2 decimal places so that you know that so it looks reasonable and you'll get from our books in will group that by topic again and when we look at our results you'll see that we've got our topics are topic counts the number of books for each topic and then we've got the calculations that we did on the pages that are in our books now I have to calculate number of pages in books probably not be probably had users hitting your systems and you're probably tracking events that those users are creating or your tracking and you know the number of flights a user gives to some thing and so my country 1 day and say what he can you give me some basic statistics on this stuff and that stuff might be scattered into a bunch of different tables that you need to to join together and use these functions and let the database to do the work for you rather than trying to hold all of that data into your Rails app and do the work in Ruby because again you might be dealing with millions and millions of rows here and it's not feasible feasible pull all that the endowment so it's like a little bit about how would join data
together so how can we answer the question which authors have written 5 or more books on a given topic that's an interesting business question His you might want to contact those authors and say 0 hey you you're really on the ball cranking out these review books you know do you want to come talk at a review conference or something like that that's an interesting business question that's where you're gonna have to combine different data together and this is the sort of thing that's a lot easier to explore and do directly within sequel than it is to do with in rails so the quickly explain joints for those who are unfamiliar if you have authors over here in books over here adjoining combines those 2 tables together based on some criteria and in our example the criteria is that the author has an ID the book has an offer IDE in it and if those fields are equal then that's how we know that those records should be linked together that's the essence of the joint OK so how
do we realize this in SQL so we have the author's name the topic account of the books because remember we need to figure out how many books has this author cranked up we're gonna select from the authors table and then we need to join its to the books table and that's how we specify a joint criteria there's we're gonna say we're gonna select this stuff from the authors table joined together with the books table based on this criterion and then will group these things by the author's name and then the topic so the same group by concept we had before but now we're just extending it a little bit and of using 2 different criteria to different fields In that joined the the and then will say what we want to find just the authors who have written more than 4 books 5 or more there before more but is the fiber wars were looking for so they use greater than 4 having is the same as the where clause which I'm sure you're familiar with it in a in a very basic query select the user where I equals wall right so having clause is the exact same thing as aware only it applies to be things that are grouped together so since the authors that our our what's being aggregated here we're going to be at calculating that really using that the having thoughts to to limit our results that all of the total number of books for each of those authors and there we get the data so all of the you know 500 authors that we have in our in our test data here we only have a handful of them who have written more than 4 books and there's the topics that they've written things on unfortunately Ruby didn't show up NORAD rails but that is the nature of randomness on the test data did not have that many authors writing Ruby on Rails books from at least multiple books back-to-back so that's pretty cool and obviously you can take that query and you can build it from there you can take these queries in you can ask them together so you can take the results of 1 and then apply it to the search criteria that another call another queries using we could have joined in another table here say it's a table of sales data so instead of just asking how many authors have written 5 or more books on a given topic how many authors have written 5 or more books on a given topic and have sold more than a thousand copies of each of those books those are the kind of questions that you can answer and by understanding how to write SQL you can very easily come up with those kinds of those kind of things on the fly the so on
joining data is it's obviously a the thing here they do a lot of we just covered a very basic join they're the kind where you have just the records that match up you'll see that there's a lot of other types of joins when I can get into all the details of those but I'm suffice it to say there are ways to say well give me everything that just matches and then there's other ways to say things like OK will give me everything that matches the clause everything over here that doesn't so maybe some of the authors don't have books with specific topics that you're looking for but also include those authors if you wanted to things like that and that's all a matter of the syntax and the different roles that you applied in city query OK so let's talk a little
bit about the tool called explain aside from doing like ad hoc searches in your database and exploring data the other reason you might want to have some knowledge of how the database is working behind the scenes is that you can figure out why your app is so slow I'm sure we've all run into a situation where you work on something it works great on your laptop and then you deploy to production and it's not so great it's very slow under laptops fine because for 1 you probably have a necessity so that super fast compared to the spinning disk that might be a new database server and to have their day on your laptop you might have a hundred Rosen on the production database you made of 100 thousand that's a totally different ball game when it comes to the searching through things in the database so explain is a tool that will let you understand how is the database trying to find this information what's its plant the and it's really easy to run explain on literally aquarium all you have to do is take a query that you want test and stick the word explain in front of optionally on some databases you can write explained analyzed in that will go the extra step of actually executing the query in giving you a little bit more information on well explain told me what I think I'm going to do is the database this is my plan for how I'm gonna find this data and this is how I think it's going to go explain analyzes here's my plan and then I actually execute my point this is what really happened so I tend to to use the the analyzes because it gives you some more interesting information and what you get from explained is output that looks like this which is extremely dense and I do not expect you to walk out of your understanding how to read except for 1 key word or 2 key words I guess the the sequential scan anywhere using sequential scan in and explain from your database that's probably a bad and you want to avoid at all costs the sequential scan Our sees a sequential scan basically means the database has to look through every single role in the database 1 by 1 and see if it finds what you've told to look for that's very slow that's as if you were trying to find out all of the words rails in a given text if you were trying to do that in real life how would you do it you would use the index in the back of the book and if you had the index you could say all look rails as mentioned on you know pages x y and z the database needs the same kind of thing you can add an index very easily to your database and that will help to resolve these issues where you have a sequential scan now there's definitely a works to creating indexes that matter and indexes that improve performance and we can't get into the details of those today but suffice it to say the 1st step in all of this is running explain on queries the slow or any queries for that matter in your database and just looking for those keywords things like sequential scan who that that's that's a hot spot there I probably want to looked into adding an index on that even if it's not slow on my development laptop rails will dump the output and it will dump the actual cycle that's been run into the development logs when you're using your application in development so you can just go into your log files and any time you see the word select you can go ahead and copy that stick it into your database Council word explain on the front of it and check out the output the it's a great way to learn more about how the database works honestly because you can kind of get into the database is head of like how are you gonna find this information the so In short rights everything
so you might have noticed that I didn't include any mention of how do I directly call sequel from my Rails application and that's because it's dangerous you can definitely do that and you will do that but to get up here and say well this is how you do it and how you do it safely in a you know 30 seconds that were on a slide would be I'm a little bits of reckless I think any responsible because there's a lot of the there there's a lot of gifts and edge cases there that you could end up and causing problems with and I would want to lead you in a direction but the if you're doing reporting type words we're not using data that provided by the user that's probably fine you can use that in your and if you do need to in incorporates some user data like say you want to do a geographic search so you want to find all of the coffee shops that a nearby certain location and you decided to implement this query using wrong well that's fine but make sure that your sanitizing those inputs for you stick it into your course you don't want a end up
like a school where little body tables when Monday's phone call says hey a sensible or handsome computer problems I did you in near Sun Moon rubber quote so my Coleman best s drop tables of yeah we call little body tables so that's why I have sometimes user input you never know little body tables can enroll in a school and start using the application so where do we go from here the
there's obviously a lot to this sequel stuff if you don't have a book on your desk at work or at home of that is about databases and SQL you should absolutely report so those are that's not a list of recommendations or anything that is just there are a single books out there and they are ranked by reviews pick 1 you will be able to keep it for a very long time because he doesn't change that much there is also gonna be good documentation for your specific database where you can learn about things like the aggregation functions and like geographic extensions and things like that it might be specific to your particular database and usually the doctor pretty good for those posters has very documentation remote parents not necessarily remote pairing pairing in general it is I think the best way for a junior developer to level up quickly working side by side even with other junior developers working together trying to solve a problem especially if you're working side-by-side with someone more senior than is a fantastic way to learn very quickly things that might not necessarily pick up in a book because most likely you're going to working on a real production system with real production problems and they are going to be demonstrations of 2 tables with you know 5 attributes in each 1 it's going to be real data real problems in real systems and that's when you are so absolutely pair program as much as you can and if you don't have an opportunity to do that there are a lot of a lot of places where you can do that online and and in remotely pair with people on things like screen hero and stuff like that on and just because I want to squeeze in 1 more just out here is a reminder should scour your logs for database queries to understand what they do run explain on them and figure out how the of your application is really working binds States so take takeaways the
main 1 is to learn the native language whether you're talking about travel or programming it's very helpful to know and speak the native language of the database understand what Active Record is doing for you behind the scenes and by all means pick the right tool for the job I Use active record all the time it is a great tool but I know when to jump in and just use the database directly and just because you have an already does not mean that it's wrong or bad to use equal directly you have a lot of tools and you just need to know what they're good at what they're not good at and went to pick up of the 1 4 0 for the job you have at hand so thank you very much and if you have any
questions they haven't taken we have a couple minutes the and b the the yes it would be possible my my recommendation is you don't do it without knowing what you're doing of the unique executing Ross equal from within your else not I hope that the there's a few different ways to do it at basically the 1 we can do it is you can get a connection the from the from the Active Record connection-based you can get a connection you can execute Ross equal that's very helpful if you're using it inside of of migration saying you need to create a geography type of column in a PostgreSQL database if if rails doesn't know how to create a geography column can can't use the normal schema migration stuff and you might need execute sequel directly so that's a 101 use of connection execute but and the other time you might wanna do it or the other way you might wanna do it is using find biased you well which is a method on your mark this is the 1 where you need to be very careful indeed be careful anyway that you need to be careful that you are just you know throwing user data acts of this thing but the nice thing about using find by SQL is that it will automatically instantiate objects for you that are of the type that you call the bond so if you have authors in you said orthodox find biased you well you provided it with a query then you will get back Author objects and they will have for any parameters are that you didn't specify or that are really parameters on your model from naturally things you might have created in your query by hand there some of our out of columns and stuff those will come back as virtual at tributes attached to your model and so you can just make the calls directly on and just like any other actually on my so any other questions we and a lot more about what the well I don't have a specific example for that for when Table rewriter a necessary right well case you have a migration like that we need to be careful at the Annapolis take your act but a good example of a migration that you could add so directly with SQL would be if in i in contrast you can create indexes comfort but at least as of recently like yields and 5 but you couldn't just do that as part of normal migration and so you need to kind of create your arm your migration by hand you need to say OK I'm going to create this indexing you would use all the same things that that rails is going to do for you when it's treating you next but you get the tackle 1 keyword onto the query that says create index concurrently and then the rest of the the the the parameters and so the went back executes instead of the rails generated SQL to create the index it will use the string you provided and it will allow you to create art and index on a table that doesn't block access to the table like the normal non-concurrent create and excess so that's when 1 example of what you might use it in a migration Our goes to the last 1 that the so it's not necessarily faster the question is is it faster to write the SQL on directly it's not necessarily fast and you can observe this when you're looking at how your application operates all of those things you ask Active Record to do translate directly into of SQL queries that get executed against the database and it's usually Active record does the right thing and there are some times when you might find a better way to skin a cat and for lack of better word our and that's when you might wanna in use wrong SQL but typically Active Record does the right thing there the key is to just look at what Active Record is doing and try to learn from are it things like thank you and I and I and my my