cursor vs resultHandler

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

cursor vs resultHandler

joek
Hello,

What is the difference using cursor vs resultHandler in mybatis?

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: cursor vs resultHandler

Guy Rouillier-2
The MyBatis User's Guide has a short description of ResultHandler:

"The ResultHandler parameter allows you to handle each row however you like. You can add it
to a List, create a Map, Set, or throw each result away and instead keep only rolled up totals of
calculations. You can do pretty much anything with the ResultHandler, and it's what MyBatis uses
internally itself to build result set lists."

You only need to consider it if you are unable to get MyBatis to process the result set as you require; I've been using MyBatis for many years, and have never had to resort to a custom ResultHandler.

The primary use case of a cursor is when one is returned from a stored procedure.  This is fairly common.  You are able to immediately send the returned cursor to a result map, and MyBatis will process it for you automatically.

--
Guy Rouillier

------ Original Message ------
From: "denis Khong" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 7/31/2018 5:32:39 PM
Subject: cursor vs resultHandler

Hello,

What is the difference using cursor vs resultHandler in mybatis?

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: cursor vs resultHandler

Erwan Letessier
I would say that they are not in the same scope.
The resultHandler fetches the whole resultSet to return a list by default or do whatever you want for each result.
The cursor is an iterator over the resultSet with the particular interest to be able to fetch either nothing, all, partially, by page.
Otherwise the same things can ce achieved with one or the other.

On Wed, Aug 1, 2018, 07:16 Guy Rouillier <[hidden email]> wrote:
The MyBatis User's Guide has a short description of ResultHandler:

"The ResultHandler parameter allows you to handle each row however you like. You can add it
to a List, create a Map, Set, or throw each result away and instead keep only rolled up totals of
calculations. You can do pretty much anything with the ResultHandler, and it's what MyBatis uses
internally itself to build result set lists."

You only need to consider it if you are unable to get MyBatis to process the result set as you require; I've been using MyBatis for many years, and have never had to resort to a custom ResultHandler.

The primary use case of a cursor is when one is returned from a stored procedure.  This is fairly common.  You are able to immediately send the returned cursor to a result map, and MyBatis will process it for you automatically.

--
Guy Rouillier

------ Original Message ------
From: "denis Khong" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 7/31/2018 5:32:39 PM
Subject: cursor vs resultHandler

Hello,

What is the difference using cursor vs resultHandler in mybatis?

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: cursor vs resultHandler

joek
Thanks!

So in term of memory, I understand that it's better to use cursor then resultHandler when query return millions of rows right ?

Le mercredi 1 août 2018 10:32:07 UTC+2, Erwan Letessier a écrit :
I would say that they are not in the same scope.
The resultHandler fetches the whole resultSet to return a list by default or do whatever you want for each result.
The cursor is an iterator over the resultSet with the particular interest to be able to fetch either nothing, all, partially, by page.
Otherwise the same things can ce achieved with one or the other.

On Wed, Aug 1, 2018, 07:16 Guy Rouillier <<a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="V32OcySgCgAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">guy.ro...@...> wrote:
The MyBatis User's Guide has a short description of ResultHandler:

"The ResultHandler parameter allows you to handle each row however you like. You can add it
to a List, create a Map, Set, or throw each result away and instead keep only rolled up totals of
calculations. You can do pretty much anything with the ResultHandler, and it's what MyBatis uses
internally itself to build result set lists."

You only need to consider it if you are unable to get MyBatis to process the result set as you require; I've been using MyBatis for many years, and have never had to resort to a custom ResultHandler.

The primary use case of a cursor is when one is returned from a stored procedure.  This is fairly common.  You are able to immediately send the returned cursor to a result map, and MyBatis will process it for you automatically.

--
Guy Rouillier

------ Original Message ------
From: "denis Khong" <<a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="V32OcySgCgAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">denis...@...>
To: "mybatis-user" <<a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="V32OcySgCgAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybati...@...>
Sent: 7/31/2018 5:32:39 PM
Subject: cursor vs resultHandler

Hello,

What is the difference using cursor vs resultHandler in mybatis?

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="V32OcySgCgAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="V32OcySgCgAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: cursor vs resultHandler

