Commit Graph

30 Commits

Author SHA1 Message Date
Tomasz Grabiec
4c418ddef8 types: Use enum rather than bool in tuple_type template parameter
The 'bool' type doesn't hold any meaning on its own, which makes the
template instantiation sites not very readable:

  tuple_type<true>

To improve that, we can introduce an enum class which is meaningful in
every context:

  tuple_type<allow_prefixes::yes>
2015-04-16 14:57:21 +03:00
Tomasz Grabiec
3bb23c5aff types: Convert tuple_type to use uint16_t for length component
Origin is using CompositeType to serialize composite keys and that
type is using 16-bit integer to encode the length. If it's enough for
Origin, it's enough for us.
2015-04-16 11:49:26 +03:00
Avi Kivity
e9774fe1e1 db: adjust lexicographical_tri_compare to take a bounded type list
When comparing tuples, we don't want to overrun the type list.
2015-04-10 22:26:41 +03:00
Tomasz Grabiec
ef52bb6048 type: Remove unused code 2015-03-26 10:46:53 +01:00
Tomasz Grabiec
ec867fb93d type: Fix _is_byte_order_comparable calculation
Because the length preceeds component contents, serialized tuples are
not byte order comparable. It breaks lexi ordering. It should be that
"abc" < "b", but with length prefix "<3>abc" is greater than
"<1>b". Only single element tuples can be byte order capared because
they have no length component.

Spotted during code review.
2015-03-26 10:22:13 +01:00
Tomasz Grabiec
7a6dd463dd types: Optimize serialization of single-element tuples
There are two sides of this optimization:

 1) We don't store the length of the last component, so the
    representation is now shorter.

 2) A single-element tuple is serialized exactly as the component it
    holds, which allows us to optimize conversions for such keys.
2015-03-26 10:21:48 +01:00
Tomasz Grabiec
49b7a166a8 keys: Make key components non-optional 2015-03-19 14:54:41 +01:00
Tomasz Grabiec
300a9572bd types: De-virtualize tuple_type
tuple_type is for managing our internal representation of keys. It
shares some interface with abstract_type, but the latter is a basis
for types of data stored in cells. tuple_type does not need to hide
behind a virtual interface.

Note: there is a TupleType in Origin, but it serves a different purpose.
2015-03-19 12:55:28 +01:00
Tomasz Grabiec
9d1fe2c8d9 types: Rename tuple_type::component_iterator to 'iterator' 2015-03-17 15:56:29 +01:00
Tomasz Grabiec
1b1af8cdfd db: Introduce types to hold keys
Holding keys and their prefixes as "bytes" is error prone. It's easy
to mix them up (or use wrong types). This change adds wrappers for
keys with accessors which are meant to make misuses as difficult as
possible.

Prefix and full keys are now distinguished. Places which assumed that
the representation is the same (it currently is) were changed not to
do so. This will allow us to introduce more compact storage for non-prefix
keys.
2015-03-17 15:56:29 +01:00
Dor Laor
7921ef406a db: serialize via bytes_iterator instead of std::ostream
Instead of using inefficient std::ostream, use our own 'bytes' iterator class.
Compute ahead of time the length of the byte buffer.
Afterwards serialize the objects into it.

Gives ~X5 boost over previus results (that sometimes don't even
finish in reasonable time)

[avi: add missing include]
2015-03-16 07:07:25 +02:00
Dor Laor
29c21f1eda db: move tiny write util template to serialization.hh 2015-03-16 06:58:23 +02:00
Tomasz Grabiec
b9d6cbeb3b types: Introduce tuple_type::is_full()
For checking if prefix is in fact a full tuple.
2015-03-11 16:01:13 +01:00
Tomasz Grabiec
4c7480ce3b cql3: Introduce to_identifier(column_definition&) 2015-03-11 14:56:09 +01:00
Tomasz Grabiec
124ec33a4a types: Fix tuple_type::compare() for missing values 2015-03-10 10:16:55 +02:00
Tomasz Grabiec
e8d22e5598 tuple: Fix component iterator
The iterator prematurely compared equal with end().
2015-02-18 21:59:35 +02:00
Tomasz Grabiec
ad3ffd2e96 tuple: Remove internal deserialize_value() usages
deserialize_value() is slow because it involves multiple allocations
and copies. Internal operations such as compare() or hash() don't need
all that heavy transformations, now that those functions work on
bytes_view we can iterate over component values in-place.
2015-02-17 12:43:15 +02:00
Tomasz Grabiec
700799e965 types: Make deserialize() work on bytes_view 2015-02-17 12:43:15 +02:00
Tomasz Grabiec
54b9c637bd tuple: Convert is_prefix_of() to work on bytes_view 2015-02-17 12:43:15 +02:00
Tomasz Grabiec
6cde02cbc7 types: Make equal/hash/less work on bytes_view
The serialized value is not always a standalone "bytes" object, it can
be embedded in a larger chunk. It's much faster to work on the data
in-place.
2015-02-17 12:43:15 +02:00
Tomasz Grabiec
8721b2e900 tuple: Add missing copyright banner 2015-02-17 12:43:15 +02:00
Tomasz Grabiec
ebb8a11206 types: Add helper tuple_type::serialize_value_deep()
It works on fully deserialized values.
2015-02-12 19:40:59 +01:00
Tomasz Grabiec
63d152ece8 types: Introduce abstract_type::as_cql3_type()
Origin also has it.
2015-02-12 19:40:58 +01:00
Tomasz Grabiec
863d305a66 types: Make from_string() work on sstring_view 2015-02-12 19:40:58 +01:00
Tomasz Grabiec
138ed6faac tests: Add test for tuple_type::is_prefix_of() 2015-02-09 10:28:45 +01:00
Tomasz Grabiec
0a5bf555ea types: Introduce tuple_type::is_prefix_of() 2015-02-09 10:28:45 +01:00
Tomasz Grabiec
f1c9f64a25 types: Implement string conversions for int32_type and string_type 2015-02-09 10:28:44 +01:00
Tomasz Grabiec
92c95c6c81 types: Add tuple_type::decompose_value() shorthand method 2015-02-09 10:28:44 +01:00
Tomasz Grabiec
ed0500e1cd tuple: Remove dead code 2015-02-04 10:28:51 +01:00
Tomasz Grabiec
bf60d82dd0 types: Introduce tuple_type 2015-01-29 15:02:27 +01:00