SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Are transactions faster?

    I know that database engines that support transactions tend to be slower than engines without support for transactions (e.g. innodb and myisam).

    But are transactions faster than separate queries?

    Example:

    I need to run 15 edit queries.

    Will it be faster if I just run them one by one or if I wrap them inside a transaction? My understanding of transactions is that the database gets queried only once with all queries inside the transaction and then it runs it one by one. So it should be faster or no?

    Thank you.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    the "database gets queried only once with all the queries inside" concept applies to stored procedures, not transactions

    transactions actually have the potential to be slower than the individual queries

    imagine seven classloads of grade 2 children trying to get into a movie theater -- what's faster, letting them all go in one after the other in any order, or trying to ensure that all the kids from the first class are inside before the first kid from the second class goes in, and all the kids from the second class are inside before the first kid from the third class goes in, and so on?

    transactions work in a similar way

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I lost you rudy after I imagined a riot

    Is your analogy for transactions that of the second half of your third sentence?

    bazz

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    letting them all go in in any order = no transactions

    making sure one entire class is inside before the next class can start going in = transactions

    which takes longer?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •