title: NoSQL & AdHoc Queries - Millions of Rows
body: <p>I currently run a MySQL-powered website where users promote advertisements and gain revenue every time someone completes one. We log every time someone views an ad ("impression"), every time a user clicks an add ("click"), and every time someone completes an ad ("lead").</p>
  
  <p>Since we get so much traffic, we have millions of records in each of these respective tables. We then have to query these tables to let users see how much they have earned, so we end up performing multiple queries on tables with millions and millions of rows multiple times in one request, hundreds of times concurrently.</p>
  
  <p>We're looking to move away from MySQL and to a key-value store or something along those lines. We need something that will let us store all these millions of rows, query them in milliseconds, and MOST IMPORTANTLY, use adhoc queries where we can query any single column, so we could do things like:</p>
  
  <p>FROM leads WHERE country = 'US' AND user_id = 501   (the NoSQL equivalent, obviously)</p>
  
  <p>FROM clicks WHERE ad_id = 1952 AND user_id = 200 AND country = 'GB'</p>
  
  <p>etc.</p>
  
  <p>Does anyone have any good suggestions? I was considering MongoDB or CouchDB but I'm not sure if they can handle querying millions of records multiple times a second and the type of adhoc queries we need.</p>
  
  <p>Thanks!</p>