How make JOIN table in ClickHouse DB faster?

Oleg Khamov picture Oleg Khamov · Nov 2, 2016 · Viewed 9.4k times · Source

I have two tables

event

  • id
  • os

params

  • id
  • sx
  • sy

This table have relation 1-1 by id. If execute query

select count(*)
from
(select id from event where os like 'Android%')
inner join
(select id from params where sx >= 1024)
using id

they very slow

But if all data contains in one table

select count(*) from event where sx >= 1024 and os like 'Android%'

Query executed very fast.

Please, tell me how use join in ClickHouse DB effective? Keep all data in one table is not convenient.

Answer

uYSIZfoz picture uYSIZfoz · Nov 3, 2016

You may rewrite query like this:

select count(*)
from event 
where os like 'Android%' 
AND id IN (select id from params where sx >= 1024)