简体   繁体   English

从JAVA到数据库的数据库调用的性能

[英]Performance of database call from JAVA to Database

Our team is building a small application wherein a UI has about 10 drop-down list boxes. 我们的团队正在构建一个小型应用程序,其中一个UI包含大约10个下拉列表框。 ( DDLB ). (DDLB)。

These list boxes will be populated by selecting data from different tables. 这些列表框将通过从不同表中选择数据来填充。

Our JAVA person feels that making separate database call for each list will be very expensive and wants to make a single database call for all lists. 我们的JAVA人员认为,对每个列表进行单独的数据库调用将非常昂贵,并且希望对所有列表进行单个数据库调用。

I feel it is impractical to populate all lists in one database call due to following reason 由于以下原因,我认为在一个数据库调用中填充所有列表是不切实际的

 a. Imagine an end user chooses state = 'NY' from one DDLB.
 b. The next drop down should be populated with values from ZIP_CODES table for STATE='NY'

Unless we know ahead of time what state a user will be choosing - our only choice is to populate a java structure with all values from ZIP_CODES table. 除非我们提前知道用户将选择哪种状态,否则我们唯一的选择就是用ZIP_CODES表中的所有值填充Java结构。 And after the user has selected the state - parse this structure for NY zipcodes. 在用户选择状态后-解析此结构以获取NY邮政编码。

And imagine doing this for all the DDLB in the form. 并想象对表单中的所有DDLB进行此操作。 This will not only be practical but also resource intensive. 这不仅是实际的,而且是资源密集的。

Any thoughts ? 有什么想法吗 ?

If there are not many items in those lists and memory amount allows you could load all values for all drop boxes into memory at application startup and then filter data in memory. 如果这些列表中没有很多项目,并且内存量允许,您可以在应用程序启动时将所有保管箱的所有值加载到内存中,然后过滤内存中的数据。 It will be better then execute SQL query for every action user makes with those drop boxes. 最好对用户使用这些下拉框执行的每个操作执行SQL查询。

You could also use some cache engines (like EhCache ) that could offload data to disk and store only some fraction in memory. 您还可以使用某些缓存引擎(例如EhCache ),这些引擎可以将数据卸载到磁盘上,并且仅将一部分存储在内存中。

You can run some timings to see, but I suspect you're sweating something that might take 100th of a second to execute. 您可以花一些时间看一下,但是我怀疑您正在流汗,可能需要100秒的时间才能执行。 UI design wise I never put zip codes in selection menus because the list is too long and people already know it well enough to just punch in. When they leave the zip code field I will query the city and state and pre-fill those fields if they're not already set. 明智的UI设计,我从不将邮政编码放在选择菜单中,因为列表太长,人们已经知道它足以打孔。当他们离开邮政编码字段时,我将查询城市和州,并在以下字段中预先填写他们尚未设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM