If we have a leader and a follower cluster , I know we can explicitly set a different caching policy for a follower database than the one on the leader. But what if I want to explicitly specify caching policy for a specific table in the follower database and not across the entire follower database? I have not found any command for doing something like that in the online documentation.
Basically the following command will do it across the entire follower database:-
.alter follower database MyDB caching-policies-modification-kind = union
I am looking for something like this (obviously this command is not valid):-
.alter follower table MyDB.MyTable caching-policies-modification-kind = union
The syntax is this:
.alter follower database MyDb tables (Table1, Table2) policy caching hot = 7d
or
.alter follower database MyDb table Table1 policy caching hot = 7d
See more in the docs
Related
When we fire the following command against a specific database , we get all the policy info for all the tables in that database:-
.show tables details
But how to determine if a certain policy (e.g. Caching or Retention) that is shown there is because it is inherited from database policy or it is specifically overridden for that table (which is supported too) ? Is there a command to get that information as well , some sort of per table per policy level flag which will tell us if it was overridden.
to see a policy defined at database level (or null, if not defined at database-level), run: .show database DATABASE_NAME policy POLICY_KIND.
for example: .show database MyDatabase policy retention
to see a policy defined at table level (or null, if not defined at table-level), run: .show table TABLE_NAME policy POLICY_KIND.
for example: .show table MyTable policy retention.
if this returns null as the Policy - the database-level policy, if set, is in effect.
as you mentioned correctly, .show tables details shows you the effective policy on the table, taking into account both database-level and table-level policies, if those are set (not null).
I've a query-able state and I want do a SQL query like :
SELECT DISTINCT column1,column2,.. FROM table_name;
How can I do that using Vault Query and Vault Custom Query Criteria.
Even if I get the whole state which has these distinct columns, I'm fine.
As of Corda 3, there is no way to do this using VaultQuery/VaultCustomQueryCriteria. You need to connect directly to the node's database via JDBC.
Corda saves data into Vault. Vault is nothing but Database. By default it has support for H2 database. Corda stores states into H2 table as BLOB. I have performed scan on tables NODE_TRANSACTION, VAULT_LINEAR_STATES and VAULT_STATES. I run IOU Example and performed several transactions. I truncated NODE_TRANSACTION and VAULT_LINEAR_STATES and test on UI but UI was still showing State's data. Data is showing from VAULT_STATES but how it showing is still question. There was no BLOB found in VAULT_STATES my question is where exactly it is referring state in db
The NODE_TRANSACTIONS table maps each transaction ID to a blob of the transaction. This blob includes the transaction's output states, as well as the other components of the transaction
The VAULT_STATES table references each state by the ID of transaction that created it, and its index in the outputs of that transaction. This (ID, output idx) pair is then used to retrieve the state object from the corresponding blob in the NODE_TRANSACTIONS table
I've got this query
UPDATE linkeddb...table SET field1 = 'Y' WHERE column1 = '1234'
This takes 23 seconds to select and update one row
But if I use openquery (which I don't want to) then it only takes half a second.
The reason I don't want to use openquery is so I can add parameters to my query securely and be safe from SQL injections.
Does anyone know of any reason for it to be running so slowly?
Here's a thought as an alternative. Create a stored procedure on the remote server to perform the update and then call that procedure from your local instance.
/* On remote server */
create procedure UpdateTable
#field1 char(1),
#column1 varchar(50)
as
update table
set field1 = #field1
where column1 = #column1
go
/* On local server */
exec linkeddb...UpdateTable #field1 = 'Y', #column1 = '1234'
If you're looking for the why, here's a possibility from Linchi Shea's Blog:
To create the best query plans when
you are using a table on a linked
server, the query processor must have
data distribution statistics from the
linked server. Users that have limited
permissions on any columns of the
table might not have sufficient
permissions to obtain all the useful
statistics, and might receive aless
efficient query plan and experience
poor performance. If the linked
serveris an instance of SQL Server, to
obtain all available statistics, the
user must own the table or be a member
of the sysadmin fixed server role, the
db_ownerfixed database role, or the
db_ddladmin fixed database role on the
linkedserver.
(Because of Linchi's post, this clarification has been added to the latest BooksOnline SQL documentation).
In other words, if the linked server is set up with a user that has limited permissions, then SQL can't retrieve accurate statistics for the table and might choose a poor method for executing a query, including retrieving all rows.
Here's a related SO question about linked server query performance. Their conclusion was: use OpenQuery for best performance.
Update: some additional excellent posts about linked server performance from Linchi's blog.
Is column1 primary key? Probably not. Try to select records for update using primary key (where PK_field=xxx), otherwise (sometimes?) all records will be read to find PK for records to update.
Is column1 a varchar field? Is that why are you surrounding the value 1234 with single-quotation marks? Or is that simply a typo in your question?
I have a Message table and a User table. Both are in separate databases. There is a userID in the Message table that is used to join to the User table to find things like userName.
How can I create this in LINQ to SQL? I can't seem to do a cross database join.
Should I create a View in the database and use that instead? Will that work? What will happen to CRUD against it? E.g. if I delete a message - surely it won't delete the user? I'd imagine it would throw an error.
What to do? I can't move the tables into the same database!
A view will work, if you have granted access to both database to the configured user. You'll need to use the 2-dot notation. This will only work BTW if both databases are on the same server.
create view vwUserMessages as
select * from db1.dbo.Users as users
inner join db2.dbo.Messages as msg on msg.UserID = users.id
For CRUD: a view is (usualy) only for reading: do updates etc directly to the related tables, or use a stored procedure:
create proc pdeleteUserMessages (#UserID int) as
begin trans
delete db2.dbo.Messages where userid = #UserID
delete db1.dbo.Users where id = #UserID
commit trans
go