Making sure table/materialized view created before continuing next command on Clickhouse - clickhouse

I'm using clickhouse-go, sometimes when I run create multiple materialized view, then query from those materialized view it shows success, but sometimes failed because the materialized view not yet created (table default.the_mv_name doesn't exists)
Is there any workaround so the db.Exec("CREATE MATERIALIZED VIEW .... POPULATE AS SELECT ...") only return when it's successfully created. Something like SELECT ... FROM bla FINAL when querying.
Or there's no workaround, so I have to loop and check system.columns table until it's ready?
for non-replicated engine - there's around 50% chance it's happened, for replicated engine - almost always happened

Related

oracle 11g Thamaterialized views against another view

Good day,
Is it technically possible to create a materialized view against a another view in the master database (as opposed to a solid table)?
My DBA advises that oracle does not allow creation of materialized view logs against a view. IMO a view is pretty much the same as a table, so it ought to be possible.
Has anyone ever done this successfully (Oracle 11g).
The documentation is pretty clear about this:
Restrictions on Master Tables of Materialized View Logs
The following restrictions apply to master tables of materialized view logs:
You cannot create a materialized view log for a temporary table or for a view.
You cannot create a materialized view log for a master table with a virtual column.
A view is not pretty much the same as a table. It's a stored query, so it has no storage and DML is only possible through instead-of triggers. It doesn't have the basis for noticing an underlying data change.
Just thinking about it, in order to support a view log - even for a simple single-table view - an update to the view's base table would have to check if there were any views; check if any of those had materialized view logs; and then work out if the change needed to be logged - which would mean executing each view's query and looking at the entire result set. Imagine doing that for every change to the underlying table. And then imagine a more complicated view query, with aggregates or multiple tables, etc.
You'd effectively be materialising the view query to decide whether was a change that needed to be logged, to update an actual materialized view. This is partly what actual materialized views do - stop you having to repeatedly re-execute an expensive view query by tracking changes on the master table(s).
You have to create the materialized view logs on the (normal) view's base tables.

Why does SQL Developer think there's an error in my materialized views?

I created some materialized views and Oracle SQL Developer puts a little red 'x' next to each of them. At the moment they are returning the correct information when I query them and running the following query in SQL Plus suggests that there are no errors:
SELECT * FROM USER_SNAPSHOTS
The ERROR column in this returns 0 for the materialized views in question.
Does anyone know why SQL Developer thinks there is an error? Is there anywhere else I can check?
UPDATE
Taking Patrick's advice I ran the following query:
SELECT * FROM ALL_MVIEWS
The COMPILE_STATE is 'NEEDS_COMPILE' for each view in question. What does this mean? Why would it need to be recompiled? None of the underlying tables have been changed.
To fix 'red' cross icon on views (actually it is a white cross over red background) due to NEEDS_COMPILE run the ALTER VIEW COMMAND.
ALTER VIEW MY_VIEW COMPILE;
Check ORACLE SQL Reference about ALTER VIEW.
http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_4004.htm
For some reason, simply refreshing the materialized views made the 'error' go away. So not a true error, more of a reminder that the data isn't up to date. I guess you can ignore it if the table structure hasn't actually changed then...
This can be caused by modifications to an underlying table that the materialized view is based on. For example: increasing the max size of a column in the table which is included in the materialized view.
To refresh the materialized view you can do the following:
BEGIN
DBMS_SNAPSHOT.REFRESH('Name of materialized view');
END;

Creating Materialized view in oracle taking forever

I have following query which has select query that returns data in 5sec. But when I add create materialized view command infront it takes ever for the query to create materialized view.
When you create a materialized view, you actually create a copy of the data that Oracle takes care to keep synchronized (and it makes those views somewhat like indexes). If your view operates over a big amount of data or over data from other servers, it's natural that the creating this view can take time.
From docs.oracle.com:
A materialized view is a replica of a target master from a single
point in time.
Just for "yuks", try
create table temp_tab nologging as select ...
I've seen cases where MV creation is long for some reason, probably logging.
Also, query development tools sometimes begin returning the data to the screen right away, but if you "paged" to the last row, you would find out how long it really takes to get all the data.
You should profile the select statement with explain plan and understand the table cardinality, indexes, waits states when running, ... in order to see if the query needs tuning.

Oracle materialized view error

I have materialized views that ran in production but hare having problems refreshing. The error message is
ORA-32411: materialized view definition query exceeds the maximum length
The ones that are having the problems are 76kb,70kb,75kb, and 67kb. Is there anything that can be done, besides splitting up the query? The scripts are one long query each so it will be hard to split up.
Recreate your materialized views as just views, and then recompile your materialized view select statement as
select * from your_new_view
I don't believe there is a limit to how long a view can be. I've also found this makes updating the MV query quite simple as you only have to recompile the view instead of dropping and recreating the MV.

changes in Materialized

I have one Materialized view on one server which is created by DB link.
There is one job running on that Mview. (created with dbms_refresh.make earlier).
Now I have created 3 new fields in original table.
My queries are.
1) Do I need to drop and create Mview again, if yes, do i need to create Mview log on main server again
2) What happens to job running on Mview , do i need to create it agin?
Also there are views created on Mview ,so
--If i run create or replace view query , will it create any problem?
Please guide.
Thanks!
If you need to include the new columns in your materialized view then yes you need to re-create the materialized view. You must explicitly drop the view as there is no "create or replace materialized view" statement.
DROP MATERIALIZED VIEW blah;
CREATE MATERIALIZED VIEW blah...
Dropping/recreating the materialized view should re-create the refresh job. Not 100% certain, but you should probably recreate the log as well.
And, if you don't need to include the new columns in your view, you really don't need to do anything...
After dropping/creating the materialized view, you should recompile the other views afterwards, because they may have become invalid.
You can check if that happened with
select *
from user_objects
where status = 'INVALID';
Recompile a view can be done with
alter view the_view compile;
or
exec dbms_utility.compile_schema(user);
This simply recompiles everything in your schema. Be sure to have no running jobs while doing this!

Resources