Reading record in PHP: scan vs. single record read vs. query

scan

#1
Hi
I'm sorry for my english and i new for this db.
I want see a record from aerospike through php.

In aql write:
select * from jubecca.prodotti
+-------------+----------+
|  name       | cpu      |             
+-------------+----------+
| "fx-6350"   | 1        |
| "I7"        | 2        |
+------------+-----------+
I expect "fx-6350" 

<?php
...
...
$key = $db->initKey("jubecca","prodotti");
$status = $db->get($key, $record, ["name","cpu"]);
if ($status == Aerospike::ERR_RECORD_NOT_FOUND) { var_dump($record); }
..
..
?>

Not work for me...sure something I do wrong, some guy can help me for make right code?
Thank you!!

#2

Hi. A key requires three components - the namespace, the set, and its primary key in the application. In your code sample initKey() is missing that third argument.

The equivalent of select * from jubecca.prodotti where PK='fx-6350' (assuming the primary key is that value) is

$key = $db->initKey('jubecca','prodotti','fx-6350');

If what you want is a scan , the equivalent of the AQL select * from jubecca.prodotti is

$status = $db->scan("jubecca", "prodotti", function ($record) {
    var_dump($record);
}, ["name", "cpu"]);

#3

Thank you so much!! For make only ‘fx-6350’ output: echo $record [‘bins’][‘name’], right? I need search inside db with relation(or similar relation) for example:

Product_xxx { … “available_in_stores”: [“Store_1”, “Store_55”, “…”] }

Store_xxx { … “products”: [“Product_44”, “Product_19”, “Product_1994”, “…”] }

The problem is the speed, because with scan 68ms for search “fx-6350” and the db is empty, only just this record( jubecca.prodotti bin name and bin cpu with only one tuple) If I make this fake relation you think is possible reduce the time? If yes, how?

Thank you for your patience!!


#4

Scans are definitely going to be slower than single record reads or even queries. Scans on very small sets seem especially slow because there’s the overhead of finding all the records of a set as those are split across 4096 logical partitions. It’s less noticeable in sets with more records. In the upcoming version of the server (3.6) you’ll be able to configure it for more parallelism by dedicating more threads to scans. This is will be similar to how you can set the number of threads for transactions.

Anyway, for your case it makes more sense to build a secondary index on the bin you want to search, and use actual queries. There’s more information in the quick guide.


#5

Thank you for answer me! I really appreciate.


#6

@mdwalter

Ciao Marco,

We just released Aerospike 3.6.0, which features a number of scan improvements, such as the ability to run concurrent scan jobs, plus many other features and fixes. You can read more about it on our Aerospike Server CE 3.6.0 release notes and dowload it here.