Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT DELAYED, wheres the equivelent for UPDATE?

Status
Not open for further replies.

BB101

Programmer
May 23, 2001
337
GB
I'm having fun doing a large scale UPDATE on a database table. I found I can do an INSERT DELAYED to do bulk inserts without blocking the apache thread, but there doesn't seem to be an equivelent for updating. Can anyone help?

Thanks

--BB
 
You could use LOW_PRIORITY instead:
[tt] UPDATE LOW_PRIORITY tbl SET ...[/tt]

You can also use LOW_PRIORITY for inserts if you wish. The difference between LOW_PRIORITY and DELAYED is that a DELAYED query returns to the client as soon as the inserts have been queued, regardless of the eventual outcome of the query, but LOW_PRIORITY queries return to the client only after the query has been executed.
 
I know this, I want my UPDATE to return immediately as soon as it is queued, is this possible?

--BB
 
I found a better way, only ever send a maximum of 100 things in the where clause!

I got it running in less than 0.5 seconds (an acceptable level for now).

snippet:
Code:
        $rs = $this->_db->GetAll("SELECT town_id FROM lk_user_town WHERE user_id = '".$uid."' AND active = 1");
        
        $sql = "UPDATE LOW_PRIORITY ref_town SET la = la - 1 WHERE 1=0 OR ";
        $x=0;
        foreach ($rs as $r) {
          $sql .= "id = ".$r['town_id']." OR ";
          if ($x++ % 100 == 99) {
            $sql = substr($sql, 0, -4);
            $this->_db->Run($sql);
            $sql = "UPDATE LOW_PRIORITY ref_town SET la = la - 1 WHERE 1=0 OR ";
          }
        }
        $sql = substr($sql, 0, -4);
        $this->_db->Run($sql);

Hope this helps someone!

--BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top