title: Why does this MySQL Query hang?
body: <pre><code>SELECT *
  FROM tbl_order_head AS o
  INNER JOIN tbl_orders_log AS c
  ON o.PAYMENT_TRANSACTION_LOG_ID=c.TRANSACTION_ID
  WHERE o.VISUAL_ID = '77783';
  </code></pre>
  
  <p>tbl_order_head 67,000 (30 fields) records, tbl_orders_log 17000  (5 fields) records. I don't know if it would eventually return as I am running it on a live server and fear overloading.</p>
  
  <p>I am doing similar queries and much more complex queries successfully.</p>
  
  <p>tbl_orders_log</p>
  
  <pre><code>Field Type Comment
  ID bigint(20) NOT NULL
  TRANSACTION_ID varchar(1000) NULL
  CREATED datetime NULL
  AMENDED datetime NULL
  PAYMENT_CARD_NUMBER varchar(255) NULL
  PAYMENT_CARD_TYPE varchar(255) NULL
  SESSION_ID varchar(255) NULL
  TRANSACTION_TYPE varchar(255) NULL
  TRANSACTION_VALUE varchar(255) NULL
  LOG_DATA text NULL
  </code></pre>
  
  <p>Index Information</p>
  
  <pre><code>Indexes Columns Index_Type
  PRIMARY ID Unique
  </code></pre>
  
  <p>tbl_order_head</p>
  
  <pre><code>CREATE TABLE `tbl_order_head` (
    `ID` varchar(255) NOT NULL,
    `VISUAL_ID` decimal(20,0) DEFAULT NULL,
    `CREATED` datetime DEFAULT NULL,
    `AMENDED` datetime DEFAULT NULL,
    `CUSTOMER_ID` varchar(255) DEFAULT NULL,
    `BILLING_ID` varchar(255) DEFAULT NULL,
    `ORDER_LINES_ITEM_VALUE` varchar(20) DEFAULT NULL,
    `DELIVERY_VALUE` varchar(20) DEFAULT NULL,
    `ORDER_LINES_ITEM_TAX` varchar(20) DEFAULT NULL,
    `DELIVERY_TAX` varchar(20) DEFAULT NULL,
    `DELIVERY_ALLOCATED_ITEMS_VALUE` varchar(20) DEFAULT NULL,
    `DELIVERY_ALLOCATED_ITEMS_TAX` varchar(20) DEFAULT NULL,
    `DELIVERY_ALLOCATED_ITEMS_TAX_DEDUCTION` varchar(20) DEFAULT NULL,
    `DELIVERY_TAX_DEDUCTION` varchar(20) DEFAULT NULL,
    `LOYALTY_CARD_POINTS_EARNED` varchar(10) DEFAULT NULL,
    `LOYALTY_CARD_POINTS_REDEEMED` varchar(10) DEFAULT NULL,
    `LOYALTY_CARD_POINTS_REDEEMED_VALUE` varchar(20) DEFAULT NULL,
    `VOUCHER_CODE` varchar(50) DEFAULT NULL,
    `AFFILIATE_CODE` varchar(50) DEFAULT NULL,
    `LOYALTY_CARD_NUMBER` varchar(209) DEFAULT NULL,
    `REDEEM_LOYALTY_CARD_POINTS` varchar(1) DEFAULT NULL,
    `SOURCE` varchar(50) DEFAULT NULL,
    `SKU_DATA` text,
    `SKU_TAX_DATA` text,
    `DISCOUNT_DATA` text,
    `PAYMENT_CARD_TYPE` varchar(6) DEFAULT NULL,
    `PAYMENT_CARD_NUMBER` varchar(255) DEFAULT NULL,
    `PAYMENT_CARD_START_MONTH` varchar(6) DEFAULT NULL,
    `PAYMENT_CARD_EXPIRY_MONTH` varchar(6) DEFAULT NULL,
    `PAYMENT_CARD_START_YEAR` varchar(6) DEFAULT NULL,
    `PAYMENT_CARD_EXPIRY_YEAR` varchar(6) DEFAULT NULL,
    `PAYMENT_CARD_ISSUE_NUMBER` varchar(3) DEFAULT NULL,
    `PAYMENT_CARD_SECURITY_NUMBER` varchar(4) DEFAULT NULL,
    `PAYMENT_CARD_NAME` varchar(50) DEFAULT NULL,
    `PAYMENT_CARD_SAVE` varchar(1) DEFAULT NULL,
    `PAYMENT_CARD_CHARGE_AMOUNT` varchar(10) DEFAULT NULL,
    `SAVED_PAYMENT_CARD_ID` varchar(255) DEFAULT NULL,
    `SAVED_PAYMENT_CARD_SECURITY_NUMBER` varchar(255) DEFAULT NULL,
    `GIFT_VOUCHER_DATA` text,
    `GIFT_VOUCHER_APPLIED_VALUE` varchar(10) DEFAULT NULL,
    `LOYALTY_EARNED_SKU_DATA` text,
    `LOYALTY_REDEMPTION_SKU_DATA` text,
    `LOYALTY_REDEMPTION_DEDUCTED_SKU_DATA` text,
    `PAYMENT_CARD_AUTH_CODE` varchar(10) DEFAULT NULL,
    `PAYMENT_TRANSACTION_LOG_ID` text,
    `CREATED_BY` varchar(20) DEFAULT NULL,
    `BASKET_ID` varchar(255) DEFAULT NULL,
    `SKU_DESCRIPTION_XREF` text,
    `IP_TRANSACTION_NUMBER` varchar(255) DEFAULT NULL,
    `MEMS_BESPOKE_DISCOUNT_DATA` text,
    `IP_EXPORTED` varchar(255) DEFAULT NULL,
    PRIMARY KEY (`ID`),
    KEY `CUSTOMER_ID` (`CUSTOMER_ID`,`CREATED`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  </code></pre>
  
  <p>Hi I have (with help)
  rewritten the query</p>
  
  <pre><code>SELECT * FROM tbl_orders_log WHERE TRANSACTION_ID=(SELECT o.PAYMENT_TRANSACTION_LOG_ID FROM tbl_order_head AS o WHERE  o.VISUAL_ID = '77783');
  </code></pre>
  
  <p>which executes instantly</p>