Choosing an optimal hash size (2024)

Choosing an optimal hash size

The UltraLite default maximum hash size of 4 bytes was chosen to suit most deployments. You can increase the size to include more data with the row ID. However, this change could increase the size of the index and fragment it among multiple pages. This change can possibly increase the size of the database as a result. The impact of an increased maximum hash size depends on the number of rows in the table: for example, if you only have a few rows, a large index hash key would still fit on the index page. No index fragmentation occurs in this case.

When choosing an optimal hash size, consider the data type, the row data, and the database size (especially if a table contains many rows).

The only way to determine if you have chosen an optimal hash size is to run benchmark tests against your UltraLite client application on the target device. You need to observe how various hash sizes affect the application and query performance, in addition to the changes in database size itself.

The data type

If you want to hash the entire value in a column, note the size required by each data type in the table that follows. UltraLite only uses the maximum hash size if it really needs to, and it never exceeds the maximum hash size you specify. UltraLite always use a smaller hash size if the column type does not use the full byte limit.

Data type Bytes used to hash the entire value
FLOAT, DOUBLE, and REAL Not hashed.
BIT and TINYINT 1
SMALL INT and SHORT 2
INTEGER, LONG, and DATE 4
DATETIME, TIME, TIMESTAMP, and BIG 8
CHAR and VARCHAR

To hash the entire string, the maximum hash size in bytes must match the declared size of the column. In a UTF-8 encoded database, always multiply the declared size by a factor of 2, but only to the allowed maximum of 32 bytes.

For example, if you declare a column VARCHAR(10) in a non-UTF-8 encoded database, the required size is 10 bytes. However, if you declare the same column in a UTF-8 encoded database, the size used to hash the entire string is 20 bytes.

BINARY

The maximum hash size in bytes must match the declared size of the column.

For example, if you declare a column BINARY(30), the required size is 30 bytes.

UUID 16

For example, if you set a maximum hash size of 6 bytes for a two-column composite index that you declared as INTEGER and BINARY (20) respectively, then based on the data type size requirements, the following occurs:

  • The entire value of the row in the INTEGER column is hashed and stored in the index because only 4 bytes are required to hash integer data types.

  • Only the first 2 bytes of the BINARY column are hashed and stored in the index because the first 4 bytes are used by the INTEGER column. If these remaining 2 bytes do not hash an appropriate amount of the BINARY column, increase the maximum hash size.

The row data

The row values of the data being stored in the database also influence the effectiveness of a hashed index.

For example, if you have a common prefix shared among entries of a given column, you may render the hash ineffective if you choose a size that only hashes prefixes. In this case, you need to choose a size that ensures more than just the common prefix is hashed. If the common prefix is long, you should consider not hashing the values at all.

When a non-unique index stores many duplicate values, and UltraLite cannot hash the entire value, the hash likely cannot improve performance.

The database size

Each index page has some fixed overhead, but the majority of the page space is used by the actual index entries. A larger hash size means each index entry is bigger, which means that fewer entries can fit on a page. For large tables, indexes with large hashes use more pages than indexes with small or no hashes. The more pages required increases the database size and degrades performance. The latter typically occurs because the cache can only hold a fixed number of pages thereby causing UltraLite to swap pages.

The following table gives you an approximation of how the hash size can affect the number of pages required to store data in an index:

Table Page size Hash size Number of entries Pages required
Table A 4 KB 0 1200 3 pages
Table B 4 KB 32 bytes 116 3 pages
Table C 4 KB 32 bytes 1200 entries 11 pages
See also
  • UltraLite max_hash_size creation parameter
  • UltraLite performance and optimization
  • Adding UltraLite indexes
  • Data types in UltraLite
Choosing an optimal hash size (2024)
Top Articles
Uzi
W3Schools.com
AllHere, praised for creating LAUSD’s $6M AI chatbot, files for bankruptcy
Doublelist Paducah Ky
Videos De Mexicanas Calientes
RuneScape guide: Capsarius soul farming made easy
According To The Wall Street Journal Weegy
Canelo Vs Ryder Directv
Weather In Moon Township 10 Days
How Many Slices Are In A Large Pizza? | Number Of Pizzas To Order For Your Next Party
Aces Fmc Charting
10 Free Employee Handbook Templates in Word & ClickUp
180 Best Persuasive Essay Topics Ideas For Students in 2024
Who called you from 6466062860 (+16466062860) ?
Colorado mayor, police respond to Trump's claims that Venezuelan gang is 'taking over'
Cashtapp Atm Near Me
Dignity Nfuse
E22 Ultipro Desktop Version
Ally Joann
Robin D Bullock Family Photos
Vegito Clothes Xenoverse 2
Galaxy Fold 4 im Test: Kauftipp trotz Nachfolger?
Kingdom Tattoo Ithaca Mi
Toothio Login
Target Minute Clinic Hours
4Oxfun
Rugged Gentleman Barber Shop Martinsburg Wv
Roseann Marie Messina · 15800 Detroit Ave, Suite D, Lakewood, OH 44107-3748 · Lay Midwife
Healthy Kaiserpermanente Org Sign On
Housing Intranet Unt
1475 Akron Way Forney Tx 75126
Baddies Only .Tv
How to Draw a Bubble Letter M in 5 Easy Steps
Chase Bank Cerca De Mí
Garrison Blacksmith's Bench
Hattie Bartons Brownie Recipe
Compress PDF - quick, online, free
Wildfangs Springfield
Chatropolis Call Me
The Closest Walmart From My Location
Section 212 at MetLife Stadium
Mytime Maple Grove Hospital
Carteret County Busted Paper
How Big Is 776 000 Acres On A Map
Patricia And Aaron Toro
3500 Orchard Place
Phmc.myloancare.com
Online TikTok Voice Generator | Accurate & Realistic
15:30 Est
Kobe Express Bayside Lakes Photos
The Love Life Of Kelsey Asbille: A Comprehensive Guide To Her Relationships
Latest Posts
Article information

Author: Melvina Ondricka

Last Updated:

Views: 5939

Rating: 4.8 / 5 (68 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Melvina Ondricka

Birthday: 2000-12-23

Address: Suite 382 139 Shaniqua Locks, Paulaborough, UT 90498

Phone: +636383657021

Job: Dynamic Government Specialist

Hobby: Kite flying, Watching movies, Knitting, Model building, Reading, Wood carving, Paintball

Introduction: My name is Melvina Ondricka, I am a helpful, fancy, friendly, innocent, outstanding, courageous, thoughtful person who loves writing and wants to share my knowledge and understanding with you.