2013年9月10日星期二

Database design redundant field two small applications [turn]

1 time display redundant field .

in the table if there is time field , such as storage recording business hours , we usually put time into digital for storage, the main purpose is to facilitate the comparison , but the problem lies in the display when faced with a conversion problems , it must be converted into a format the text styles.

My initial approach is to write a utility class and then encounter such a situation is to stop turning , return query results before the data complete traversal again List, now think a little bit should not waste the service side of the a lot of resources , and later became a page is displayed in the render method to use extjs conversion, so they delayed the page rendering time .

now want to understand , can add an extra field in the database , the storage format is used to display the time , just for display, then the impact of doing so is not great , when inserted into the multi- processing a field into the display format of the digital deposit into , but when the query and display brought great convenience. Almost no loss of efficiency . The problem is too easy to meet , highly recommended that you use .



2. use for sorting random numbers out of sequence segments

Most of the databases are all business records stored in order , usually time or the id, but sometimes we need to come up with a collection of disorder , such as we have to deal with an enrollment exam question exam racket .

previous practice was to have come to the entire table , and then into a List1, and then remove the element from List1 random and then turn into List2, then List2 return , low efficiency naturally without saying .

Later solution becomes more in the table to add a random number field , shoving when inserting data into the generated random number into the query when the direct order by this random number field , the result has been is out of order , but without affecting other normal business inquiries , high efficiency and a little more than two points .

------ Solution ------------------------------------ --------
select tdate from table;
select tdate, to_char (tdate, 'yyyy-mm-dd') from table;

basically no difference in performance .

select a, b, c from table order by c
select a, b, c from table order by sys_guid ()

it would not have any difference .

true redundant connection code in the main table is the table , they can do the appropriate redundancy , reducing the connection with the code table .
------ Solution ---------------------------------------- ----
case 1 , with the redundant field , a weak reason.

Case 2, with redundant field , completely wooden justified .
------ Solution ---------------------------------------- ----
2. every query results are the same, it is also called can be called random
------ Solution ----------------- ---------------------------
the first one to say there are still desirable , Part 2 said, I do not think it advisable . If this demand is really for scheduling the examination room , then , this approach led to a corresponding seat beginning of each student has been identified , easily lead to cheating.

I am more used database redundancy place, and I also share with you:
1, with the data dictionary fields, such as education, I usually set up two fields, a storage 01,02 this encoding , a storage undergraduate and post this for display.
2, the table associated with the user table users within the field , I generally use two fields, one to store user code , a store user names for easy display .
------ Solution ---------------------------------------- ----

  
  
Each gate exam examination arrangements are certainly taking this course students from the exterior into the examination room elected and then randomly arranged table , each data insertion sequence changes are likely to bring to do so but also ensure the number of students in the exam after each export confirmation when the result is the same, in order to facilitate the examination schedule lost re-query .   
words, students will know in advance how their examination seat it ? The teachers do not take the initiative to schedule the examination room to say , who knows ?  



I think it should not do , but should manually by an administrator to generate a random order , rather than an insert to generate a random number , so more reliable. In order to export the same order every time , which can be generated after the order , then the order back into the database ah.
------ Solution ---------------------------------------- ----


Option 1 , in addition to the database string operations ( the database must have provided , but the wording is not uniform ) , some of the components can also display the date format can solve the problem . Unless there is a limit in terms of performance requirements , will use the " static " means.

Scenario 2 , in fact, a floor for suggestions on the right ; you can rest assured that virtually all databases provide "random function" , is to use this as a sort keywords.
------ For reference only -------------------------------------- -


If the film is the order of the examination room , then each query are random, then each print when they are not the same sort the results obtained , will also how to arrange examinations .
------ For reference only -------------------------------------- -


Great God , Case 1 you have a better solution , please enlighten me !
case out two , do you encounter random row of the examination room , how to solve ?
------ For reference only -------------------------------------- -



If "to_char" function and the order by sys_guid () is not supported by the database how to do, how to do multiple database support , change the database when it is not it will impact ?
------ For reference only -------------------------------------- -



In addition, you are from a database perspective consider this issue, if the business code uses a persistence layer framework, then define the sql script on the encoding process OO had a great impact . But sql programming, your thinking is correct, but from a system design perspective, this idea more one-sided , only for the Oracle, if the technology selection in using mysql, it will bring a lot of trouble .

current business design direction I think it should upgrade to business computing and processing to do business code , the database only do some CURD, so that regardless of the database to reduce the pressure , but also more conducive to the server cluster configuration , improve the system's swap sex .
------ For reference only -------------------------------------- -



Each gate exam examination arrangements are certainly taking this course students from the exterior into the examination room elected and then randomly arranged table , each data insertion sequence changes are likely to bring to do so but also ensure the number of students in the exam after each export confirmation when the result is the same, in order to facilitate the examination schedule lost re-query .
words, students will know in advance how their examination seat it ? The teachers do not take the initiative to schedule the examination room to say , who knows ?
------ For reference only -------------------------------------- -
seriously I lose !
------ For reference only -------------------------------------- -

  
Option 1 , in addition to the database string operations ( the database must have provided , but the wording is not uniform ) , some of the components can also display the date format can solve the problem . Unless there is a limit in terms of performance requirements , will use the " static " means.   
  
