Sorting overhead

When does the sort overhead for binary search overcomes linear search while using read statement for a internal table?
Moderator Message: Read the F1 documentation on READ TABLE
Edited by: Suhas Saha on Aug 16, 2011 11:34 AM

When does the sort overhead for binary search overcomes linear search while using read statement for a internal table?
Moderator Message: Read the F1 documentation on READ TABLE
Edited by: Suhas Saha on Aug 16, 2011 11:34 AM

Similar Messages

  • Parallel Index creation takes more time...!!

    OS - Windows 2008 Server R2
    Oracle - 10.2.0.3.0
    My table size is - 400gb
    Number of records - 657,45,95,123
    my column definition first_col varchar2(22) ; -> I am creating index on this column
    first_col -> actual average size of column value is 10
    I started to create index on this column by following command
    CREATE INDEX CALL_GROUP1_ANO ON CALL_GROUP1(A_NO) LOCAL PARALLEL 8 NOLOGGING COMPRESS ;
    -> In my first attempt after three hours I got an error :
    ORA-01652: unable to extend temp segment by 128 in tablespace TEMP
    So I increased the size of temp tablespace to 380GB ,Because i expect the size of first_col index this much.
    -> In my second attempt Index creation is keep going even after 17 hours...!!
    Now the usage of temp space is 162 GB ... still it is growing..
    -> I checked EM Advisor Central ADDM :
    it says - The PGA was inadequately sized, causing additional I/O to temporary tablespaces to consume significant database time.
    1. why this takes this much of Temp space..?
    2. It is required this much of time to CREATE INDEX in parallel processing...? more than 17 hrs
    3. How to calculate and set the size of PGA..?

    OraFighter wrote:
    Oracle - 10.2.0.3.0
    My table size is - 400gb
    Number of records - 657,45,95,123
    my column definition first_col varchar2(22) ; -> I am creating index on this column
    first_col -> actual average size of column value is 10
    I started to create index on this column by following command
    CREATE INDEX CALL_GROUP1_ANO ON CALL_GROUP1(A_NO) LOCAL PARALLEL 8 NOLOGGING COMPRESS ;
    Now the usage of temp space is 162 GB ... still it is growing..The entire data set has to be sorted - and the space needed doesn't really vary with degree of parallelism.
    6,574,595,123 index entries with a key size of 10 bytes each (assuming that in your choice of character set one character = one byte) requires per row approximately
    4 bytes row overhead 10 bytes data, 2 bytes column overhead for data, 6 bytes rowid, 2 bytes column overhead for rowid = 24 bytes.
    For the sorting overheads, using the version 2 sort, you need approximately 1 pointer per row, which is 8 bytes (I assumed you're on 64 bit Oracle on this platform) - giving a total of 32 bytes per row.
    32 * 6,574,595,123 / 1073741824 = 196 GB
    You haven't said how many partitions you have, but you might want to consider creating the index unusable, then issuing a rebuild command on each partition in turn. From "Practical Oracle 8i":
    <blockquote>
    In the absence of partitioned tables, what would you do if you needed to create a new index on a massive data set to address a new user requirement? Can you imagine the time it would take to create an index on a 450M row table, not to mention the amount of space needed in the temporary segment. It's the sort of job that you schedule for Christmas or Easter and buy a couple of extra discs to add to the temporary tablespace.
    With suitably partitioned tables, and perhaps a suitably friendly application, the scale of the problems isn't really that great, because you can build the index on each partition in turn. This trick depends on a little SQL feature that appears to be legal even though I haven't managed to find it in the SQL reference manual:
         create index big_new_index on partitioned_table (colX)
         local
         UNUSABLE
         tablespace scratchpad
    The key word is UNUSABLE. Although the manual states that you can 'alter' an index to be unusable, it does not suggest that you can create it as initially unusable, nevertheless this statement works. The effect is to put the definition of the index into the data dictionary, and allocate all the necessary segments and partitions for the index - but it does not do any of the real work that would normally be involved in building an index on 450M rows.
    </blockquote>
    (The trick was eventually documented a couple of years after I wrote the book.)
    Regards
    Jonathan Lewis

  • I need to sort an array of strings based on the number in each string.

    Basically, I have a directory of files that all have the same name but each with a different number on the end.
    example: image 1.jpg, image 2.jpg, etc.
    When I use the List Directory function that returns an array of strings containing the file names in the directory, they don't come out in a 1, 2, 3, order like they appear in the directory. It sorts them character by character so that they come out like: 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22 etc.
    Is there a simple way of sorting this array of strings with the file names (as above) so that they are in numerical order?

    It's a while since this thread was started, but I am sure others will have use for this so here goes:
    The in-built array sort function sorts the strings the same way DOS and Windows do. Microsoft has fixed this in the Explorer that comes with XP, however the rest of the OS(s) still sorts the old way.
    The attached "AlphaLogical String Array Sort" VIs will sort strings arrays the same way as the new XP Explorer. There are three different implementations of the sorting, one based on the Insertion sort algorithm, a Quick Sort based on recursive calls (the most elegant way, but unfortunately LabVIEW has too much overhead when doing recursive calls so this is actually a very slow alternative) and finally the fastest; a stack based Quick Sort. There is also a test VI that will show you how the different implementations perform.
    I had not used recursive calls in LV much until I made the attached quick sort and was a bit disappointed by the fact that it is so slow, but it's a good learning example...The ability to do recursive calls this way was introduced in LV7 I believe...There is an example here on the zone that shows how you can calulate a factorial by using recursive calls, however - unlike for the quick sort (normally) - recursive calls are actually not the optimal solution for that calculation.
    Message Edited by Mads on 09-13-2005 02:30 AM
    MTO
    Attachments:
    AlphaLogical Sorting.zip ‏142 KB

  • Buffer(sort) operator

    Hi,
    i'm trying to understand what "buffer sort" operation is in the following explain plan:
    0 SELECT STATEMENT
    -1 MERGE JOIN CARTESIAN
    --2 TABLE ACCESS FULL PLAYS
    --3 BUFFER SORT
    ---4 TABLE ACCESS FULL MOVIE
    In Oracle 9i DataBase Performance Guide and Reference, "buffer sort" is not mentioned although all other explain plan's operations are.
    What does it mean? Does it take place in main memory or is it an external sort?
    Thank you.

    A BUFFER SORT typically means that Oracle reads data blocks into private memory,because the block will be accessed multiple times in the context of the SQL statement execution. in other words, Oracle sacrifies some extra memory to
    reduce the overhead of accessing blocks multiple times in shared memory.
    Hope this will clear your doubts.
    Thanks.

  • Using field-symbols in sort criteria ??

    Hi All,
    I am having problems getting a dynamic sort to work.
    The idea is to dynamically assign the field and sequence in the sort statement.
    example.
    assign 'WERKS' to <fld1>.
    assign 'ASCENDING' to <ord1>.
    assign 'MATNR' to <fld2>.
    assign 'DESCENDING' to <ord2>.
    sort itab by <fld1> <ord1> <fld2> <ord2>.
    Thanks for the help.
    David Cooper

    Hi!
    You can sort internal table specifying the sort fields dynamically only using construction:
    SORT itab BY (name), where name contains itab sort field name.
    You cannot dynamically specify sort order for internal tables (correct me anybody if not so).
    However if such requirement is obligatory you can use dynamic subroutine pool generation for this purpose. But keep in mind the following:
    - performance overhead
    - up to 36 temporary subroutine pools can currently be managed for each roll area and there is no mechanism to "free" used one (even in this case you can get around - just wrap this functionality in separate FM, call it using DESTINATION 'NONE' and call RFC_CONNECTION_CLOSE after that - so there is only one dynamic program per roll area)
    - consider SAP warnings - "This statement is for internal use only. Incompatible changes or further developments may occur at any time without warning or notice."
    Here it is code snippet:
    DATA:
          it_code TYPE STANDARD TABLE OF char72,
          code_line LIKE LINE OF it_code,
          table_type type string,     
          prog(8) TYPE c,
          msg(120) TYPE c,
          lin(10) TYPE c,
          wrd(10) TYPE c,
          off(3) TYPE c.
        APPEND 'PROGRAM SUBPOOL.' TO it_code.
        APPEND 'FORM SORT_IT' TO it_code.
        CONCATENATE 'TABLES P_IT STRUCTURE' table_type '.'
        INTO code_line SEPARATED BY SPACE.
        APPEND code_line TO it_code.
        CONCATENATE 'SORT P_IT' fld1 ord1 fld2 ord2 '.'
        INTO code_line SEPARATED BY SPACE.
        APPEND code_line TO it_code.
        APPEND 'ENDFORM.' TO it_code.
        GENERATE SUBROUTINE POOL it_code
          NAME prog
          MESSAGE msg
          LINE lin
          WORD wrd
          OFFSET off.
        IF sy-subrc <> 0.
    *TODO: your error handler
        ENDIF.
        PERFORM sort_it IN PROGRAM (prog)
        TABLES itab.
    Regards,
    Maxim.

  • Sorting a List containing Symbols?

    Hi,
    My problem relates to ordering results from a Hibernate query.
    I'm using Hibernate to return all records from a specific database table in the form of a List. The query contains an "order by" clause, and so my results look something like this (results ordered firstly alphanumerically, then alphabetically):
    1
    2
    9
    A
    B
    C
    Z
    The "problem" occurs when I retrieve records that contain symbols. I was hoping that such records would appear at the beginning of my retrieved records, and indeed that is the case for the majority of symbols, i.e.
    $
    1
    2
    9
    A
    B
    C
    Z
    However, for some reason, certain symbols are appearing at the END of my results. So my list of results looks something like this...
    $
    1
    2
    9
    A
    B
    C
    Z

    I assume that this ordering is the default one for Oracle.
    I want to sort my list of results so that ALL symbols appear at the beginning of the list. I was thinking about using some sort of Comparator, i.e.
    List result = Collections.sort(q.list(), new YourComparator());
    However, I'm not sure what code would go inside YourComparator() to compare symbols and order them accordingly. Perhaps comparing the ASCII codes might be an idea(?)
    Another solution might be to loop through each of my results and add the symbols and "non symbols" to separate lists, then order each list separately and combine them at the end. However this would probably have a major processing overhead.
    Any other (simpler) suggestions?
    Thanks in advance.

    If there are non-ASCII characters in your data, ASCII values probably won't do the job. If so, look at some of the static methods of the Character class. You should be able to build your own Comparator.

  • Firefox is supposed to be faster - it's far slower than any other version & I'm going to back to Explorer - this is too much & it keeps crashing!. Is anything going to be sorted soon?

    It is now so slow to load pages - I can have coffee and then maybe a page has loaded. Otherwise it's "embarrassed" because it cannot load pages/ bookmarks. This version is terrible - can you not put back the previous version till you've sorted out the problems?

    I don't know anything about that.  But I googled it and found this post in another forum -
    "I have more info on the issue at hand.
    The RDTSC instruction has, until recently, been an excellent high-resolution, low-overhead way of getting CPU timing information. With the advent of multi-core/hyperthreaded CPUs, systems with multiple CPUs, and "hibernating" operating systems, RDTSC often no longer provides reliable results. The issue has two components: rate of tick and whether all cores (processors) have identical values in their time-keeping registers. There is no longer any promise that the timestamp counters of multiple CPUs on a single motherboard will be synchronized. So, you can no longer get reliable timestamp values unless you lock your program to using a single CPU. Even then, the CPU speed may change due to power-saving measures taken by the OS or BIOS, or the system may be hibernated and later resumed (resetting the time stamp counter).
    I might be understanding this wrong but... Basically both RDTSC and QPC are used to time code in time-sensitive programs. However, RDTSC might be inaccurate in above described situations. I also might be wrong about this but I believe QPC has something to do with the HPET high precision event timer. Which is a more accurate timer.
    So this might explain why RDTSC and QPC has a delta that is too high. And if all of what I said above is true, then this error is benign."
    This signature left intentionally blank.

  • Sorted dynamic list problem - Azure Search Index

    Hello Everyone,
    Let's consider following problem: Vote app - we have 1000 NBA players and we want to create an app which first: let user vote for a player he wants to see in the All Star Game, second: user gets current rank list (example: Michael Jordan 1st - 1M votes,
    Derrick Rose 2nd - 0,9M votes, .. , Freddy Kruger - 999th - 0 votes and so on).
    Question: what is the best structure that can be implemented here to keep this data sorted? I would like to query this data source already sorted - it is not allowed to get the list of 1000 and sort locally in app. For example: 800 players can have 0 votes
    and I do not want to download their names just to display '0 votes' next to their names. I would like to get only 50 with highest score at the moment. Index should be refreshed-rebuild after each new POST-vote request.
    Can Azure Search service and its Index help me to solve this problem? The perfect .NET SortedList synchronized structure would look like this [votes][name]:
    SortedList[99982]['Michael Jordan']
    SortedList[89921]['Derrick Rose']
    SortedList[0]['Freddy Kruger']
    SortedList[0]['Ace Ventura'] -> but SortedList does not allow the 0 KEY to appear twice.
    Regards,

    Hi pr0t,
    It should be straightforward to get the data you want using the $orderby, $filter, and $top options. For example, if you have a field named vote, you could include this in your search request:
    /indexes/players/docs?$orderby=vote desc&$filter=vote gt 0&$top=50
    This will give the top 50 players by vote in descending order by vote. You can then put the data in whatever data structure you like on the client.
    One thing to be aware of though is the way you update votes in the index. We highly recommend batching index updates as much as possible rather than updating one document at a time. You can have up to 1000 documents in a single batch when indexing. This
    reduces overhead and indexing pressure on your search service.
    Hope this helps,
    -Bruce

  • Sorting a vector using the selection sort method

    I have to write a program that sorts a Vector using the selection sort algorithm. Unfortunately the textbook only has about 2 pages on vectors so needless to say I'm pretty clueless on how to manipulate vectors. However I think I'm on the right path, however I'm stuck on one part as shown in the code below.     
    private static void  selectionSort(Vector parts)
          int index;
            int smallestIndex;
            int minIndex;
            int temp = 0;
            for (index = 0; index < parts.size() - 1; index++)
              smallestIndex = index;
              for (minIndex = index + 1; minIndex < parts.size(); minIndex++)
               if (parts.elementAt(minIndex) < parts.elementAt(smallestIndex))  // this is where I'm having trouble
                  smallestIndex = minIndex;
                parts.setElementAt(temp, smallestIndex);
                parts.setElementAt(smallestIndex, index);
                parts.setElementAt(index, temp); if (parts.elementAt(minIndex) < parts.elementAt(smallestIndex))
    is returning "ProcessParts3.java:51: operator < cannot be applied to java.lang.Object,java.lang.Object"
    Here is the full program:
    import java.util.*;
    import java.io.*;
    public class ProcessParts3
         static Vector parts;
         public static void main(String[] args)
              loadVector();
         private static void loadVector()
         try
              Scanner fileIn = new Scanner(new File("productionParts.txt"));
              parts = new Vector();
              String partIn;
              while (fileIn.hasNext())
                   partIn = fileIn.nextLine();
                        parts.addElement(partIn.trim());
              selectionSort(parts);
                   for (int i = 0; i < parts.size(); i ++)
                   System.out.println(parts.elementAt(i));
         catch(Exception e)
              e.printStackTrace();
         private static void  selectionSort(Vector parts) //from this part down I'm responsible for the coding, everything
                                                               // everything above this was written by the teacher
                 int index;
            int smallestIndex;
            int minIndex;
            int temp = 0;
            for (index = 0; index < parts.size() - 1; index++)
                smallestIndex = index;
                for (minIndex = index + 1; minIndex < parts.size(); minIndex++)
                    if (parts.elementAt(minIndex) < parts.elementAt(smallestIndex))
                        smallestIndex = minIndex;
                parts.setElementAt(temp, smallestIndex);
                parts.setElementAt(smallestIndex, index);
                parts.setElementAt(index, temp);
    }Edited by: SammyP on Nov 27, 2009 11:43 AM

    SammyP wrote:
    I have to write a program that sorts a Vector using the selection sort algorithm...Hmmm.... Your teacher is, in my humble opinion, a bit of a tard.
    1. Vector is basically deprecated in favor of newer implementations of the List interface which where introduced in [the collections framework|http://java.sun.com/docs/books/tutorial/collections/index.html] with Java 1.5 (which became generally available back in May 2004, and went end-of-support Oct 2009). ArrayList is very nearly a "drop in" replacement for Vector, and it is much better designed, and is marginally more efficient, mainly because it is not syncronised, which imposes a small but fundamentally pointless overhead when the collection is not being accessed across multiple threads (as is the case in your program).
    2. Use generics. That "raw" Vector (a list of Objects) should be a genericised List<String> (a list of Strings)... because it's compile-time-type-safe... mind you that definately complicates the definition of your static sort method, but there's an example in the link... Tip: temp should be of type T (not int).
    Note that String implements [Comparable<String>|http://java.sun.com/javase/6/docs/api/java/lang/Comparable.html], so two String's can safely be compared using the compareTo method... In Java the mathematical operators (<, >, &#43;, -, /, &#42;, etc) are only applicable to the primitive types (byte char, int, float, etc)... The Java Gods just chose to muddy the waters (especially for noobs) by "overloading" the &#43; operator for String (and String only) to enable succinct, convenient string-concatenation... which I personally now see as "a little bit of a mistake" on there part.
         private static void  selectionSort(Vector parts)  {
    int index, smallestIndex, minIndex, temp = 0;
    for (index = 0; index < parts.size() - 1; index++) {
    smallestIndex = index;
    for (minIndex = index + 1; minIndex < parts.size(); minIndex++) {
    if (parts.elementAt(minIndex) < parts.elementAt(smallestIndex)) {
    smallestIndex = minIndex;
    parts.setElementAt(temp, smallestIndex);
    parts.setElementAt(smallestIndex, index);
    parts.setElementAt(index, temp);
    }3. ALLWAYS use {curly braces}, even when not strictly necessary for correctness, because (a) they help make your code more readable to humans, and also (b) if you leave them out, you will eventually stuff it up when you insert a line in the expectation that it will be part of the if statement (for example) but you forgot to also add the now mandatory curly-braces... This is far-too-common source of bugs in noob-code. Almost all professionals, nearly allways allways use curly braces, most of the time ;-)
    4. Variable names should be meaningful, except (IMHO) for loop counters... Ergo: I'd rename index plain old i, and minIndex to plain old j
        for ( int i=0; i<list.size()-1; ++i) {
          int wee = i; // wee is the index of the smallest-known-item in list.
          for ( int j=i+1; j<list.size(); ++j ) {Cheers. Keith.
    Edited by: corlettk on 28/11/2009 09:49 ~~ This here fraggin forum markup friggin sucks!

  • Does cleaning sort records and impact on max log size

    I'm looking for confirmation that the act of cleaning logs produces sorted records, equivalent to having inserted them in sorted order to begin with. If that is the case is the memory overhead of cleaning proportional to the maximum log file size, or will it spill to disk to sort? I ask since the max log file size is 1G, and if there is a memory component then it may be relevant to take into consideration.
    On a similar note, is increasing the log file size from 10MB recommended if the database is large (say a TB)? Are there some linear operations (most likely in the admin/maintenance category) that have to iterate over each log file?
    Thanks.

    Hi,
    I'm looking for confirmation that the act of cleaning logs produces sorted records, equivalent to having inserted them in sorted order to begin with.No, that's not exactly true. When records are written (migrated to the end of the log) during the log cleaning process, any clustering (writing of adjacent records in key order) occurs on a per BIN (bottom internal node) basis. So at most 128 records (or DatabaseConfig.setNodeMaxEntries) with adjacent key values are sorted and written out together in this manner. But normally not all records in a BIN will be migrated and I'll describe more about this below.
    If that is the case is the memory overhead of cleaning proportional to the maximum log file size, or will it spill to disk to sort? I ask since the max log file size is 1G, and if there is a memory component then it may be relevant to take into consideration.No, the memory used for sorting in this case is the JE cache itself -- the memory that holds the Btree. The log cleaner thread moves records to be migrated into the Btree (in the cache), and flags them for migration. These records are written lazily the next time their parent Btree node (the BIN I mentioned) needs to be flushed. This can occur for two reasons: 1) when the BIN is evicted from the cache because the cache is full, or 2) during the next checkpoint, since a checkpoint will flush all dirty BINs. The most desirable situation is that the BIN is flushed during the checkpoint, not during eviction, to reduce the number of times that a single BIN is flushed to disk. If a BIN is evicted, it may have to be fetched again later in order to migrate more records as part of the log cleaning process, and this is counterproductive.
    So during this process, the number of records that are written to disk in key order in a cluster, such that they are physically adjacent on disk, is variable. It depends on how many records are processed by cleaner threads, and inserted in their parent BIN for migration, between checkpoint intervals, and whether the BINs are evicted during this period.
    A physical cluster of records includes the BIN itself as well as its child records that are migrated for log cleaning. The fact that the BIN is part of the cluster is beneficial to apps where not all BINs fit in the cache. If a record and its parent BIN are not in cache, and the app reads that record, the BIN and the record must both be fetched from disk. Since they will be in physical proximity to each other on disk, disk head movement is avoided or reduced.
    However, not all of the child records in a BIN will necessarily be part of a physical cluster. If only some of the records in a BIN were processed by the log cleaner before the BIN is flushed by the checkpointer or evictor, then only a subset of the child records will be written as part of the cluster. In other words, even for a single BIN, all the child records in that BIN are not normally written out together in a cluster.
    Clustering is a useful feature and something we would like to enhance in the future. What I've described above is as far as we've gotten with this feature in the currently released and supported product. However, there are two experimental configuration settings that cause additional clustering to occur. These cause additional records to be written to disk when their parent BIN is flushed. If you're interested in trying these, I will be happy to explain them and work with you. But you should be aware that they're not currently in the standard, supported set of features, and are not well tested.
    I'm not sure whether I've given you less information than you need or more than you wanted. :-) If you describe in detail what you're trying to do, and more about your app and performance requirements, I may be able to offer more concrete advice.
    On a similar note, is increasing the log file size from 10MB recommended if the database is large (say a TB)? Are there some linear operations (most likely in the admin/maintenance category) that have to iterate over each log file?Yes, there are such operations and per-log file overhead, and we recommend using using a 20M to 50M log file size for large data sets. Log files larger than 50MB could decrease log cleaner performance.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Sorting and CopyOnWriteArrayList

    Hi,
    Last week I found myself working around the following problem: I have a list of data that is being searched already while new data is still added. Knowing to take care of the dreaded ConcurrentModificationException, I chose the [url http://download.oracle.com/javase/6/docs/api/java/util/concurrent/CopyOnWriteArrayList.html]CopyOnWriteArrayList implementation and I discovered that that class does not play well with Collections.sort():
    import java.util.Collections;
    import java.util.List;
    import java.util.concurrent.CopyOnWriteArrayList;
    public class OTNConcurrentArrayListSorting {
         public static void main(String[] args) {
              List<String> l = new CopyOnWriteArrayList<String>();
              l.add("oracle");
              l.add("java");
              Collections.sort(l);
    }leads to:
    Exception in thread "main" java.lang.UnsupportedOperationException
         at java.util.concurrent.CopyOnWriteArrayList$COWIterator.set(CopyOnWriteArrayList.java:1013)
         at java.util.Collections.sort(Collections.java:121)
         at OTNConcurrentArrayListSorting.main(OTNConcurrentArrayListSorting.java:12)This came as a surprise to me, but it is documented and after a bit of thinking quite understandable. After all what good is sorting if new elements are added to the list unseen and not taken into account in the sort.
    The way I worked around it, is using a binary search to find out where to add the new element and thus keeping the list sorted at all times. Only in preparation of this post, it occurred to me that I'd need the additions to be synchronized for that idea to work, so I ended up with this fragment:
    synchronized (revolutions) {
         int i = Collections.binarySearch(revolutions, info);
         if (i < 0) {
              revolutions.add(-(i+1), info);
    }I am not unhappy with the solution and it serves the purpose, but still I wonder whether there's a better alternative. Any ideas?

    Great suggestion! The list I am maintaining is a sort of index for elements like this, where the number is positive and the interval is a start and end date (the intervals are non overlapping and their sorting goes hand-in-hand with the number):
          * Packs the revolution number and the date range covered by it,
          * while {@link #compareTo(RevolutionInfo)} orders according to the number.
         private static class RevolutionInfo implements Comparable<RevolutionInfo>{
              int number;
              Interval span;
              @Override
              public String toString() {
                   return "Revolution "+number+" "+ span.toString();               
              @Override
              public int compareTo(RevolutionInfo o) {
                   return number - o.number;
         }I need to support both a search by number to retrieve the Interval of dates (an exact match, will work very well with the HashMap) and a search by date to get the revolution number. The two are now unified in one piece of search code and two different Comparator implementations.
    I am already maintaining an underlying datastructure in a HashMap, which I could use to improve the by number lookup-performance. By the way, the main (and measured) performance penalty I am trying to avoid is the following. I have a datastructure SkyMap, one per revolution (we'll reach 1000 in a couple of weeks) which I read from a 2 Mb XML-file (which is 400 maps, benchmarked at ~8 maps per second). In one use case, all the maps are alredy pre-loaded and can be served out of memory. In a much rarer use case, the maps are being loaded and a request (get number for a given date) needs to be handled: it's here that I want to remove the overhead of waiting for the entire file to be processed, but go about the business as soon as the SkyMap covering that date is available.

  • Sort key too long error

    Hi,
    I have a query which is customizable by the user based on changes to a table. They recently added 12 more double-precision columns to the table, giving them a total of 353 number columns and 32 varchar2 columns.
    The query needs to summarize these records into another table. Before adding the 12 new columns it worked fine. Now we get the oracle sort key too long error.
    Basically, the query looks like this:
    insert into MyTable(txtField1,txtField2,..,txtField32,numField1,numField2, ..,numField353)
    select txtfield1,txtfield2,..,txtfield32, SUM(numfield1),SUM(numfield2), .., SUM(numfield353)
    from MyOldTable
    where txtField1='somevalue' and txtField2='some other value'
    group by txtField1,txtField2,..,txtFieldn;
    I have tried increasing the sort_area_size parameter and it doesn't make a difference. What else can/should I change in order to get this query working again? As I said, this worked when there were only 341 sum columns.
    Thanks for any information you may provide.
    Thanks,
    Rob

    The sort key in Oracle is retricted to a length of one database block less some overhead. The only way to get the query to work is to increase your db_block_size parameter. Unfortunately, this will require rebuilding your database from scratch.
    In 9i, you can have different block sizes for different tablespaces. If you are running in 9i, you may be able to move the affected tables to a tablespace with a larger block size, and then do the query. I am not sure which block size would be used for the sort key in 9i, the "database" block size or the "tablespace" block size.
    Alternatively, you could look at the design of the table to see if you could split it up into several narrower tables, and use views to get the reporting.
    HTH
    John

  • How to sort a character field with numbers and letters on the end

    I have an internal table with character field which has data like this after I sort it.  This is not what I expect from the sort.:
    13A
    15A
    29A
    30A
    31A
    33A
    123A
    125
    62 
    76 
    94A
    I expect this, which is sorted number first, then alpha.  Any ideas how to get this sort?:
    13A
    15A
    29A
    30A
    31A
    33A
    62 
    76 
    94A
    123A
    125

    Thanks for the suggestions.  After reading the suggestions and reviewing some other post threads, here's what I did to get the sort to work:
    Add a dash - to the end of any record that did not have an alphabet character at the end.  This way, all records have at least one non-numeric character at the end.  Then I overlayed zeros  '0000000'  over each record.  Then I sorted the table.  Afterwards, I removed the dashes and zeros.
    The long way around, but it worked for me.  Since the internal table is processed in memory, it doesn't add much overhead to the run time.

  • Sort algorithm for LARGE amount of data?

    hi,
    i need a sorting scheme for the following situation:
    I have a data file where entries are in chunks of variable length. The size of each
    chunk is defined in the first 5 bytes as a string, so the length can be from
    00001-99999, though it is usually around 1000-3000 bytes long. In reality it is never
    over 10000 bytes, but it is possible for it to be.
    Anyways, I need to sort these files according to the data found in certain
    displacements in these chunks. I will be sorting anywhere from 200,000 to
    100,000,000 at a time. Time is an issue certainly, but if it takes a week to finish that is
    fine, i just need it to work.
    So, my problem is that none of the typical sorts will work for me (bubble, heap) as far
    as i can tell because in those sorts i need to have the data loaded into memory, and
    this much data will overload the system. I have used, in the past, a c method that
    feeds these chunks to the sort function a few at a time, then makes files. Hence, not
    all chunks need to be loaded at once. Does anyone know of any solution to this
    problem? Any sort algorithms or sort classes that can handle this much data? thanks!

    Ever tried the radix sort? it's got linear complexity.
    You can still work a chunk at a time, and simply separate the data into several different "buckets", each one identified by, oh, say, the unicode number for the first character in the chunk.
    You now have several smaller lists to sort, and when you're done, NO MERGING IS NECESSARY. Simply append the lists, because the main sets of lists are already sifted into different "buckets".
    Kinda like this:
    create 256 files, and store in each every record that contains a first character that corresponds to it's ascii value. Then create 256 files for each of the original 256 files, and store in each every recond that contains a second character that correstonds to it's second character.
    etc, etc, etc.
    This is very memery intensive for storage, but in terms of run time complexity, it is linear: You will make an explicit number of passes through the list of data. And, as you go along, the lists get shorter and shorter. So while it appears that you are making 256 ^ (max length of data) passes, you're really only making (max length of data) passes, with some additional overhead of creating extra multiple files.
    For that much data, I would definitely recommend a linear algorithm. Any other sorts would be extremely slow.

  • Paging simultaneously to IP phones and legacy overhead

    I just wanted to share something with the community as it is something I have seen a number of posts on and somethign we struggled with as a company before stumbling on this ingenious solution.  I can't take credit for this, we found it online (Also sorry if this is a repost)
    There is a simple, if somewhat kludgy way to do this.  Any time we have a customer who needs to page both to an overhead and the phone simultaneously what we do is purchase a very basic model IP phone such as a 7912.
    You then open that phone up and attach a single pair from a Cat5 cable to the leads for the phones speakerphone.  Drill a small hole for your cable to come out of the phone and attach the other end of the pair to your overhead paging system.  In this way, users need only dial the DN for the IP to IP phone paging and it will broadcast over both the phones and the overhead simultaneously without any sort of complicated additional configuration.
    This is handy as a number of people I see on these forums aren't terribly familiar with the command line and this method requires no configuration that can not be done with CCA.
    I hope this helps you guys, I know it's certainly been a great time saver for us when installing CME and UC500 systems!

    Bruce,
    I've never run into any sound quality issues.  The overhead pages all sound fine.  Additionally I've not had to make any impedence changes.  Really the only thing I've ever had to change were just the output levels on the overhead system to raise or lower the volume but this trick has really been a boon to us for situations exactly like you describe.  Customers want the transition to be seemless and if anything works differently it becomes a deal breaker.  I can't believe Cisco hasn't come up with an official way to universally page but this should do the trick for you.
    Unfortunately I've not done any of the actual physical work to hook the cable up to the internal speakers, someone else in my company has always done this.  I know we're not the first to do this as we got the idea from someone else online so there may be a video up on youtube.
    An additional caveat I would have you be aware of is that if they want ring out over the overhead, you're going to need to use a phone with multiple buttons (unlike the 7912s we typically use).  So its a matter of balancing needs of customers against cost.

Maybe you are looking for

  • Adobe Acrobat 9 (in Windows 7) - Saving removes fields & edit capability

    I have been using this program for about two weeks, working on a very long form to create fields and formatting them without any problem.  I have been saving the form and editing the fields without problem.  I scanned the form initially to get most o

  • Problema para fazer download do XML (Firefox, Chrome, Safari)

    Oi Pessoal, Queria ver se alguém tem alguma dica... no monitor web, em vários clientes diferentes, conseguia acessar normalmente o download do XML: clicava no botão "Download XML" na visão de detalhes da NF-e, abre-se o menu com "NF-e" habilitado, "N

  • IPhone 5 won't sync to iTunes since update to 11.1.3.8 yesterday

    I've tried repairing iTunes and resetting the sync history since I've also been getting the error message unable to load sync services. But iTunes will sync to my iPad 4. And if I make changes to my playlists on my iPhone they do update in iTunes but

  • Why does my Firefox no longer start and open ?

    I have run Mozilla Firefox on my Windows PC for years with no problem. Now, when I click on the desktop icon, nothing happens. The .exe file is in the same location, nothing has changed but it just will not start and run I am having to use this iPad

  • MacBook Air vs Pro

    I need to buy a laptop for Sixth Form and I wish to buy a MacBook. I'm into design and programming and wish to continue these as my career. I currently have a 21.5" Late 2011 iMac as my main computer which I do all my work on but since I am going to