ResultSet Memory

痞子三分冷 提交于 2019-12-22 18:29:06

问题


I have ResultSet of 100k records with each record has 5 cell 2 of them are of int data type and 3 are of Varchar (100) data type

my question is how the memory is allocated to resultset for these data types when a query is executed from a java program

specially to varchar data type is all the varchar(100) cells have same memory of 100 chars or it depends on the data each varchar(100) cell contains

for example say I have the following record with two cell on varchar(100)

------------------------
| "abc" | | "pqrstuv" |
------------------------

is memory size here 10 chars or 200 chars?

regards


回答1:


the "varchar" type is for variable length strings. thus, your strings will only take the amount of space as the number of characters actually in the string (so 10 chars in your example). if you defined those fields as just "char" (fixed length), then they would take up 100 characters each.




回答2:


Most JDBC drivers support paging of result sets. This means only a portion of results are loaded at a time. The amount of memory used internal is unlikely to matter because it will only ever be a sub-set of the data. If you keep all the records, the amount of data used is more important. When you retain a String it will use 1-2 bytes per character (plus some overhead) depending on your JVM.

Either way, unless you have a mobile device the memory used is likely to be very small compared to the memory you have.



来源:https://stackoverflow.com/questions/6651250/resultset-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!