Scenario 2 , in fact, a floor for suggestions on the right ; you can rest assured that virtually all databases provide "random function" , is to use this as a sort keywords.  


Scenario 1 , rely on the database can be made , but the problem is to break the OO, a persistence layer framework in existence when not simple to achieve ; formatting controls can not export a report and use the grid display .
Option 2 , or database functions should or should not be dependent on the question, I firmly hold opposing views.
------ For reference only -------------------------------------- -

    
    
Each gate exam examination arrangements are certainly taking this course students from the exterior into the examination room elected and then randomly arranged table , each data insertion sequence changes are likely to bring to do so but also ensure the number of students in the exam after each export confirmation when the result is the same, in order to facilitate the examination schedule lost re-query .     
words, students will know in advance how their examination seat it ? The teachers do not take the initiative to schedule the examination room to say , who knows ?    
  
  
  
  
I think it should not do , but should manually by an administrator to generate a random order , rather than an insert to generate a random number , so more reliable. In order to export the same order every time , which can be generated after the order , then the order back into the database ah.  


administrators anxious to put the row consequently quit good exam to him, he can manually do these things ;
Even administrators willing to do that, then the data would not exist back yes yes no reason more times database access back to the origin ?
------ For reference only -------------------------------------- -

  
If the film is the order of the examination room , then each query are random, then each print when they are not the same sort the results obtained , will also how to arrange examinations .  
Why are you being so
shoving when inserting data inserted into the generated random number ?

What is the significance ?
------ For reference only -------------------------------------- -


Scenario 1 , you may contact display assembly is still relatively small , HTML -side component is very rich.

Scenario 2 , there is definitely not rely on the database program , a simple example : how do you come to a paging algorithm " does not rely on the database " ? And your program to generate random numbers is fixed, this seemingly random does not conform to the requirements .
------ For reference only -------------------------------------- -
Well, although I would like to continue the debate and you go down , I suddenly found not necessary. CSDN really is not much nutrition place .

  
  
Scenario 1 , you may contact display assembly is still relatively small , HTML -side component is very rich.   
  
Scenario 2 , there is definitely not rely on the database program , a simple example : how do you come to a paging algorithm " does not rely on the database " ? And your program to generate random numbers is fixed, this seemingly random does not conform to the requirements .  

------ For reference only ---------------------------------- -----
I think , the second question is very worthy of our discussion
------ For reference only ----------------- ----------------------
landlord said the way , I think it makes sense, took CET-4 , the candidates should be randomly get a ticket number , then press the number for row ticket examination , so as to achieve the purpose of the random sort
------ For reference only ---------------- -----------------------


landlord said method is not without value, but he described the scene does not make sense .

actually use the database to do a pseudo-random records, production systems are not not used . I designed a system on the use of this kind of program , the data size is ten million level . And I say this scene is just the requirement: "random results can be reproduced ."
------ For reference only -------------------------------------- -

  
landlord said method is not without value, but he described the scene does not make sense .   
  
actually use the database to do a pseudo-random records, production systems are not not used . I designed a system on the use of this kind of program , the data size is ten million level . And I say this scene is just the requirement: "random results can be reproduced ."  



random results can reproduce this is what a scene
------ For reference only ----------------------- ----------------


first generation is to be random, but the future will need to be able to accurately check each number against the random value.

similar to a collective wave number , the latter can always be found in the results of the wave number .
------ For reference only -------------------------------------- -

  
first generation is to be random, but the future will need to be able to accurately check each number against the random value.   
  
similar to a collective wave number , the latter can always be found in the results of the wave number .  



that the landlord said , the second case is applicable to you this scene myself
------ For reference only ----------------- ----------------------


I do not think the same, the landlord is ranked scene examination , then the test results are recorded directly to the seating chart can ; ultimate aim should be the seating chart , which is what the candidates being drawn into the examination room which seats ; no record the original random order .


Another scenario for a non- repeating pseudo-random , must require to efficiently obtain 1 million or less non-repeating random numbers ; so this case can be prepared in advance a record of non- repeating 100W row table of random numbers ; follow-up to get a random number only need to set a start bit random , plus a random primes as incremental , you can get 100W continuous non- repeating random numbers ; Moreover, this table can also be reused.
------ For reference only -------------------------------------- -

  
I do not think the same, the landlord is ranked scene examination , then the test results are recorded directly to the seating chart can ; ultimate aim should be the seating chart , which is what the candidates being drawn into the examination room which seats ; no record the original random order .   
  
  
Another scenario for a non- repeating pseudo-random , must require to efficiently obtain 1 million or less non-repeating random numbers ; so this case can be prepared in advance a record of non- repeating 100W row table of random numbers ; follow-up to get a random number only need to set a start bit random , plus a random primes as incremental , you can get 100W continuous non- repeating random numbers ; Moreover, this table can also be reused.  


ah , learning

没有评论:

发表评论