Scrolling, Counting (the whole shebang?)

Bear with me here, this one's causing me headaches and sleepless nights (and I'm not exaggerating. While this issue sits in Bugzilla the boss cannot be silenced.)
<cliche>The story so far...</cliche>
An implementation of a scrolling result set I built recently for one of the queries in our system was done like this (The database system in question is Postgresql, btw):
(1) Count the rows using a SELECT count(*) ...
(2) Get a cursor with DECLARE CURSOR FOR SELECT ...
(3) Use FETCH to grab rows, MOVE to move the cursor, etc.
(4) Finish up at some point in the future with a CLOSE.
Now...
The entire reason we went through this horror was because ResultSet in Postgres isn't implemented using native Postgres cursors. This made the development team uneasy (we thought the performance wouldn't be up to scratch) so we eventually decided we would go for a somewhat more brute-force way of using Postgres' built-in commands. The result, a very fast scrolling result set, which works fine, for the one or two pages in our system which use it.
But (there is ALWAYS a but, right?)...
Since the DECLARE CURSOR, FETCH, MOVE, and CLOSE statements are not in the SQL standard, the query doesn't work under, say, DB2. Likelihood is it wouldn't work under any other database at all. And for portability's sake, we're considering this to be a bad thing.
In addition to this, the need to get the count separately from the query itself means that in every place where we do a SELECT, we have to have an equivalent SELECT to do the count (which in some cases can bear little or no resemblance to the one used to do the query.)
So...
Question 1: Is doing an 'ordinary' SELECT query, holding the ResultSet in memory and simply reading off row by row only parts of it considered 'safe', where 'safe' is defined by not causing OutOfMemoryError for queries in the order of 10,000-100,000 results?
Now, we require a count of the number of the results. In our existing system this is the slowest part of the process because the SELECT count(*) takes orders of magnitude more time to execute than the DECLARE CURSOR. That is, the DECLARE CURSOR takes about 10ms, and the SELECT count(*) can take a minute, depending on the size of the result set, presumably because the DECLARE CURSOR doesn't actually do the query, and that the query executes as you fetch more results from it, or in the background. (Beats me, anything involving databases is magic as far as I'm concerned.)
Since we 'require' the count though (for the user interface only, despite the fact that it cripples the query speed somewhat), we might be able to get away with doing it this way, so...
Question 2: Would doing the following set of commands likely take the same amount of time to run (or less, or more), compared to doing the SELECT count(*)?
PreparedStatement ps = /* insert code here ;-) */
ResultSet rs = ps.executeQuery();
rs.afterLast();
int numRows = rs.getRow();
rs.beforeFirst();I guess another part of Question 2 is, is that sequence of commands considered an 'acceptable' way of counting the number of rows returned? It seems to me they would take a long time to run, but sob I don't know.
The main thing is, we have an extraordinarily large number of different queries in this system, and all of them pretty much use joins of some sort, and all of them are incredibly complex. The system as a whole is quite monolithic, which is why I'm trying to make this enhancement as simple as possible. The count-and-then-cursor method would not only be incompatible with DB2, Oracle and whatever, but would probably take an order of magnitude more time to roll into the system than something which simply caches the result sets.
Question 3: Does anyone know of an independent group, which might have implemented cursor-based ResultSet scrolling into Postgres' JDBC driver? This would be a big time saver, as the lack of this in their driver makes the database nearly useless for any sizable system, and 'unfortunately' our company has a heavily Open-Source philosophy (believe me, I love OS too, but in this case it's crippling us.)
Question 4: Does anyone know of a company in the Sydney region who is looking to recruit a guy who knows a hell of a lot about Jabber and various IM protocols, but not so much about databases? [Disclaimer: if you are my current employer, this is a JOKE.]
Since this is such a weight on my shoulders at the moment, I'll put up a fairly sizable number of dukes. Let's hope we attract the hot-shots. These problems must have been done 1000 times before, but I've never seen a tutorial on them, and not even the 5kg JDBC book we have here helps at all.

