.setPreservesAll();
    }
    virtual void print(raw_ostream &O, const Module *M) const {}

  };
}

char InstCount::ID = 0;
INITIALIZE_PASS(InstCount, "instcount",
                "Counts the various types of Instructions", false, true);

FunctionPass *llvm::createInstCountPass() { return new InstCount(); }

// InstCount::run - This is the main Analysis entry point for a
// function.
//
bool InstCount::runOnFunction(Function &F) {
  unsigned StartMemInsts =
    NumGetElementPtrInst + NumLoadInst + NumStoreInst + NumCallInst +
    NumInvokeInst + NumAllocaInst;
  visit(F);
  unsigned EndMemInsts =
    NumGetElementPtrInst + NumLoadInst + NumStoreInst + NumCallInst +
    NumInvokeInst + NumAllocaInst;
  TotalMemInst += EndMemInsts-StartMemInsts;
  return false;
}
Q: Como consultar dados de uma tabela usando INNER JOIN em uma subconsulta no PHP Possuo o seguinte SELECT para selecionar dados de uma tabela (chat) em um sistema de chat:
SELECT * FROM (SELECT * FROM chat WHERE id_chat = '$chat_id' ORDER BY id DESC LIMIT 10) S WHERE id_chat = '$chat_id' ORDER BY id ASC LIMIT 10

O mesmo faz a consulta retornando as últimas dez mensagens para exibi-las em forma decrescente.
Nessa tabela (chat), há uma coluna usuario onde a mesma representa o id do usuário que enviou a mensagem.
Gostaria de, a partir do id do usuário que enviou a mensagem, conseguir retornar os dados de tal usuário (tabela usuarios).
Exemplo da tabela usuarios:
id | nome  | foto
1  | Lucas | perfil.jpg

Qual a melhor maneira de se fazer isso utilizando a consulta acima? LEFT JOIN? INNER JOIN? E, como fazer?

A: Eu não sei exatamente qual a estrutura de tabela que você tem mas vamos supor que seja esta
tb_usuario
- id_usuario
- nome
- foto

tb_chat
- id_chat
- id_usuario
- tx_msg
- dt_envio

id_usuario sendo rigido e necessario
SELECT
    U.nome,
    U.foto,
    C.tx_msg,
    C.dt_envio
FROM
    tb_chat C
    INNER JOIN tb_usuario U ON U.id_usuario = C.id_usuario
WHERE
    id_chat = '{$id_chat}'
ORDER BY
    dt_envio DESC

O INNER ja restringe a QUERY a retornar apenas resultados que possuam id_usuario
Exemplo
- Lucas     |   perfil1.jpg     | teste msg  | 12/01/2016 08:20:14
- Rafael    |   perfil2.jpg     | teste msg2 | 12/01/2016 08:24:37

id_usuario nao sendo rigido
SELECT
    U.nome,
    U.foto,
    C.tx_msg,
    C.dt_envio
FROM
    tb_chat C
    LEFT JOIN tb_usuario U ON U.id_usuario = C.id_usuario
WHERE
    id_chat = '{$id_chat}'
ORDER BY
    dt_envio DESC

O LEFT diz para dar preferencia para o conteudo da esquerda no caso tb_chat, assim
caso não haja o vinculo com tb_usuario as colunas pertencentes a ele resebem NULL
Exemplo
-           |                   | teste msg  | 12/01/2016 08:20:14
- Rafael    |   perfil2.jpg     | teste msg2 | 12/01/2016 08:24:37

Nota


*

*Se você usar LEFT e id_usuario deve ser rigido, sera necessario polo no WHERE
WHERE
    id_chat = '{$id_chat}'
    AND id_usuario IS NOT NULL


A: Isso depende da view que você vai criar. No caso pode ser um INNER JOIN para a tabela chat. Contando que todos os chats tenham obrigatoriamente um usuário.
Segue um exemplo:
Select * 
From 'chat' 
INNER JOIN 'usuarios' ON 'chat'.$chave_estrangeira_do_id_entre_aspas = usuarios.id 
ORDER BY 'chat'.'id' ASC LIMIT 10

Se quiser mostrar mensagens sem usuários por exemplo não precisa de usuário para o chat nem nada, pode usar o left join.
*16th 57-60F, 14-16C, very windy, overcast with sunny periods. Rain and showers forecast all day. I was going to treat it as a rest day but with a gentle ride to avoid seizing up. The new saddle had branded itself into my undersides over the last week. So I swapped back to the Brooks after giving it a slight tension. With great relief! After three years of struggling the saddle is still the limit on my range.
The gear change cables have been getting creaky and stiff. It didn't help that I had used soft, low grade outers borrowed from an old bike. After oiling the cables I noticed that the cassette was moving an 1/8" to the side when I tried to change gear at a standstill! So I will have to strip the rear axles to find out where the play is. It won't do any harm to check the lubrication in the Trykit double freehub at the same time. The cassette is also filthy.
As I was calling this a sort of rest day I resolved to stay on the 34T chainwheel and keep the revs up. 133 rpm for a half mile felt a bit excessive. So the rest of the time I just kept twiddling freely above 95 rpm. I was still doing 15 mph + so it was hardly a dawdle.
It poured with rain at the halfway point when the saddle bag was already full and the sports bag was too. Remember to put the waterproofs on top next time! Yes, Chris. But it didn't look like rain! What sort of excuse is that? Only 16 fairly gentle miles.
The Trykit freehub still looked as good as new internally. I removed both journal bearings. Then ran a toothbrush through the ratchet teeth while well loaded with car engine cleaner. Much easier than trying to work with either bearing in place. The clicks were also given a good clean and appeared as new. Everything was carefully wiped dry with a clean cloth and thoroughly re-greased during re-assembly. I use a large Allen key as an axle substitute to ensure the clicks have been inserted the correct way round.
Only the outboard journal bearings on the axles showed signs of surface discolouration. Though they had been well greased externally on each assembly. To provide some protection. Rainwater is obviously able to get past the modified bearing cups around the exposed axles. Both bearings spun smoothly and well so were re-greased and returned to their support cups. Perhaps a short length of hose on each of the bare axles will help to keep the water out. The axles are a little large for ½", common or garden, hose.
Mr Higgins baulks at the Glavendrup stones approach avenue.
I also adjusted the inner, right side, bearing cup to take up the end play. Using an Allen key to set the prescribed 4mm between the bare, inner ends of the axles. Access is poor for adjusting the cup. So I used my usual technique of 90 degree offset circlip pliers on the adjustable cup. I checked carefully for just a little end shake to both axles. To avoid the bearings binding or wearing the freehub central spacer. The special Trykit double freehub still had just a little end float. Which does no harm. After replacing the wheels I spun them up via the drive train. They continued spinning for ages and stopped almost together. A good sign of very free running. After a good wipe down with clean rags Mr Higgins is ready for another day.
Two noisy hedgehogs by the pond.
18th 56F, 13C, westerly breeze, sunny. Rain forecast for this afternoon. I used the tailwind to go to Odense. Had a look at saddles in most of the bike shops there. The nearest saddle, to the one I bought recently, was the 'Avenue.' The Selle Royal looked quite promising being flat, wide and the padding relatively soft. As soon as I perched on one I quickly got off again