I am new to couchbase and I have a requirement to create same index (same index create statement) on 2 buckets. Can I use same index name for 2 buckets?
I just tried this in Couchbase Server 6.5.1:
CREATE INDEX ix_foo ON `bucket1` (bar,baz,qux);
CREATE INDEX ix_foo ON `bucket2` (bar,baz,qux);
And yes, it is allowed.
Related
How do I add indexes to a database that is already created?
I'm a newbie to MYSQL and built a DB without any indexes in Django that is really really slow.
I'm trying to add indexes. The problem is that I need to filter by a foreign key. The query is painfully slow (think 20-25 seconds), even though the tables are not big (product = 1 million, another is 10k).
Here is my Django code:
#large db (Product) filtered by foreign key (another__id)
Product.objects.filter(another__id='x')
Should I put an index on the "id" in the another table or the "another" column in the product table?
Do I create an index like this:
CREATE INDEX "another" ON Product
Since this is on the server, what kind of lock should I do?
Is it possible to create index in MySQL similar to this one (PostGIS):
CREATE INDEX spatial_indx_test ON spatial_test USING gist(st_makeline(st_makepoint(x1,y1), st_makepoint(x2,y2)));
where x1,x2,y1,y2 are double-typed numbers stored in the table: spatial_test. Basically is there a way to make index on data that is not directly a column in a table? I've tried smth like this:
CREATE SPATIAL INDEX spatial_indx_test ON spatial_test (LineString(Point(x1,y1), Point(x2,y2));
however it doesn't work in MySQL. Is there any workaround for that?
You can create spation index on the geometry eg:
CREATE TABLE geom (g GEOMETRY NOT NULL, SPATIAL INDEX(g))
ENGINE=MyISAM;
you can find more here http://dev.mysql.com/doc/refman/5.7/en/creating-spatial-indexes.html and here https://dev.mysql.com/doc/refman/5.7/en/using-spatial-indexes.html
From the docs:
An ALTER TABLE statement that contains DROP INDEX and ADD INDEX
clauses that both name the same index uses a table copy, not Fast
Index Creation.
This is a bit unclear to me. Is it talking about the NAME of the index? Can someone give an example of a query in which MySQL resorts to a table copy?
Indeed, it sounds like this line is about:
An (One, single) ALTER TABLE statement
that contains (both) a DROP INDEX and an ADD INDEX clause
and both clauses name the same index
and states that such a statement uses a table copy, not Fast Index Creation.
Such a statement would be:
ALTER TABLE MyTable
DROP INDEX MyIndex
ADD INDEX MyIndex(MyColumn);
The documentation is not really clear about the reason behind this, but I think the database want to create an index first and then drop the other index, so the statement by itself can more easily be made atomic. (Creating the index might fail.) If the index name itself is used in the storage as well, that order of first creating then dropping would give a conflict.
After all, fast index creation is a relatively new feature, so they might improve this over time.
I have a doubt on create table syntax and more in deep when to create index on it.
More in deep I need to create a table by scratch loading ~1 milion record taken from a CSV.
The question is: when should I create an index on the table?
Or better:
- Do I have to prefer to use INDEX syntax on CREATE TABLE statement and then fill the table
or
- Do I have to create table, fill it and then use ALTER TABLE ADD INDEX statement?
Which is faster?
It is good to create index after storing data (specially large data).
Creating index before, will burden more overhead on DBMS.
Yesterday someone told me that Geoalchemy was a good choice to support spatial extensions if I want to use Sqlalchemy. It really did good. Thanks for him a lot.
But I have not found a convenient way to create spatial index with Geoalchemy. Must I run this SQL directly?
CREATE SPATIAL INDEX sp_index ON my_class (
geom_col
);
Is there a convenient way to do it without directly writing the SQL?
Thanks!
When creating a table with table.create() GeoAlchemy will automatically create an index for the geometry column.
Also, SQLAlchemy Index instances have a create method. See the "Indexes" section in http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html#metadata-constraints. I'm not sure if you'll be able to create a spatial index in MySQL with that but it's worth a try.
With GeoAlchemy, there are 2 steps you should take to create Spatial Index on the geometry column
add attr 'spatial_index' to the geometry column
Call the GeometryDDL extension
Example:
# note that spatial_index will set the column to not null
class Building(Base):
geom = GeometryColumn(Point(2, spatial_index=True))
GeometryDDL(Building.__table__)