To have scrollable ResultSet you can use CachedRowSet (you can use it with any DBMS):
http://developer.java.sun.com/developer/earlyAccess/crs/
To prevent OutOfMemoryError you can:
PreparedStatement ps = /* insert code here ;-) */
PreparedStatement.setMaxRows(int�maxRows);
ResultSet rs = ps.executeQuery();
CachedRowSet crs = new CachedRowSet();
crs.populate(rs);
crs.afterLast();
int numRows = crs.getRow();
crs.beforeFirst();
and if numRows = maxRows promt users that there are more records and let them redefine query
or if you don't have to display all rows (who needs 100000 rows once anyway? ;)
retrieve and cache just keys and display result page by page (there are some other paterns to do paging).
100000 records is a lot, but it depends on number of users and RAM - it's still can be done.
there is another OpenSource JDBC driver for PostgreSQL: jxDBCon http://sourceforge.net/projects/jxdbcon/
you can compare it with PostgreSQL driver

Similar Messages

  • How to make the whole shebang appear in itunes window

    Because my 25" Asus monitor is on the blink I'm using my 19" Asus monitor, both purchased new last year.  Problem is that the 19", which displayed itunes perfectly before, now cuts the podcast list in half vertically and I have to use the horizontal arrow to see the right hand half of the display when I'm looking at the podcast list.  But when I download and have a download list, there's no horizontal arrow and the name of the podcast is not displayed at all, just the name of that particular episode.  So I have to play each one while it's on the podcast download list in order to make the name of the podcast appear in the little oval window on top for the currently playing podcast.  How do I make the itunes window display its whole contents at once?  The maximize button doesn't help--it's already maximized

    Hello,
    just a additional info: There are differences executing a Runbook with Runbook Tester:
    http://www.sc-orchestrator.eu/index.php/scoblog/99-functionality-differences-executing-a-runbook-with-runbook-tester
    Regards,
    Stefan
    www.sc-orchestrator.eu ,
    Blog sc-orchestrator.eu

  • Transferring pics/contacts the whole shebang , with a unusable screen

    Hi..my phone is soon to be sent off for repair which I turn I will loose all of the above. I tried plugging the phone into a laptop to transfer my stuff, but it came up with msg "I need to go into settings" on my phone which I can't access due to unable to use the touch screen.. Any ideas pls

    I see, Dean1211. You could try running a software repair on the handset to see whether that helps.
    To run a repair, download PC Companion to your computer. 
    If you can't unlock the screen then unfortuantely you cannot back up any data.
    Press Start under Support Zone > Phone/tablet Software Update > Start > Repair my phone/tablet > Continue > Accept data removal > Next > Wait for prepare > select model of phone > Follow connection steps. 
    Let us know how this goes for you. Another alternative you can try is connecting a mouse to to your handset using an OTG cable and see whether you can unlock and use the phone with a mouse. If you are not able to then the next step would be to contact Sony Xperia Customer Care in your region (contact details can be found by clicking on the link in my signature).

  • Scroll the whole page

    Hello there
    Jdeveloper : 11.1.2.2.0
    my page template should be as following
    header - footer - center - menu on the right
    the question is how can i achieve the template design and at the same time have a scroll over the whole page not just the center.is that possible ? what layout should i use ?
    thanks in advance
    Omar

    Thanks Pandu05
    here is the page
    <?xml version='1.0' encoding='UTF-8'?>
    <f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
            xmlns:c="http://java.sun.com/jsp/jstl/core">
        <c:set var="viewcontrollerBundle" value="#{adfBundle['viewcontroller.Templates.lookupTemplateBundle']}"/>
        <c:set var="msgBundle" value="#{adfBundle['com.beshara.corrs.view.ViewControllerBundle']}"/>
        <af:document title="home.jsf" id="d1">
            <af:form id="f1">           
                    <af:panelStretchLayout id="idd">
                        <f:facet name="top">
                            <af:outputText id="t" value="Top" inlineStyle="background-color: #FF6666;"/>
                        </f:facet>
                        <f:facet name="start">
                            <af:outputText id="s" value="Start" inlineStyle="background-color: #FFFF66;"/>
                        </f:facet>
                        <f:facet name="center">
                            <af:panelGroupLayout layout="vertical">
                                <af:image source="/skins/images/security_home.png"/>
                                <af:image source="/skins/images/security_home.png"/>
                                <af:image source="/skins/images/security_home.png"/>
                            </af:panelGroupLayout>
                        </f:facet>
                        <f:facet name="end">
                            <af:outputText id="e" value="End" inlineStyle="background-color: #66FF66;"/>
                        </f:facet>
                        <f:facet name="bottom">
                            <af:outputText id="b" value="Bottom" inlineStyle="background-color: #6666FF;"/>
                        </f:facet>
                    </af:panelStretchLayout>           
            </af:form>
        </af:document>
    </f:view>the problem now is that the center is not scrolled and when i set the lauyout of the panelGroupLayout in the center to scroll i get the scroll in the center,but what i want is to scroll over the whole page instead of the center.how can i achieve that ?

  • How can I get Instant notification if a download fails, instead of sifting through the whole library later looking for a fail message

    sometimes I download hundreds of articles, pdf's, videos etc at one sitting, and cannot stop to watch whether or not some few of the items "fail" to completely download. Later, when scrolling down the whole list of recent downloads in the library I try to squint and see the tiny words notifying of a failed download but it is easy to miss the warning plus when there are hundreds of items it is VERY time-consuming to double click each item to attempt a re-download . . it usually DOES re-download ok BUT selecting this process sends the cursor back to the top of the library listings and now it takes forever to find your place back in the area where there were several "fails" listed together to continue the correction process for the whole list. Would be SO VERY MUCH better if and when a particular download fails, that a pop up window message would alert to that fact and a simple click within said window would automatically re-start the download, etc. That way a vital article would not later be discovered to have no content or error message, etc, just when one needed it and perhaps was not able to go online to fix it.

    You can run this code in the Browser Console (Firefox/Tools > Web Developer) to add a tooltip to the icon of each item in that list.
    You probably need to scroll the full list to make Firefox update all attributes and you need to rerun the code in the browser console via cursor Up and Enter to update all tooltips after having done a new download.
    If you run the code then you get a pop-up that shows some information of all selected items (Ctrl click multiple items).
    You can open the Browser Console (Firefox/Tools > Web Developer).
    Paste the JavaScript code in the command line and press the Enter key to run the code.
    *Toggle the devtools.chrome.enabled pref on the <b>about:config</b> page to true to enable the command line
    <pre><nowiki>var {classes:Cc,interfaces:Ci} = Components;
    var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
    var win = wm.getMostRecentWindow("Places:Organizer");
    if(d=win.document.getElementById("downloadsRichListBox")){
    var C=[],L=[],r,R;
    r=d.getElementsByTagName("richlistitem");
    for(i=0;R=r[i];i++){
    var tt=R.getAttribute("image").replace(/^moz-icon:[/][/]([^?]+)[?]size=\d+$/,"$1");
    var tT=[];
    var nD=R.getAttribute("displayName");
    tT.push("["+(i+1)+"] ["+nD+"]");
    tT.push("FILE: "+tt);
    var eT=R.getAttribute("state")||0;
    var sT=R.getAttribute("status");
    tT.push("STATUS["+eT+"]: "+sT);
    R.setAttribute("tooltiptext",tT.join("\n"));
    if(R.getAttribute("selected")=="true"){C.push(tT);L.push(tt)}
    if(C){if(prompt(C.join("\n"),C)){prompt(L.join("\n"),L);}}
    </nowiki></pre>

  • How can I do Count the Words in a cell with Numbers?

    I'm producing a documentary, with a long list of captions. I was hoping using numbers to organize the captions in sequence. them take the word count and do a simple calculation to work out the numbers of frames required per caption, based on a certian numbers of words per minute.
    I can handle calculations, but can't figure out how/if numbers can count the whole words in a cell and pass that on to a formula.
    I count them manually, but the nature of the script means the captions are being constantly updated.
    Any help appreciated!

    Clever. The only additional suggestion is to use the function Trim() just in case there are extra spaces between the words.
    =LEN(TRIM(B))-LEN(SUBSTITUTE(B," ",""))+1
    Rob

  • How can I see the whole day in day view without scrolling?

    I'm using iCal 4.0.4 on my MacBook. I'd like to see the whole day of events without having to scroll down. Right now I can only see about 5 hours at a time. I've set the day to start at 8am to midnight. Is there a way to see 12-16 hours at a time with no scrolling?

    Hi,
    Go to iCal > Preferences General. If I remember correctly there should be a "Show XX hours at a time" option there.  There certainly is in version 6.0.
    Best wishes
    John M

  • How to read the whole name of a music title while scrolling down a list of titles? With the new iOs7 Music App there is no more black box showing the entire name!

    How to read the whole name of a music title while scrolling down a list of titles? The old software-app had the function to click for a longer time on a titles beginning letters until a black box revealed the entire name. I miss this function especially for my classical music, because lots of pieces start with similar words. E.g.:
    "Beethoven: Variations On "Ein Mädchen Oder Weibchen", Op. 66 - Var. 1"
    "Beethoven: Variations On "Ein Mädchen Oder Weibchen", Op. 66 - Var. 2"
    Scrolling in a list of title, I can't distinguish the titles, because just the first words are shown followed by: "...".
    That's horrible!

    Or you could include a width to your body style:
    body {
    background-image: url(Logo/sky1.jpg);
    background-position: center center;
    background-attachment: fixed;
    width: 75%;}
    It might work or not depending on your other color scheme.

  • Highlights the whole shuttle and starts scrolling down the shuttle

    Hi,
    I created a shuttle on a page and when I submit the page, which right now has no processes executing, automatically it highlights the whole shuttle and starts scrolling down the shuttle and then goes to a Page Not Found.
    I have a branch to this same page.
    What is going on.. ?
    Bill

    There is a limit of 2000 records (as far as my experience says). Over 1000 could also be over 2000.
    Try to press the save button here:
    http://apex.oracle.com/pls/otn/f?p=31517:166
    Do you get the same kind of error or something different?
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • I updated to the latest version and now I do not have the page controls at the right hand side and bottom and can only move the page up and down using the mouse scroll wheel. I also cannot see the whole page I am trying to view.

    When I open the web browser I cannot see the whole page and I cannot move the image sideways and must use the mouse scroll to move up and down.

    Try the following:
    1 - delete the iPhoto preference file, com.apple.iPhoto.plist, that resides in your
         User/Home/Library/ Preferences folder.
    2 - delete the contents the following folder:
    User/Library/Containers/com.apple.iPhoto
    3 - reboot, launch iPhoto and try again.
    NOTE: For Mavericks, 10.9,  go to your Home folder and use the View ➙ Show View Options menu to bring the this window:
    where you can check the Show Library Folder checkbox.

  • Can I get my old calendar back, before 7.1,. I liked seeing the whole week on me iPhone 4s. And being able to scroll

    Can I get my old calendar back? Before ios7.1. I liked seeing the whole week and being able to scroll &amp; scroll.........

    No, without a current backup any material that has been added in the interim will be lost.  Frequent backups are always highly recommended, especially before a major update to software.

  • Bookmarks opens in a window 2/3's the size of my screen since the latest update. Now the first bookmark I scroll over covers the whole window instead of too the side and I can't close it without closing the bookmarks window

    I kept getting a reminder I had a Firefox update I needed to install. I did last night but never opened Firefox again till this morning. Now when I click on bookmarks for the drop down it opens a window almost 2/3's the size of my screen instead of the narrow window it has in the past. Now as soon as I move my mouse over or close to any bookmark it opens up that bookmark in the window and I can't access the bookmark I want. I have to close the whole window and then be very careful as I move my mouse to the correct bookmark. In the past with the narrow window it opened the bookmarks to the side and only after you clicked on them. I have tried to resize the window but can't find any option to do so. Also couldn't find an option that would let me change it so a bookmark had to be clicked on. If this can't be changed I will be removing Firefox. This is too inconvenient for me.

    Take it to your local Apple Store or AASP, it's covered by a 1 year hardware warranty. If you have AppleCare then give them a call but I'm pretty sure they will advise the same. If you have not purchased AppleCare yet please do, this will extend the warranty to 3 years however it MUST be purchased within the first  year of ownership. Let it go 366 days and you are out of luck. AppleCare will also include telephone support too.
    Good luck.

  • How can I see the whole screen on my original iPad, without having to scroll up or down.  Something changed and I don't know how to get it back.  I don't have a computer to hook it up to.  Thx!

    My front screen seems to zoom in when I start it now.  AND, now I can not see the page fit the screen.  It makes me scroll on the borders to move parts of the screen into view.  Something changed and I don't know what happened or how to get it back to normal.  Please HELP!!!  Thx!

    it is possible that zoom maybe enabled i think double taping with three fingers should disable it.
    or you can go into settings>general> assessability> zoom and turn it off.
    hope this helps

  • IPhone 4s updated with IOS 8. Not the calendar will not show a full list of dates. Instead it shows the whole month with the list of the day selected. I want to have my full list back. So much easier to scroll thru when making appointments.

    iPhone 4s just updated with IOS 8. Now my calendar does not offer the full list of items by day on the screen. Instead I see the month and below the month are the appointments in a list for the selected day only. I would like the option to have the full list available as it is much easier to scroll thru the list when making appointments.

    Hello memormor,
    Thank you for visiting Apple Support Communities.
    To see the full scrollable list of events, start from the day view (tap on a day), not the month view, then click .
    Calendar at a glance - iPhone
    View a list of events. In month view, tap to see a day’s events. In day view, tap .
    Take care,
    Nubz

  • How can I print the whole page from an onlione HTML application - when the whole page is not visible without scrolling down?

    I am working with a spreadsheet with percentage marks; only 5 names out of a class are visible at one time. I need to print the data for the whole class - in a whole sheet.

    What is the size of your actual page? Have you tried Select All and Print>Selection? Most applications will also let you resize the print area to fit the paper, and with html you might be able to resize the page for printng at 75-80%. However, that may be too small to read.

Maybe you are looking for

  • Disable warning message in MB1A during BDC

    Hi, I am posting the goods issue records into SAP through MB1A in BDC.  However the warning message finally becomes the return message of the BDC call and the action is failed.  Actually it can be skipped by doing the transaction manually. Any soluti

  • JSP Response Slow in OC4J

    Hi, I have a web application (jsps and servlets accessig to an oracle database) deployed by jdeveloper 10g in OC4J Standalone 10g, the problem appears when my aplication turned very slow where i go to a jsp page, only the html pages are fast but my j

  • R/3 database monitoring through RFC

    I have code which monitor database. There are two servers, one is XID and other is ECD. Messages are flowing from ECD to XID. Code is uploaded in XID server .Code monitor XID database .code hits Standard Sap table i.e. SXMSPMAST, check entries and se

  • Adding iMatch to a computer

    Now that I've been able to authorize this computer (thank you for the help!!!), how do I activate iMatch.  I have already paid the subscription and it's on my desktop computer, iPad and iPhone.  How do I get it added back to this computer?  Everytime

  • HT201316 i accidentally changed the name of my hd on the desktop

    Hi everyone, glad to be here, and glad you might be able to help me. I can't remember what the original name was on my desktop hardrive icon, how can I find out the original name so I can change it back?  Thanks All.