Articles tagged with sql

  1. MySQL Multiple-Column Indexes: Order Matters

    Posted on in Programming

    Powered By MySQLThis will just be a short reminder. If you're planning to create multiple-column indexes in MySQL, remember that the order of the columns matters. As the MySQL documentation points out, any "leftmost prefix of the index can be used." This means that the index can be used for any number …

  2. MySQL: Query caused different errors on master and slave

    Posted on in System Administration

    We ran across the following error on a MySQL slave server recent:

    mysql> SHOW SLAVE STATUS \G
    <snip>
    Last_Error: Query caused different errors on master and slave. Error on master: 'Deadlock found when trying to get lock; try restarting transaction' (1213), Error on slave: 'no error' (0). Default database: '<database_name …
  3. Listing WordPress Database Queries

    Posted on in Programming

    WordPress Horizontal Logo If you need to debug what queries your WordPress site is making, try adding the following PHP to your theme:

    <?php
      foreach ( $wpdb->queries as $query ) {
        echo "$query[0]<br />";
      }
    ?>
    

    For this code to work, you need to add the following line to wp-config.php:

    define('SAVEQUERIES', true);
    

    After that …

  4. Two Random Asterisk-Related SQL Queries

    Posted on in voice

    I hate losing useful SQL queries, so I tend to save them. Ever so often, I stumble across a file of queries from some work I was doing months ago. The following two queries are just such a case. I was analyzing some call data for a call center that …

  5. ActiveRecord and SELECT DISTINCT

    Posted on in Programming

    Blue Cup 1 (photo by woodsy)I'm writing this post for two reasons:

    1. For some reason, I couldn't find a lot of information on ActiveRecord and SELECT DISTINCT().
    2. I'm hoping some Ruby / ActiveRecord guru will stumble across this and provide a better solution.

    Recently, I was working on a project written in Ruby with ActiveRecord that …

  6. Logging Active Record Queries to a File

    Posted on in Programming

    Grapefruit Glory (photo by AnnaMaciel)I was recently helping a developer with some SQL optimizations in Ruby. The developer was using Active Record, and (until now) my Active Record experience has been pretty minimal.

    One thing that was really driving me bonkers was how to get Active Record to print out the queries it was …

Slaptijack's Koding Kraken