rebuild index for APL table in Sybase - sybase-ase

I use reorg rebuild index to maintain indexes on table with data lock, but what can I use with allpages locking table? how to maintain its indexes, then update statistics?

For allpages, there’s jusr the classic method of dropping and recreating the clustered index.

Related

How to create index faster?

I have 10mln rows in my table in MySQL and 7 indexes on this table. Now when I try to add 8th it takes infinite time to do this. Is there any way to workaround this problem to add easily and fast 8th index?
This is one of the thousand ways MySQL just sucks. By design...
Details: http://lists.mysql.com/mysql/202489
and I don't care if I lose karma for this answer.
No, the time it takes to create an index is directly proportional to the amount of data you have. In MS SQL I create indexes on a table with that many records in about 10 minutes.
EDIT: After seeing comment, please elaborate on infinite. By definition you are saying it never finishes, my answer is related to a long running index creation and not infinite.
Which engine are you using? The implementation of ALTER TABLE ... CREATE INDEX varies significantly.
Using MyISAM, any index change requires a complete table rebuild. This is not inherent to the engine, but a bug which has never been fixed.
Using InnoDB, creating a secondary index does not require a table rebuild, but this optimisation is only available if you're using the InnoDB plugin (rather than the older, shipped engine). Changing the primary key always requires a rebuild, because it is clustered.
Rebuilding the table (in either case) requires a lot of work as it must rebuild all the existing indexes, as well as rewriting the rows, in order to complete the operation. If your table fits in RAM (10M rows sounds like it should do easily), this is relatively quick.
Rebuilding a table which doesn't fit in ram is rather expensive, I recommend it's avoided if possible.
Rebuilding an individual index which doesn't fit in ram, is VERY expensive and is best avoided.
How often do you need to add new indexes? Perhaps you can populate the tables with the index already created?

Can PostgreSQL array be optimized for join?

I see that Postgres array is good for performance if the array's element is the data itself, e.g., tag
http://shon.github.io/2015/12/21/postgres_array_performance.html
How about if I use array as a way to store foreign keys of integer? Barring foreign key constraint problem, is it advisable to store foreign keys with integer array?
Apps should optimize for report or analytics. So if the app will end up joining the array to table most of the time, say the app need to show the label/title/name of the foreign key, is it still ok to use array for storage of foreign keys?
Would the performance be better when array is smallish as compared to using a junction table, say checkboxes of movie genres integer?
How about if the array is in thousands, would the performance be better when not using array and just use junction table instead?
No, storing FKs in an array is never a good idea for general purpose tables. First an foremost, there is the fact you mentioned in passing: Foreign key constraints for array elements are not implemented (yet). This alone should void the idea.
There was an attempt to implement the feature for Postgres 9.3 that was stopped by serious performance issues. See this thread on pgsql-hackers.
Also, while read performance can be improved with arrays for certain use cases, write performance plummets. Think of it: To insert, update or delete a single element from a long array, you now have to write a new row version with the whole array for every canged element. And I see serious lock contention ahead, too.
If your table is read only, the idea starts to make more sense. But then I would consider a materialized view with denormalized arrays on top of a normalized many-to-many implementation:
How to implement a many-to-many relationship in PostgreSQL?
While being at it, the MV can include all join tables and produce one flat table for even better read performance (for typical use cases). This way you get referential integrity and good read (and write) performance - at the cost of the overhead and additional storage for managing the MV.

Does PostgreSQL quickly search for columns with arrays of strings?

