How to set max length for a String field in DynamoDB? - amazon-dynamodb

Can you constrain the max length of a string field?
The documentation describes only the internal limits for a field.
Strings are Unicode with UTF-8 binary encoding. The length of a string must be greater than zero and is constrained by the maximum DynamoDB item size limit of 400 KB.
The following additional constraints apply to primary key attributes that are defined as type string:
For a simple primary key, the maximum length of the first attribute value (the partition key) is 2048 bytes.
For a composite primary key, the maximum length of the second attribute value (the sort key) is 1024 bytes.

Unlike traditional RDBMS, DynamoDB does not have a notion of "maximal column size". The only limit is an item size limit, which is, as you've mentioned, 400 KB. That is a total limit, it inludes attribute name lenghts and attribute value lengths. I.e. the attribute names also counts towards the total size limit.
Read more in the docs.

Related

BLOB/TEXT column used in key specification without key length (1170)? [duplicate]

Entries in my table are uniquely identified by word that is 5-10 characters long and I use TINYTEXT(10) for the column. However, when I try to set it as PRIMARY key I get the error that size is missing.
From my limited understanding of the docs, Size for PRIMARY keys can be used to simplify a way to detect unique value i.e. when first few character (specified by Size) can be enough to consider it unique match. In my case, the size would differ from 5 to 10 (they are all latin1 so they are exact byte per character + 1 for the lenght). Two questions:
If i wanted to use TINYTEXT as PRIMARY key, which size should I specify? Maximum available - 10 in this case? Or should be the size strictly EXACT, for example, if my key is 6 character long word, but I specify Size for PK as 10 - it will try to read all 10 and will fail and throw me an exception?
How bad performance-wise would be to use [TINY]TEXT for the PK? All Google results lead me to opinions and statements "it is BAD, you are fired", but is it really true in this case, considering TINYTEXT is 255 max and I already specified max length to 10?
MySQL/MariaDB can index only the first characters of the text fields but not the whole text if it is too large. The maximum key size is 3072 bytes and any text field larger than that cannot be used as KEY. Therefore on text fields longer than 3072 bytes you must specify explicitly how much characters it will index. When using VARCHAR or CHAR it can be done directly because you explicitly set it when declaring the datatype. It's not the case with *TEXT - they do not have that option. The solution is to create the primary key like this:
CREATE TABLE mytbl (
name TEXT NOT NULL,
PRIMARY KEY idx_name(name(255))
);
The same trick can be done if you need to make primary key on a VARCHAR field which is larger than 3072 bytes, on BINARY fields and BLOBs. Anyway you can imagine that if two large and different texts start with the same characters at the first 3072 bytes at the beginning, they will be treated as equal by the system. That may be a problem.
It is generally bad idea to use text field as primary key. There are two reasons for that:
2.1. It takes much more processing time than using integers to search in the table (WHERE, JOINS, etc). The link is old but still relevant;
2.2. Any foreign key in another table must have the same datatype as the primary key. When you use text, this will waste disk space;
Note: the difference between *TEXT and VARCHAR is that the contents of the *TEXT fields are not stored inside the table but in outside memory location. Usually we do that when we need to store really large text.
for TINYTEXT can not specify the size. Use VARCHAR (size)
SQL Data Types
FYI, you can't specify a size for TINYTEXT in MySQL:
mysql> create table t1 ( t tinytext(10) );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near '(10) )' at line 1
You can specify a length after TEXT, but it doesn't work the way you think it does. It means it will choose one of the family of TEXT types, the smallest type that supports at least the length you requested. But once it does that, it does not limit the length of input. It still accepts any data up to the maximum length of the type it chose.
mysql> create table t1 ( t text(10) );
Query OK, 0 rows affected (0.02 sec)
mysql> show create table t1\G
*************************** 1. row ***************************
Table: t1
Create Table: CREATE TABLE `t1` (
`t` tinytext
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
mysql> insert into t1 set t = repeat('a', 255);
Query OK, 1 row affected (0.01 sec)
mysql> select length(t) from t1;
+-----------+
| length(t) |
+-----------+
| 255 |
+-----------+

String length data for DynamoDB

I try to convert the string length of 400KB (the maximum size of a DynamoDB item) to characters.
I don't know if KB is kilobytes (in this case 400 000 characters) OR kilobits (in this case 51 200 characters).
Do you know that ?
Thanks
Definitely 400 KiloBytes. But DynamoDb uses UTF-8 encoding for the strings. So if the your string is UTF-16 encoded, it may or may not fit as one dynamodb item. Secondly the 400KB limit also includes the binary length of the attribute key names you have in the table.
How many characters can UTF-8 encode?
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-items

Some firestore quotas misunderstandings

I'm planning a stucture of db in firestore and cannot understand some standard points
Link: https://firebase.google.com/docs/firestore/quotas
1 point
This means total memory size in db of fields which are composite indexed in collection?
3 point
Is 20000 similar to max count of fields in document because due to doc every field is automatically indexed? or they mean something like
queryRef
.where('field1', '<', someNumber1)
...
.where('field20000', '<', someNumber20000);
Sorry for my not good english
Point 1
You can see how size is calculated in the Storage Size Calculation documentation.
Index entry size
The size of an index entry is the sum of:
The document name size of the indexed document
The sum of the indexed field sizes
The size of the indexed document's collection ID if the
index is an automatic index (does not apply to composite indexes)
32
additional bytes
Using this document in a Task collection with a numeric ID as an example:
Task id:5730082031140864
- "type": "Personal"
- "done": false
- "priority": 1
If you have a composite index on type + priority (both ascending), the total size of the index entry in this index is 84 bytes:
29 bytes for the document name
6 bytes for the done field name and boolean value
17 bytes for the priority field name and integer value
32 additional bytes
Point 2
For single field indexes (the ones we automatically create), we create 2 indexes per field: ascending + descending.
This means 10000 fields will hit the 20000 index entry limit, so 10000 fields is the current maximum. Less if you also have composite indexes since it will consume some of the 20000 index entry limit per document.

What is the maximum size limit of varchar data type in sqlite?

I'm new to sqlite. I want to know the maximum size limit of varchar data type in sqlite?
can anybody suggest me some information related to this? I searched on sqlite.org site and they give the answer as:
Q. What is the maximum size of a VARCHAR in SQLite?
A. SQLite does not enforce the length of a VARCHAR. You can declare a VARCHAR(10) and SQLite will be happy to let you put 500
characters in it. And it will keep all 500 characters intact - it
never truncates.
but I want to know the exact max size limit of varchar datatype in sqlite.
from http://www.sqlite.org/limits.html
Maximum length of a string or BLOB
The maximum number of bytes in a
string or BLOB in SQLite is defined by
the preprocessor macro
SQLITE_MAX_LENGTH. The default value of this macro is 1 billion (1 thousand
million or 1,000,000,000). You can
raise or lower this value at
compile-time using a command-line
option like this:
-DSQLITE_MAX_LENGTH=123456789 The current implementation will only
support a string or BLOB length up to
231-1 or 2147483647. And some built-in
functions such as hex() might fail
well before that point. In
security-sensitive applications it is
best not to try to increase the
maximum string and blob length. In
fact, you might do well to lower the
maximum string and blob length to
something more in the range of a few
million if that is possible.
During part of SQLite's INSERT and
SELECT processing, the complete
content of each row in the database is
encoded as a single BLOB. So the
SQLITE_MAX_LENGTH parameter also
determines the maximum number of bytes
in a row.

What is the maximum size we can give for nvarchar in sqlite?

In SqlServer we can use NVarchar(MAX) but this is not possible in sqlite. What is the maximum size I can give for Nvarchar(?)?
There is no maximum in SQLite. You can insert strings of unlimited length (subject to memory and disk space.) The size in the CREATE TABLE statement is ignored anyway.
What is the maximum size I can give for Nvarchar(?)?
You don't, because Sqlite will ignore anything over 255 when specified inside NVARCHAR(?).
Instead, use the TEXT datatype wherever you need NVARCHAR(MAX).
For instance, if you need a very large string column to store Base64 string values for images, you can use something like the following for that column definition.
LogoBase64String TEXT NULL,
SQLite doesn't really enforce length restrictions on length of string.
Note that numeric arguments in parentheses that following the type
name (ex: "VARCHAR(255)") are ignored by SQLite - SQLite does not
impose any length restrictions (other than the large global
SQLITE_MAX_LENGTH limit) on the length of strings, BLOBs or numeric
values.
Source www.sqlite.org/datatype3

Resources