title: performance issue while querying with comparison operator with limit on dynamodb
body: <p>I am querying a table which has both hash and range key. While querying, I am putting a limit on it but <code>limit</code> only restricts the number of returning items. As I understand, using comparison operators like <code>range_key__lt=12345</code> scans all items less then given range key and returns first n items of it which is specified by <code>limit</code> argument. In this case I have problem with query performance that I do not want it to scan all items less than range key. Does not exist there an index on range keys? It seems like it retrieves all items on bucket belongs to hash key. Then scans all items less than or greater than a value and returns some of it. I do not understand how filter/search mechanism works on range keys.</p>
  
  <p>Is not my question clear? I think it is a basic question related with databases or <code>dynamodb</code> specifically. I will try to explain it in detail. When we try to retrieve an item from database, without indices it created on a specific column it scans all rows and compare if it satisfies given condition. However, if there exist an index on this column like <code>B+ Tree</code> it will be too much faster to retrieve an item since it will find direct address of the row from index table. Now the problem is that, I have a table on <code>dynamodb</code> which has a <code>hash key</code> (type not matter) and a <code>range key</code> which is type of Number. My range key is actually timestamp and I will query such that row has nearest timestamp(date) to current time. Here I am querying like this. <code>r = test_table.query(hashkey__eq="abc", date__lt=1398099600, limit=1)</code> . In my table, nearly 1000 items has "abc" hash key. So I first go this bucket with this query and make a range key search on these 1000 items. I have  nearly 990 items which has timestamp value lower than <code>1398099600</code> . My query sentence above written in <code>python</code> using <code>boto</code> module. However, it works slow. I have also make same query on <code>aws console</code> and it tooks much time (There is no limit condition on aws console already so it retrieves all items lower than given timestamp normally). So, I open a log file in <code>DEBUG</code> mode using <code>logging</code> module in python. In this mode I can see how many rows did dynamodb server scan to get result. Then I saw that it scans all items has timestamp lower than given timestamp on <code>dynamodb server</code>. <code>limit=1</code> only restricts the number of rows will be returned to remote client, that is, it only sends first row of scanned rows to the client. Since it scans many rows, it gives <code>throughput provision</code> error also. </p>
  
  <p>Note: Instead using <code>less than</code>, if I use <code>between</code> comparator query runs faster. Hence, I can solve this problem using a datetime and an avarage lower limit and use between operator for query. But I don't know this is the proper solution.</p>
  
  <p>Question is that, is there a way to retrieve item with nearest date with more efficient way, instead retrieving all items less than an item?</p>