According to Can PostgreSQL index array columns?, PostgreSQL can index array columns.
Can it do searches on an array column as efficiently as it does for non array types?
For example, suppose you have a row from a questions table (like SO):
title: ...
content:...
tags: [ 'postgresql', 'indexing', 'arrays' ]
And you want to find questions with the tag 'postgresql'. Would storing the relationship in a join table be faster for searching?
And yes, each column would have an index.
GIN and GiST indexes are generally bigger than a simple b-tree, and take longer to scan. GIN is faster than GiST at the cost of very expensive updates.
If you store your tags in an array column then any update to the row will generally require an update to the index on the array. Under some circumstances HOT will permit this to be skipped, but it's not something you can rely on. So you'll have more index updates and more index bloat.
On the other hand, you're avoiding the need to scan a b-tree for the IDs of the desired objects then fetch them from the main table via a join. You're also saving a fair bit of space by using an array instead of paying the 28 byte per row overhead for each tag in the join table.
If your insert and update rate on the main table is fairly low - including changes to tags - then GIN might be a suitable choice. Otherwise I'd probably go for a typical b-tree on a join table, with a secondary index on (tag, object_id) so that index-only scans can be used to look up the object(s) that have a given tag.
In the end the best thing to do is benchmark it for a simulation of your workload.

Is there any advantage of using ENGINE as MRG_MYISAM in mysql

I am doing a tracking site like google adwords. I am doing only modifications. In that site i have seen they are creating tables for each month and merging that table into one this is done for the tables which stores information about clicks and search details and the merged tables having crores of records.And for querying they have used only the merged table which is having crores of records. Is there any advantage of using tables like this?And the query is taking more than 10 minutes to execute.
A MRG_MYISAM only works over MyISAM tables, which are, by themselves, not the first option for a table. You would normally go for InnoDB tables.
The MRG_MYISAM engine was invented before MySQL had support for views and for partitions. Range partitioning (e.g. partition per month) is most probably what you want.
Partitioning is transparent to the user in terms of queries, but nevertheless uses pruning so as to only read from selected partitions for a query, thus optimizing it.
I would recomment that you use InnoDB tables, and check out range partitioning.
MRG_MYISAM and MyISAM are still in use. They could work out for you. It's just that MyISAM introduces so much trouble (no crash recovery, table level locking, more...) that it's many times out of the question.
Advantages are as follows, If you dont get the following advantages then do not use it.
Easily manage a set of log tables. For example, you can put data from different months into separate tables, compress some of them with myisampack, and then create a MERGE table to use them as one.
Obtain more speed. You can split a large read-only table based on some criteria, and then put individual tables on different disks. A MERGE table structured this way could be much faster than using a single large table.
Perform more efficient searches. If you know exactly what you are looking for, you can search in just one of the underlying tables for some queries and use a MERGE table for others. You can even have many different MERGE tables that use overlapping sets of tables.
Perform more efficient repairs. It is easier to repair individual smaller tables that are mapped to a MERGE table than to repair a single large table.
Instantly map many tables as one. A MERGE table need not maintain an index of its own because it uses the indexes of the individual tables. As a result, MERGE table collections are very fast to create or remap. (You must still specify the index definitions when you create a MERGE table, even though no indexes are created.)
If you have a set of tables from which you create a large table on demand, you can instead create a MERGE table from them on demand. This is much faster and saves a lot of disk space.
Exceed the file size limit for the operating system. Each MyISAM table is bound by this limit, but a collection of MyISAM tables is not.
You can create an alias or synonym for a MyISAM table by defining a MERGE table that maps to that single table. There should be no really notable performance impact from doing this (only a couple of indirect calls and memcpy() calls for each read).
You can read more about this on basic info link, advantages disadvantages link.

Perl: Programmatically drop PostgreSQL table index then re-create after COPY using DBD::Pg

I'm copying several tables (~1.5M records) from one data source to another, but it is taking a long time. I'm looking to speed up my use of DBD::Pg.
I'm currently using pg_getcopydata/pg_putcopydata, but I suppose that the indexes on the destination tables are slowing the process down.
I found that I can find some information on table's indexes using $dbh->statistics_info, but I'm curious if anyone has a programmatic way to dynamically drop/recreate indexes based on this information.
The programmatic way, I guess, is to submit the appropriate CREATE INDEX SQL statements via DBI that you would enter into psql.
Sometimes when copying a large table it's better to do it in this order:
create table with out indexes
copy data
add indexes

Resources