"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Database Mapping/batchSize.html" (14 Sep 2022, 60027 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(Quick Reference)

batchSize

Purpose

Customizes how many results are fetching during lazy loading.

Examples

class Book {
    ...
    static mapping = {
        batchSize 10
    }
}

Description

Usage: batchSize(integer)

Given a lazy association where an Author has many Book instances, GORM will perform one query for the Author and additional queries the associated Book instances. This is what is known as the N+1 problem and can often be worked around by using a join query. However, joins can be expensive.

Batch fetching is an optimization of lazy loading so that if, for example, you set a batchSize of 10 and you have an Author that with 30 books, instead of 31 queries you get four (one for the Author and three batches of 10):

static mapping = {
    batchSize 10
}

You can also configure batchSize on a per association basis:

class Author {

    static hasMany = [books: Book]

    static mapping = {
        books batchSize: 10
    }
}