Available in versions: Dev (3.19) | Latest (3.18) | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11 | 3.10 | 3.9
Interning data
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
SQL result tables are not optimal in terms of used memory as they are not designed to represent hierarchical data as produced by JOIN
operations. Specifically, FOREIGN KEY
values may repeat themselves unnecessarily:
+----+-----------+--------------+ | ID | AUTHOR_ID | TITLE | +----+-----------+--------------+ | 1 | 1 | 1984 | | 2 | 1 | Animal Farm | | 3 | 2 | O Alquimista | | 4 | 2 | Brida | +----+-----------+--------------+
Now, if you have millions of records with only few distinct values for AUTHOR_ID
, you may not want to hold references to distinct (but equal) java.lang.Integer
objects. This is specifically true for IDs of type java.util.UUID
or string representations thereof. jOOQ allows you to "intern" those values:
// Interning data after fetching Result<?> r1 = create.select(BOOK.ID, BOOK.AUTHOR_ID, BOOK.TITLE) .from(BOOK) .join(AUTHOR).on(BOOK.AUTHOR_ID.eq(AUTHOR.ID)) .fetch() .intern(BOOK.AUTHOR_ID); // Interning data while fetching Result<?> r1 = create.select(BOOK.ID, BOOK.AUTHOR_ID, BOOK.TITLE) .from(BOOK) .join(AUTHOR).on(BOOK.AUTHOR_ID.eq(AUTHOR.ID)) .intern(BOOK.AUTHOR_ID) .fetch();
You can specify as many fields as you want for interning. The above has the following effect:
- If the interned Field is of type
java.lang.String
, then String.intern() is called upon each string - If the interned Field is of any other type, then the call is ignored
Future versions of jOOQ will implement interning of data for non-String data types by collecting values in java.util.Set
, removing duplicate instances.
Note, that jOOQ will not use interned data for identity comparisons: string1 == string2
. Interning is used only to reduce the memory footprint of org.jooq.Result
objects.
Feedback
Do you have any feedback about this page? We'd love to hear it!