lots of schemes vs lot of tables?

40 views
Skip to first unread message

Pablo Beltran

unread,
Sep 12, 2013, 11:54:31 AM9/12/13
to h2-da...@googlegroups.com
Hi,

I need to store lot of data (even millions of records) on an small bunch of tables for many users (thousands). What would be would be the best approach?

1. Create one schema per user, so each user would have its own private table:  select * from USER_N.TABLE_X

2. Create one table shared by all the users and add a new column to identify the data by user: select * from PUBLIC.TABLE_X where user=N;

Thanks!
Pablo.

Thomas Mueller

unread,
Sep 20, 2013, 9:23:13 PM9/20/13
to H2 Google Group

Hi

You could do both, but I would use one schema. (the title of the mail is incorrect: many schemas is many tables, which is what I would avoid).

Regards, Thomas

--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.
To post to this group, send email to h2-da...@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/groups/opt_out.

Pablo Beltran

unread,
Sep 21, 2013, 3:19:00 AM9/21/13
to h2-da...@googlegroups.com
Hi Thomas,

You are right, many schemas implies many tables.

What I like of the may schemas approach (one per user) is that I can partition the data very neatly and resolve the data isolation simply with the connection:

public Connection getConnection(String userId){
    Connection conn = pool.getConnection();
    conn.createStatement().execute("set schema USER_"+userId);
    return conn;
}

The code above ensures that the user views only his tables (and data) by default.

I'm not expert and you know much better the database internals, how it scales and how to prevent future problems... I'll change my current model (many schemas) to a single schema.

Regards,
Pablo

2013/9/21 Thomas Mueller <thomas.to...@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "H2 Database" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/h2-database/jp_fVH9XqXU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to h2-database...@googlegroups.com.

Thomas Mueller

unread,
Sep 21, 2013, 5:57:47 AM9/21/13
to H2 Google Group
Hi,

You are right of course. The problem I see is that you might end up with a lot of schemas and a lot of tables, if you try to keep all data in one database. For H2, schema and table metadata is kept fully in memory, I'm not sure about other database engines. And at some point you might want to keep some data that applies to all users.

Regards,
Thomas

Pablo Beltran

unread,
Sep 21, 2013, 3:34:37 PM9/21/13
to h2-database
Hi,

schema and table metadata is kept fully in memory
 
I see the problem. For instance, how much memory would require (approximately) 10.000 schemes x 10 tables = 110.000 object medata? Would that magnitude order be of Megas or Gigas? Megas might be acceptable. Gigas, hmm...

Regards,
Pablo.

2013/9/21 Thomas Mueller <thomas.to...@gmail.com>

Gecko Inked

unread,
Sep 21, 2013, 3:39:40 PM9/21/13
to h2-da...@googlegroups.com
Hi guys,

so I have only 1 table called table1 in the database, but when I transfer the h2.jar file over to another pc (exported as a file along with all the other .jars in the project) and then the table is gone on the new pc. 

How do I get it to stay?

Thanks,
Josh

Thomas Mueller

unread,
Sep 21, 2013, 3:50:40 PM9/21/13
to H2 Google Group
Hi Josh,

Your question is not related to the subject of this thread, which is "lots of schemes vs lot of tables?". Please don't try to hijack other threads.

Also, it seems to me you have asked this question here: http://stackoverflow.com/questions/18924873/h2-embedded-database-loses-tables-data-on-deploymen  - and you got questions and comments, but didn't answer any of them.

Regards,
Thomas

Gmail - Josh

unread,
Sep 21, 2013, 3:53:53 PM9/21/13
to h2-da...@googlegroups.com
Hi Thomas,

I keep getting emails from this thread, so I assumed it was the one I posted, I did not mean to hijack any thread. Just the topic is a matter of urgency as it is my grade 11 final project due next week friday and I cannot get the database working.

I have answered on the thread.

Thanks for your replies,
Josh

Sent from my BlackBerry 10 smartphone.
From: Thomas Mueller
Sent: Saturday 21 September 2013 9:50 PM
To: H2 Google Group
Subject: Re: [h2] lots of schemes vs lot of tables?

Thomas Mueller

unread,
Sep 21, 2013, 3:57:35 PM9/21/13
to H2 Google Group
Hi,


> I keep getting emails from this thread

Well, this is a mailing list, and you have subscribed to it.

No problem, I will unsubscribe you. Anyway it will be easier for you to use StackOverflow and not this mailing list.

Regards,
Thomas

Gmail - Josh

unread,
Sep 21, 2013, 3:58:32 PM9/21/13
to h2-da...@googlegroups.com
Ok, thank you very much Thomas.

Thanks,
Josh

Sent from my BlackBerry 10 smartphone.
From: Thomas Mueller
Sent: Saturday 21 September 2013 9:57 PM
Reply all
Reply to author
Forward
0 new messages