Index counter shared by multiple tables in mysql -
I have two tables, each have the primary ID column key. I have shared two tables for sharing a hosting key Want to For example, when two tables are empty, and counter = 1. When record A is going to be included in Table 1, then its ID will be increased to 1 and Counter 2. When Record B is to be entered in Table 2, its ID will be 2 and the counter will be increased to 3. When the record c is to be re-inserted in Table 1, then its ID3 and similar will be.
I am using PHP as an external language. Now I have two options:
-
Place the counter as a single-row single-column table in the database, but every time when I add things to A or B I have to update this counter table.
-
I can keep the counter as a global variable in PHP. But then I need to start the counter with the maximum key of the two tables at the beginning of the apache, which I do not know how to do it.
Any suggestions for this?
The background is, I want to display a mix of records from both tables of ASC or DESC order of construction time of records. In addition, the records will be displayed in the page-style, for example, 50 records per page are added to the database instead of being removed. After the above implementation, I select "only two tables ... where 1 and 50 Middle key "and together I can unify the selected dataset, Sort the 50 records according to the ID and display them.
Is there any other idea to implement this requirement?
Thank you very much
OK, you have nothing with this setup will get; If you keep the date time of entry now, you can easily select
from SELECT * (Select column A, column B, Table 1, select Union all, column A, column B, table 2) 1, 50
and it will perform properly.
Alternatively (if chasing the last drop of preformance), if you are merging the result then it can be an indicator to merge the tables (if you are merged with the result Why are two tables too).
Or do this (then you can maintain a table id and other general attributes, and the other two references common id sequence as the foreign key).
Comments
Post a Comment