MySQL prefix index in django? - mysql

I have a CharField(max_length=260) in a utf8-general-ci MySQL DB. The column is too long to be fully indexed so I want to use the prefix index feature of MySQL.
"Indexes can be created that use only the leading part of column values, using col_name(length) syntax to specify an index prefix length"
See: http://dev.mysql.com/doc/refman/5.0/en/create-index.html
Is there a way to do this in django? What is the best way to go?

I don't see any other options except executing SQL query directly.
Read this tutorial: https://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly

Related

Does Prisma support multi-valued index in MySQL?

MySQL 8.0.17 and above supports multi-valued indexes for indexing columns which are a JSON array.
Creating such an index requires specific use of DDL, like this:
INDEX zips( (CAST(custinfo->'$.zipcode' AS UNSIGNED ARRAY)) )
The question is how to get this declaration done in the Prisma schema.
The documentation for defining indexes seems to have nothing about this. The equivalent in Postgres (GIN index) is covered and has a specific syntax in the Prisma schema: (##index([value(ops: JsonbPathOps)], type: Gin)
I guess this means that support for multi-valued MySQL index doesn't exist, but maybe I'm missing something?
Any other thoughts / ideas on this?
Is this maybe something that's coming soon in Prisma?

Alternative ways of searching a string in mysql column

I've a web app developed by java. Currently I'm in a part of my app that I need to use MySql like in order to search for a string in mysql table contain 100000+ rows. When I had my research I found that MySql like doesn't use indexes but if you have the wildcard at the end of your string example: hello% but I need %hello% which like doesn't use index in these kinds of wildcards. And I also read on the internet that there are other technologies such as postgresql which can give you the ability of using indexes for searching string.
My question is Just because of like do I need to change MySql DB with all it's other features to postgresql DB, Do we have any alternative way on MySql To search for a string that uses indexes?, Do I Install them both and use each for it's own use ( If there is no other way );
All replies are much appreciated.
Do we have any alternative way on MySql To search for a string
Have you looked into MySQL Full-Text Search which uses fulltext index; provided you are using either InnoDB or MyISAM engine

Update sphinx RT index

I'm using RT indexes with sphinx, but actually I'm having troubles updating their structure. For example adding a new column, or a new attribute like charset_table to a RT index that already exists.
What I suppose I need is to reconstruct the index. But the command indexer is useless with this type of index.
I've considered using ALTER TABLE in mysql, but what about the attributes like the one I mentioned?
Well there is a ALTER TABLE in sphinx QL (in latest versions anyway)
http://sphinxsearch.com/docs/current.html#sphinxql-attach (the url is wrong!)
And there is a 'RECONFIGURE' option (see the above page)
... which can be used to an extent to change things like charset_table
But if you want to apply to the whole index, the only way is to delete/truncate the index. Which will pickup the config fresh from the config file, and then you have to explicitly reinsert all the data again.
Readed the spinx document,you'll see you can't modify the structrue with field directly,you must reconstucture the conf and restart the spinx procedure.Good luck

How to load column names, data from a text file into a MySQL table?

I have a dataset with a lot of columns I want to import into a MySQL database, so I want to be able to create tables without specifying the column headers by hand. Rather I want to supply a filename with the column labels in it to (presumably) the MySQL CREATE TABLE command. I'm using standard MySQL Query Browser tools in Ubuntu, but I didn't see in option for this in the create table dialog, nor could I figure out how to write a query to do this from the CREATE TABLE documentation page. But there must be a way...
A CREATE TABLE statement includes more than just column names
Table name*
Column names*
Column data types*
Column constraints, like NOT NULL
Column options, like DEFAULT, character set
Table constraints, like PRIMARY KEY* and FOREIGN KEY
Indexes
Table options, like storage engine, default character set
* mandatory
You can't get all this just from a list of column names. You should write the CREATE TABLE statement yourself.
Re your comment: Many software development frameworks support ways to declare tables without using SQL DDL. E.g. Hibernate uses XML files. YAML is supported by Rails ActiveRecord, PHP Doctrine and Perl's SQLFairy. There are probably other tools that use other format such as JSON, but I don't know one offhand.
But eventually, all these "simplified" interfaces are no less complex to learn as SQL, while failing to represent exactly what SQL does. See also The Law of Leaky Abstractions.
Check out SQLFairy, because that tool might already convert from files to SQL in a way that can help you. And FWIW MySQL Query Browser (or under its current name, MySQL Workbench) can read SQL files. So you probably don't have to copy & paste manually.

Friendfeed schemaless data in MYSQL

I read an article around schema-less database which sounds cool. (http://bret.appspot.com/entry/how-friendfeed-uses-mysql)
But what isn't clear to me is how do they run search queries on this data? Since the data is in JSON format how do we look for it?
For attributes that are needed for filtering / searching, they are first indexed using a separate table. This makes the data more transparent.
Let me quote what this post says: http://bret.appspot.com/entry/how-friendfeed-uses-mysql
Indexes are stored in separate tables. To create a new index, we create a new table storing the attributes we want to index on all of our database shards.
I'd imagine they have a separate search engine with its own index - probably not even in MySQL, something like Solr.
They're using sphinx for that