Erwan Letessier
No. Memory usage is the same. For both you specify what to find for each result: in the handleResult or in the cursor iteration loop. Second thought, with resultHandler you can also do pagination. E.g For batch processing 1 million results by groups of 1000.
Eventually the only thing left I see is with cursor you stop when you want because you write the loop. Unlike resultHandler approach will fetch the result till the end because MyBatis iterates.
Cursor seems sometimes a better approach.
Can likely be easily used in Stream API. 

On Wed, Aug 1, 2018, 22:17 joek <[hidden email]> wrote:
Thanks!

So in term of memory, I understand that it's better to use cursor then resultHandler when query return millions of rows right ?

Le mercredi 1 août 2018 10:32:07 UTC+2, Erwan Letessier a écrit :
I would say that they are not in the same scope.
The resultHandler fetches the whole resultSet to return a list by default or do whatever you want for each result.
The cursor is an iterator over the resultSet with the particular interest to be able to fetch either nothing, all, partially, by page.
Otherwise the same things can ce achieved with one or the other.

On Wed, Aug 1, 2018, 07:16 Guy Rouillier <[hidden email]> wrote:
The MyBatis User's Guide has a short description of ResultHandler:

"The ResultHandler parameter allows you to handle each row however you like. You can add it
to a List, create a Map, Set, or throw each result away and instead keep only rolled up totals of
calculations. You can do pretty much anything with the ResultHandler, and it's what MyBatis uses
internally itself to build result set lists."

You only need to consider it if you are unable to get MyBatis to process the result set as you require; I've been using MyBatis for many years, and have never had to resort to a custom ResultHandler.

The primary use case of a cursor is when one is returned from a stored procedure.  This is fairly common.  You are able to immediately send the returned cursor to a result map, and MyBatis will process it for you automatically.

--
Guy Rouillier

------ Original Message ------
From: "denis Khong" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 7/31/2018 5:32:39 PM
Subject: cursor vs resultHandler

Hello,

What is the difference using cursor vs resultHandler in mybatis?

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: cursor vs resultHandler

joek
Thanks !

Le mer. 1 août 2018 à 11:11 PM, Erwan Letessier <[hidden email]> a écrit :
No. Memory usage is the same. For both you specify what to find for each result: in the handleResult or in the cursor iteration loop. Second thought, with resultHandler you can also do pagination. E.g For batch processing 1 million results by groups of 1000.
Eventually the only thing left I see is with cursor you stop when you want because you write the loop. Unlike resultHandler approach will fetch the result till the end because MyBatis iterates.
Cursor seems sometimes a better approach.
Can likely be easily used in Stream API. 

On Wed, Aug 1, 2018, 22:17 joek <[hidden email]> wrote:
Thanks!

So in term of memory, I understand that it's better to use cursor then resultHandler when query return millions of rows right ?

Le mercredi 1 août 2018 10:32:07 UTC+2, Erwan Letessier a écrit :
I would say that they are not in the same scope.
The resultHandler fetches the whole resultSet to return a list by default or do whatever you want for each result.
The cursor is an iterator over the resultSet with the particular interest to be able to fetch either nothing, all, partially, by page.
Otherwise the same things can ce achieved with one or the other.

On Wed, Aug 1, 2018, 07:16 Guy Rouillier <[hidden email]> wrote:
The MyBatis User's Guide has a short description of ResultHandler:

"The ResultHandler parameter allows you to handle each row however you like. You can add it
to a List, create a Map, Set, or throw each result away and instead keep only rolled up totals of
calculations. You can do pretty much anything with the ResultHandler, and it's what MyBatis uses
internally itself to build result set lists."

You only need to consider it if you are unable to get MyBatis to process the result set as you require; I've been using MyBatis for many years, and have never had to resort to a custom ResultHandler.

The primary use case of a cursor is when one is returned from a stored procedure.  This is fairly common.  You are able to immediately send the returned cursor to a result map, and MyBatis will process it for you automatically.

--
Guy Rouillier

------ Original Message ------
From: "denis Khong" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 7/31/2018 5:32:39 PM
Subject: cursor vs resultHandler

Hello,

What is the difference using cursor vs resultHandler in mybatis?

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.